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 | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 639 | // Abstract base class for read barrier slow paths marking a reference |
| 640 | // `ref`. |
| 641 | // |
| 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) |
| 647 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 648 | DCHECK(kEmitCompilerReadBarrier); |
| 649 | } |
| 650 | |
| 651 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
| 652 | |
| 653 | // Generate assembly code calling the read barrier marking runtime |
| 654 | // entry point (ReadBarrierMarkRegX). |
| 655 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
| 656 | Register ref_reg = ref_.AsRegister<Register>(); |
| 657 | |
| 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 { |
| 687 | // Entrypoint is not already loaded, load from the thread. |
| 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 | } |
| 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 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [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 | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 707 | // reference does not get updated by this slow path after marking. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [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 |
| 714 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 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 | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 718 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 719 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 720 | public: |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 721 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 722 | Location ref, |
| 723 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 724 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +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 | 27b1f9c | 2017-01-17 16:56:34 +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); |
| 743 | __ b(GetExitLabel()); |
| 744 | } |
| 745 | |
| 746 | private: |
| 747 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 748 | }; |
| 749 | |
| 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). |
| 757 | // |
| 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 { |
| 768 | public: |
| 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), |
| 779 | obj_(obj), |
| 780 | offset_(offset), |
| 781 | index_(index), |
| 782 | scale_factor_(scale_factor), |
| 783 | needs_null_check_(needs_null_check), |
| 784 | temp_(temp) { |
| 785 | DCHECK(kEmitCompilerReadBarrier); |
| 786 | DCHECK(kUseBakerReadBarrier); |
| 787 | } |
| 788 | |
| 789 | const char* GetDescription() const OVERRIDE { |
| 790 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 791 | } |
| 792 | |
| 793 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 794 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 795 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 796 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 797 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 798 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 799 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 800 | instruction_->IsStaticFieldGet() || |
| 801 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 802 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 803 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 804 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 805 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 806 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 807 | << "Unexpected instruction in read barrier marking slow path: " |
| 808 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 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())); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 814 | |
| 815 | __ Bind(GetEntryLabel()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 823 | // |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 831 | // |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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_); |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 841 | } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 873 | __ b(GetExitLabel()); |
| 874 | } |
| 875 | |
| 876 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 887 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 888 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 889 | }; |
| 890 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [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 | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 904 | // |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 909 | public: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 921 | obj_(obj), |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 922 | offset_(offset), |
| 923 | index_(index), |
| 924 | scale_factor_(scale_factor), |
| 925 | needs_null_check_(needs_null_check), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 926 | temp1_(temp1), |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 927 | temp2_(temp2) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 928 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 929 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 930 | } |
| 931 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 932 | const char* GetDescription() const OVERRIDE { |
| 933 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 934 | } |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [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 | 27b1f9c | 2017-01-17 16:56:34 +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 | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [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 | 27b1f9c | 2017-01-17 16:56:34 +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 | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 954 | |
| 955 | __ Bind(GetEntryLabel()); |
| 956 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [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); |
| 999 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +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 | 27b1f9c | 2017-01-17 16:56:34 +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 | 27b1f9c | 2017-01-17 16:56:34 +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 | 27b1f9c | 2017-01-17 16:56:34 +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 | 27b1f9c | 2017-01-17 16:56:34 +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 | 27b1f9c | 2017-01-17 16:56:34 +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 | 27b1f9c | 2017-01-17 16:56:34 +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 | |
| 1567 | #undef __ |
| 1568 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1569 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1570 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1571 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1572 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1576 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1577 | } |
| 1578 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1579 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1580 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1581 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1584 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1585 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1586 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1589 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1590 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1591 | return kArmWordSize; |
| 1592 | } |
| 1593 | |
| 1594 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1595 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1596 | return kArmWordSize; |
| 1597 | } |
| 1598 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1599 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1600 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1601 | const CompilerOptions& compiler_options, |
| 1602 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1603 | : CodeGenerator(graph, |
| 1604 | kNumberOfCoreRegisters, |
| 1605 | kNumberOfSRegisters, |
| 1606 | kNumberOfRegisterPairs, |
| 1607 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1608 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1609 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1610 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1611 | compiler_options, |
| 1612 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1613 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1614 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1615 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1616 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1617 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1618 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1619 | uint32_literals_(std::less<uint32_t>(), |
| 1620 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1621 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1622 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1623 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1624 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1625 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1626 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1627 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1628 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1629 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1630 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1631 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1632 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1633 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1634 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1635 | // Always save the LR register to mimic Quick. |
| 1636 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1639 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1640 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1641 | __ FinalizeCode(); |
| 1642 | |
| 1643 | // Adjust native pc offsets in stack maps. |
| 1644 | 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] | 1645 | uint32_t old_position = |
| 1646 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1647 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1648 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1649 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1650 | // Adjust pc offsets for the disassembly information. |
| 1651 | if (disasm_info_ != nullptr) { |
| 1652 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1653 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1654 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1655 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1656 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1657 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1658 | } |
| 1659 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1660 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1661 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1662 | } |
| 1663 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1664 | |
| 1665 | CodeGenerator::Finalize(allocator); |
| 1666 | } |
| 1667 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1668 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1669 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1670 | blocked_core_registers_[SP] = true; |
| 1671 | blocked_core_registers_[LR] = true; |
| 1672 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1673 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1674 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1675 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1676 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1677 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1678 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1679 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1680 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1681 | // Stubs do not save callee-save floating point registers. If the graph |
| 1682 | // is debuggable, we need to deal with these registers differently. For |
| 1683 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1684 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1685 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1686 | } |
| 1687 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1688 | } |
| 1689 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1690 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1691 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1692 | assembler_(codegen->GetAssembler()), |
| 1693 | codegen_(codegen) {} |
| 1694 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1695 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1696 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1697 | 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] | 1698 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1699 | // restore another arbitrary register. |
| 1700 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1701 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1702 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1703 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1704 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1705 | // but in the range. |
| 1706 | if (fpu_spill_mask_ != 0) { |
| 1707 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1708 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1709 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1710 | fpu_spill_mask_ |= (1 << i); |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1715 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1716 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1720 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1721 | } |
| 1722 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1723 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1724 | bool skip_overflow_check = |
| 1725 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1726 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1727 | __ Bind(&frame_entry_label_); |
| 1728 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1729 | if (HasEmptyFrame()) { |
| 1730 | return; |
| 1731 | } |
| 1732 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1733 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1734 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1735 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1736 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1739 | __ PushList(core_spill_mask_); |
| 1740 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1741 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1742 | if (fpu_spill_mask_ != 0) { |
| 1743 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1744 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1745 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1746 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1747 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1748 | |
| 1749 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1750 | // Initialize should_deoptimize flag to 0. |
| 1751 | __ mov(IP, ShifterOperand(0)); |
| 1752 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1753 | } |
| 1754 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1755 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1756 | __ AddConstant(SP, -adjust); |
| 1757 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1758 | |
| 1759 | // Save the current method if we need it. Note that we do not |
| 1760 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1761 | // in the SSA graph. |
| 1762 | if (RequiresCurrentMethod()) { |
| 1763 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1764 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1768 | if (HasEmptyFrame()) { |
| 1769 | __ bx(LR); |
| 1770 | return; |
| 1771 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1772 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1773 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1774 | __ AddConstant(SP, adjust); |
| 1775 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1776 | if (fpu_spill_mask_ != 0) { |
| 1777 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1778 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1779 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1780 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1781 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1782 | // Pop LR into PC to return. |
| 1783 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1784 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1785 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1786 | __ cfi().RestoreState(); |
| 1787 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1790 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1791 | Label* label = GetLabelOf(block); |
| 1792 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1795 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1796 | switch (type) { |
| 1797 | case Primitive::kPrimBoolean: |
| 1798 | case Primitive::kPrimByte: |
| 1799 | case Primitive::kPrimChar: |
| 1800 | case Primitive::kPrimShort: |
| 1801 | case Primitive::kPrimInt: |
| 1802 | case Primitive::kPrimNot: { |
| 1803 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1804 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1805 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1806 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1807 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1808 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1809 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1810 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1811 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1812 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1813 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1814 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1815 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1816 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1817 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1818 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1819 | // Skip R1, and use R2_R3 instead. |
| 1820 | gp_index_++; |
| 1821 | index++; |
| 1822 | } |
| 1823 | } |
| 1824 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1825 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1826 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1827 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1828 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1829 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1830 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1831 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | case Primitive::kPrimFloat: { |
| 1836 | uint32_t stack_index = stack_index_++; |
| 1837 | if (float_index_ % 2 == 0) { |
| 1838 | float_index_ = std::max(double_index_, float_index_); |
| 1839 | } |
| 1840 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1841 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1842 | } else { |
| 1843 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | case Primitive::kPrimDouble: { |
| 1848 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1849 | uint32_t stack_index = stack_index_; |
| 1850 | stack_index_ += 2; |
| 1851 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1852 | uint32_t index = double_index_; |
| 1853 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1854 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1855 | calling_convention.GetFpuRegisterAt(index), |
| 1856 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1857 | DCHECK(ExpectedPairLayout(result)); |
| 1858 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1859 | } else { |
| 1860 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1864 | case Primitive::kPrimVoid: |
| 1865 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1866 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1867 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1868 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1869 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1870 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1871 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1872 | switch (type) { |
| 1873 | case Primitive::kPrimBoolean: |
| 1874 | case Primitive::kPrimByte: |
| 1875 | case Primitive::kPrimChar: |
| 1876 | case Primitive::kPrimShort: |
| 1877 | case Primitive::kPrimInt: |
| 1878 | case Primitive::kPrimNot: { |
| 1879 | return Location::RegisterLocation(R0); |
| 1880 | } |
| 1881 | |
| 1882 | case Primitive::kPrimFloat: { |
| 1883 | return Location::FpuRegisterLocation(S0); |
| 1884 | } |
| 1885 | |
| 1886 | case Primitive::kPrimLong: { |
| 1887 | return Location::RegisterPairLocation(R0, R1); |
| 1888 | } |
| 1889 | |
| 1890 | case Primitive::kPrimDouble: { |
| 1891 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1892 | } |
| 1893 | |
| 1894 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1895 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1896 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1897 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1898 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1901 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1902 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1903 | } |
| 1904 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1905 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1906 | if (source.Equals(destination)) { |
| 1907 | return; |
| 1908 | } |
| 1909 | if (destination.IsRegister()) { |
| 1910 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1911 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1912 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1913 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1914 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1915 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1916 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1917 | } else if (destination.IsFpuRegister()) { |
| 1918 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1919 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1920 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1921 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1922 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1923 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1924 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1925 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1926 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1927 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1928 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1929 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1930 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1931 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1932 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1933 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1934 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1940 | if (source.Equals(destination)) { |
| 1941 | return; |
| 1942 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1943 | if (destination.IsRegisterPair()) { |
| 1944 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1945 | EmitParallelMoves( |
| 1946 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1947 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1948 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1949 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1950 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1951 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1952 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1953 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1954 | } else if (source.IsFpuRegisterPair()) { |
| 1955 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1956 | destination.AsRegisterPairHigh<Register>(), |
| 1957 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1958 | } else { |
| 1959 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1960 | DCHECK(ExpectedPairLayout(destination)); |
| 1961 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1962 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1963 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1964 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1965 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1966 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1967 | SP, |
| 1968 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1969 | } else if (source.IsRegisterPair()) { |
| 1970 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1971 | source.AsRegisterPairLow<Register>(), |
| 1972 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1973 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1974 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1975 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1976 | } else { |
| 1977 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1978 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1979 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1980 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1981 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1982 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1983 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1984 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1985 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1986 | SP, destination.GetStackIndex()); |
| 1987 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1988 | } else if (source.IsFpuRegisterPair()) { |
| 1989 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1990 | SP, |
| 1991 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1992 | } else { |
| 1993 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1994 | EmitParallelMoves( |
| 1995 | Location::StackSlot(source.GetStackIndex()), |
| 1996 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1997 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1998 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1999 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2000 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2005 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2006 | DCHECK(location.IsRegister()); |
| 2007 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2008 | } |
| 2009 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2010 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2011 | HParallelMove move(GetGraph()->GetArena()); |
| 2012 | move.AddMove(src, dst, dst_type, nullptr); |
| 2013 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2017 | if (location.IsRegister()) { |
| 2018 | locations->AddTemp(location); |
| 2019 | } else if (location.IsRegisterPair()) { |
| 2020 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2021 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2022 | } else { |
| 2023 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2024 | } |
| 2025 | } |
| 2026 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2027 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2028 | HInstruction* instruction, |
| 2029 | uint32_t dex_pc, |
| 2030 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2031 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2032 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2033 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2034 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2035 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2036 | } |
| 2037 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2038 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2039 | HInstruction* instruction, |
| 2040 | SlowPathCode* slow_path) { |
| 2041 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2042 | GenerateInvokeRuntime(entry_point_offset); |
| 2043 | } |
| 2044 | |
| 2045 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2046 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2047 | __ blx(LR); |
| 2048 | } |
| 2049 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2050 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2051 | DCHECK(!successor->IsExitBlock()); |
| 2052 | |
| 2053 | HBasicBlock* block = got->GetBlock(); |
| 2054 | HInstruction* previous = got->GetPrevious(); |
| 2055 | |
| 2056 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2057 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2058 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2059 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2060 | return; |
| 2061 | } |
| 2062 | |
| 2063 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2064 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2065 | } |
| 2066 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2067 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2071 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2072 | got->SetLocations(nullptr); |
| 2073 | } |
| 2074 | |
| 2075 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2076 | HandleGoto(got, got->GetSuccessor()); |
| 2077 | } |
| 2078 | |
| 2079 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2080 | try_boundary->SetLocations(nullptr); |
| 2081 | } |
| 2082 | |
| 2083 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2084 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2085 | if (!successor->IsExitBlock()) { |
| 2086 | HandleGoto(try_boundary, successor); |
| 2087 | } |
| 2088 | } |
| 2089 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2090 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2091 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2094 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2097 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 2098 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 2099 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 2100 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2101 | if (rhs_loc.IsConstant()) { |
| 2102 | // 0.0 is the only immediate that can be encoded directly in |
| 2103 | // a VCMP instruction. |
| 2104 | // |
| 2105 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2106 | // specify that in a floating-point comparison, positive zero |
| 2107 | // and negative zero are considered equal, so we can use the |
| 2108 | // literal 0.0 for both cases here. |
| 2109 | // |
| 2110 | // Note however that some methods (Float.equal, Float.compare, |
| 2111 | // Float.compareTo, Double.equal, Double.compare, |
| 2112 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2113 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2114 | // -0.0. So if we ever translate calls to these methods into a |
| 2115 | // HCompare instruction, we must handle the -0.0 case with |
| 2116 | // care here. |
| 2117 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 2118 | if (type == Primitive::kPrimFloat) { |
| 2119 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 2120 | } else { |
| 2121 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 2122 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 2123 | } |
| 2124 | } else { |
| 2125 | if (type == Primitive::kPrimFloat) { |
| 2126 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 2127 | } else { |
| 2128 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 2129 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 2130 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2135 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 2136 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2137 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2138 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2139 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 2143 | Label* true_label, |
| 2144 | Label* false_label) { |
| 2145 | LocationSummary* locations = cond->GetLocations(); |
| 2146 | Location left = locations->InAt(0); |
| 2147 | Location right = locations->InAt(1); |
| 2148 | IfCondition if_cond = cond->GetCondition(); |
| 2149 | |
| 2150 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2151 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2152 | IfCondition true_high_cond = if_cond; |
| 2153 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2154 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2155 | |
| 2156 | // Set the conditions for the test, remembering that == needs to be |
| 2157 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2158 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2159 | switch (if_cond) { |
| 2160 | case kCondEQ: |
| 2161 | case kCondNE: |
| 2162 | // Nothing to do. |
| 2163 | break; |
| 2164 | case kCondLT: |
| 2165 | false_high_cond = kCondGT; |
| 2166 | break; |
| 2167 | case kCondLE: |
| 2168 | true_high_cond = kCondLT; |
| 2169 | break; |
| 2170 | case kCondGT: |
| 2171 | false_high_cond = kCondLT; |
| 2172 | break; |
| 2173 | case kCondGE: |
| 2174 | true_high_cond = kCondGT; |
| 2175 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2176 | case kCondB: |
| 2177 | false_high_cond = kCondA; |
| 2178 | break; |
| 2179 | case kCondBE: |
| 2180 | true_high_cond = kCondB; |
| 2181 | break; |
| 2182 | case kCondA: |
| 2183 | false_high_cond = kCondB; |
| 2184 | break; |
| 2185 | case kCondAE: |
| 2186 | true_high_cond = kCondA; |
| 2187 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2188 | } |
| 2189 | if (right.IsConstant()) { |
| 2190 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2191 | int32_t val_low = Low32Bits(value); |
| 2192 | int32_t val_high = High32Bits(value); |
| 2193 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2194 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2195 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2196 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2197 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2198 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2199 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2200 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2201 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2202 | } |
| 2203 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2204 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2205 | } else { |
| 2206 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2207 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2208 | |
| 2209 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2210 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2211 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2212 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2213 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2214 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2215 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2216 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2217 | } |
| 2218 | // Must be equal high, so compare the lows. |
| 2219 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2220 | } |
| 2221 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2222 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2223 | __ b(true_label, final_condition); |
| 2224 | } |
| 2225 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2226 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2227 | Label* true_target_in, |
| 2228 | Label* false_target_in) { |
| 2229 | // Generated branching requires both targets to be explicit. If either of the |
| 2230 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2231 | Label fallthrough_target; |
| 2232 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2233 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2234 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2235 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2236 | switch (type) { |
| 2237 | case Primitive::kPrimLong: |
| 2238 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 2239 | break; |
| 2240 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2241 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2242 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2243 | GenerateFPJumps(condition, true_target, false_target); |
| 2244 | break; |
| 2245 | default: |
| 2246 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2247 | } |
| 2248 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2249 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2250 | __ b(false_target); |
| 2251 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2252 | |
| 2253 | if (fallthrough_target.IsLinked()) { |
| 2254 | __ Bind(&fallthrough_target); |
| 2255 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2256 | } |
| 2257 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2258 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2259 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2260 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2261 | Label* false_target) { |
| 2262 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2263 | |
| 2264 | if (true_target == nullptr && false_target == nullptr) { |
| 2265 | // Nothing to do. The code always falls through. |
| 2266 | return; |
| 2267 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2268 | // Constant condition, statically compared against "true" (integer value 1). |
| 2269 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2270 | if (true_target != nullptr) { |
| 2271 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2272 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2273 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2274 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2275 | if (false_target != nullptr) { |
| 2276 | __ b(false_target); |
| 2277 | } |
| 2278 | } |
| 2279 | return; |
| 2280 | } |
| 2281 | |
| 2282 | // The following code generates these patterns: |
| 2283 | // (1) true_target == nullptr && false_target != nullptr |
| 2284 | // - opposite condition true => branch to false_target |
| 2285 | // (2) true_target != nullptr && false_target == nullptr |
| 2286 | // - condition true => branch to true_target |
| 2287 | // (3) true_target != nullptr && false_target != nullptr |
| 2288 | // - condition true => branch to true_target |
| 2289 | // - branch to false_target |
| 2290 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2291 | // Condition has been materialized, compare the output to 0. |
| 2292 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2293 | DCHECK(cond_val.IsRegister()); |
| 2294 | if (true_target == nullptr) { |
| 2295 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2296 | } else { |
| 2297 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2298 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2299 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2300 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2301 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2302 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2303 | |
| 2304 | // If this is a long or FP comparison that has been folded into |
| 2305 | // the HCondition, generate the comparison directly. |
| 2306 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2307 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2308 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2309 | return; |
| 2310 | } |
| 2311 | |
| 2312 | LocationSummary* locations = cond->GetLocations(); |
| 2313 | DCHECK(locations->InAt(0).IsRegister()); |
| 2314 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2315 | Location right = locations->InAt(1); |
| 2316 | if (right.IsRegister()) { |
| 2317 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2318 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2319 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2320 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2321 | } |
| 2322 | if (true_target == nullptr) { |
| 2323 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 2324 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2325 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2326 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2327 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2328 | |
| 2329 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2330 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2331 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2332 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2336 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2337 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2338 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2339 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2344 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2345 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2346 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2347 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2348 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2349 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2350 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2354 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2355 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2356 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2357 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2358 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2363 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2364 | GenerateTestAndBranch(deoptimize, |
| 2365 | /* condition_input_index */ 0, |
| 2366 | slow_path->GetEntryLabel(), |
| 2367 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2368 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2369 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2370 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2371 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2372 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2373 | locations->SetOut(Location::RequiresRegister()); |
| 2374 | } |
| 2375 | |
| 2376 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2377 | __ LoadFromOffset(kLoadWord, |
| 2378 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2379 | SP, |
| 2380 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2381 | } |
| 2382 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2383 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2384 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 2385 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2386 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2387 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2388 | } else { |
| 2389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2390 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2391 | } |
| 2392 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2393 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2394 | } |
| 2395 | locations->SetOut(Location::SameAsFirstInput()); |
| 2396 | } |
| 2397 | |
| 2398 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 2399 | LocationSummary* locations = select->GetLocations(); |
| 2400 | Label false_target; |
| 2401 | GenerateTestAndBranch(select, |
| 2402 | /* condition_input_index */ 2, |
| 2403 | /* true_target */ nullptr, |
| 2404 | &false_target); |
| 2405 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2406 | __ Bind(&false_target); |
| 2407 | } |
| 2408 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2409 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2410 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2411 | } |
| 2412 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2413 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2414 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | void CodeGeneratorARM::GenerateNop() { |
| 2418 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2421 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2422 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2423 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2424 | // Handle the long/FP comparisons made in instruction simplification. |
| 2425 | switch (cond->InputAt(0)->GetType()) { |
| 2426 | case Primitive::kPrimLong: |
| 2427 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2428 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2429 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2430 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2431 | } |
| 2432 | break; |
| 2433 | |
| 2434 | case Primitive::kPrimFloat: |
| 2435 | case Primitive::kPrimDouble: |
| 2436 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2437 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2438 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2439 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2440 | } |
| 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2445 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2446 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2447 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2448 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2449 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2452 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2453 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2454 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2455 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2456 | |
| 2457 | LocationSummary* locations = cond->GetLocations(); |
| 2458 | Location left = locations->InAt(0); |
| 2459 | Location right = locations->InAt(1); |
| 2460 | Register out = locations->Out().AsRegister<Register>(); |
| 2461 | Label true_label, false_label; |
| 2462 | |
| 2463 | switch (cond->InputAt(0)->GetType()) { |
| 2464 | default: { |
| 2465 | // Integer case. |
| 2466 | if (right.IsRegister()) { |
| 2467 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2468 | } else { |
| 2469 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2470 | __ CmpConstant(left.AsRegister<Register>(), |
| 2471 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2472 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2473 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2474 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2475 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2476 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2477 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2478 | return; |
| 2479 | } |
| 2480 | case Primitive::kPrimLong: |
| 2481 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2482 | break; |
| 2483 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2484 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2485 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2486 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2487 | break; |
| 2488 | } |
| 2489 | |
| 2490 | // Convert the jumps into the result. |
| 2491 | Label done_label; |
| 2492 | |
| 2493 | // False case: result = 0. |
| 2494 | __ Bind(&false_label); |
| 2495 | __ LoadImmediate(out, 0); |
| 2496 | __ b(&done_label); |
| 2497 | |
| 2498 | // True case: result = 1. |
| 2499 | __ Bind(&true_label); |
| 2500 | __ LoadImmediate(out, 1); |
| 2501 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2505 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2509 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2513 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2517 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2521 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2525 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2529 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2533 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2537 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2541 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2545 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2549 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2552 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2553 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2557 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2561 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2565 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2569 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2573 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2577 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2581 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2584 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2585 | LocationSummary* locations = |
| 2586 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2587 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2590 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2591 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2594 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2595 | LocationSummary* locations = |
| 2596 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2597 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2598 | } |
| 2599 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2600 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2601 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2604 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2605 | LocationSummary* locations = |
| 2606 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2607 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2608 | } |
| 2609 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2610 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2611 | // Will be generated at use site. |
| 2612 | } |
| 2613 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2614 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2615 | LocationSummary* locations = |
| 2616 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2617 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2618 | } |
| 2619 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2620 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2621 | // Will be generated at use site. |
| 2622 | } |
| 2623 | |
| 2624 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2625 | LocationSummary* locations = |
| 2626 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2627 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2628 | } |
| 2629 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2630 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2631 | // Will be generated at use site. |
| 2632 | } |
| 2633 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2634 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2635 | memory_barrier->SetLocations(nullptr); |
| 2636 | } |
| 2637 | |
| 2638 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2639 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2640 | } |
| 2641 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2642 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2643 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2646 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2647 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2650 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2651 | LocationSummary* locations = |
| 2652 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2653 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2654 | } |
| 2655 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2656 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2657 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2660 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2661 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2662 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2663 | // the method_idx. |
| 2664 | HandleInvoke(invoke); |
| 2665 | } |
| 2666 | |
| 2667 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2668 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2669 | } |
| 2670 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2671 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2672 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2673 | // art::PrepareForRegisterAllocation. |
| 2674 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2675 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2676 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2677 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2678 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2679 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2680 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2681 | return; |
| 2682 | } |
| 2683 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2684 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2685 | |
| 2686 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2687 | if (invoke->HasPcRelativeDexCache()) { |
| 2688 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2689 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2690 | } |
| 2691 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2692 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2693 | if (invoke->GetLocations()->Intrinsified()) { |
| 2694 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2695 | intrinsic.Dispatch(invoke); |
| 2696 | return true; |
| 2697 | } |
| 2698 | return false; |
| 2699 | } |
| 2700 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2701 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2702 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2703 | // art::PrepareForRegisterAllocation. |
| 2704 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2705 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2706 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2707 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2708 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2709 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2710 | LocationSummary* locations = invoke->GetLocations(); |
| 2711 | codegen_->GenerateStaticOrDirectCall( |
| 2712 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2713 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2714 | } |
| 2715 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2716 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2717 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2718 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2721 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2722 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2723 | if (intrinsic.TryDispatch(invoke)) { |
| 2724 | return; |
| 2725 | } |
| 2726 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2727 | HandleInvoke(invoke); |
| 2728 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2729 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2730 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2731 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2732 | return; |
| 2733 | } |
| 2734 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2735 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2736 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2737 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2740 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2741 | HandleInvoke(invoke); |
| 2742 | // Add the hidden argument. |
| 2743 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2744 | } |
| 2745 | |
| 2746 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2747 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2748 | LocationSummary* locations = invoke->GetLocations(); |
| 2749 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2750 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2751 | Location receiver = locations->InAt(0); |
| 2752 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2753 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2754 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2755 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2756 | DCHECK_EQ(R12, hidden_reg); |
| 2757 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2758 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2759 | if (receiver.IsStackSlot()) { |
| 2760 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2761 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2762 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2763 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2764 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2765 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2766 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2767 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2768 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2769 | // emit a read barrier for the previous class reference load. |
| 2770 | // However this is not required in practice, as this is an |
| 2771 | // intermediate/temporary reference and because the current |
| 2772 | // concurrent copying collector keeps the from-space memory |
| 2773 | // intact/accessible until the end of the marking phase (the |
| 2774 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2775 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2776 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2777 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2778 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2779 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2780 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2781 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2782 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2783 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2784 | // LR = temp->GetEntryPoint(); |
| 2785 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2786 | // LR(); |
| 2787 | __ blx(LR); |
| 2788 | DCHECK(!codegen_->IsLeafMethod()); |
| 2789 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2790 | } |
| 2791 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2792 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2793 | HandleInvoke(invoke); |
| 2794 | } |
| 2795 | |
| 2796 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2797 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2798 | } |
| 2799 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2800 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2801 | LocationSummary* locations = |
| 2802 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2803 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2804 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2805 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2806 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2807 | break; |
| 2808 | } |
| 2809 | case Primitive::kPrimLong: { |
| 2810 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2811 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2812 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2813 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2814 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2815 | case Primitive::kPrimFloat: |
| 2816 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2817 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2818 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2819 | break; |
| 2820 | |
| 2821 | default: |
| 2822 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2827 | LocationSummary* locations = neg->GetLocations(); |
| 2828 | Location out = locations->Out(); |
| 2829 | Location in = locations->InAt(0); |
| 2830 | switch (neg->GetResultType()) { |
| 2831 | case Primitive::kPrimInt: |
| 2832 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2833 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2834 | break; |
| 2835 | |
| 2836 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2837 | DCHECK(in.IsRegisterPair()); |
| 2838 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2839 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2840 | in.AsRegisterPairLow<Register>(), |
| 2841 | ShifterOperand(0)); |
| 2842 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2843 | // instruction here, as it does not exist in the Thumb-2 |
| 2844 | // instruction set. We use the following approach |
| 2845 | // using SBC and SUB instead. |
| 2846 | // |
| 2847 | // out.hi = -C |
| 2848 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2849 | out.AsRegisterPairHigh<Register>(), |
| 2850 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2851 | // out.hi = out.hi - in.hi |
| 2852 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2853 | out.AsRegisterPairHigh<Register>(), |
| 2854 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2855 | break; |
| 2856 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2857 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2858 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2859 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2860 | break; |
| 2861 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2862 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2863 | DCHECK(in.IsFpuRegisterPair()); |
| 2864 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2865 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2866 | break; |
| 2867 | |
| 2868 | default: |
| 2869 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2870 | } |
| 2871 | } |
| 2872 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2873 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2874 | Primitive::Type result_type = conversion->GetResultType(); |
| 2875 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2876 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2877 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2878 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2879 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2880 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2881 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2882 | && result_type == Primitive::kPrimLong) |
| 2883 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2884 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2885 | : LocationSummary::kNoCall; |
| 2886 | LocationSummary* locations = |
| 2887 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2888 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2889 | // The Java language does not allow treating boolean as an integral type but |
| 2890 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2891 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2892 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2893 | case Primitive::kPrimByte: |
| 2894 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2895 | case Primitive::kPrimLong: |
| 2896 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2897 | case Primitive::kPrimBoolean: |
| 2898 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2899 | case Primitive::kPrimShort: |
| 2900 | case Primitive::kPrimInt: |
| 2901 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2902 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2904 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2905 | break; |
| 2906 | |
| 2907 | default: |
| 2908 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2909 | << " to " << result_type; |
| 2910 | } |
| 2911 | break; |
| 2912 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2913 | case Primitive::kPrimShort: |
| 2914 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2915 | case Primitive::kPrimLong: |
| 2916 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2917 | case Primitive::kPrimBoolean: |
| 2918 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2919 | case Primitive::kPrimByte: |
| 2920 | case Primitive::kPrimInt: |
| 2921 | case Primitive::kPrimChar: |
| 2922 | // Processing a Dex `int-to-short' instruction. |
| 2923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2924 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2925 | break; |
| 2926 | |
| 2927 | default: |
| 2928 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2929 | << " to " << result_type; |
| 2930 | } |
| 2931 | break; |
| 2932 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2933 | case Primitive::kPrimInt: |
| 2934 | switch (input_type) { |
| 2935 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2936 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2937 | locations->SetInAt(0, Location::Any()); |
| 2938 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2939 | break; |
| 2940 | |
| 2941 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2942 | // Processing a Dex `float-to-int' instruction. |
| 2943 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2944 | locations->SetOut(Location::RequiresRegister()); |
| 2945 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2946 | break; |
| 2947 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2948 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2949 | // Processing a Dex `double-to-int' instruction. |
| 2950 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2951 | locations->SetOut(Location::RequiresRegister()); |
| 2952 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2953 | break; |
| 2954 | |
| 2955 | default: |
| 2956 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2957 | << " to " << result_type; |
| 2958 | } |
| 2959 | break; |
| 2960 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2961 | case Primitive::kPrimLong: |
| 2962 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2963 | case Primitive::kPrimBoolean: |
| 2964 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2965 | case Primitive::kPrimByte: |
| 2966 | case Primitive::kPrimShort: |
| 2967 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2968 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2969 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2970 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2971 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2972 | break; |
| 2973 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2974 | case Primitive::kPrimFloat: { |
| 2975 | // Processing a Dex `float-to-long' instruction. |
| 2976 | InvokeRuntimeCallingConvention calling_convention; |
| 2977 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2978 | calling_convention.GetFpuRegisterAt(0))); |
| 2979 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2980 | break; |
| 2981 | } |
| 2982 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2983 | case Primitive::kPrimDouble: { |
| 2984 | // Processing a Dex `double-to-long' instruction. |
| 2985 | InvokeRuntimeCallingConvention calling_convention; |
| 2986 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2987 | calling_convention.GetFpuRegisterAt(0), |
| 2988 | calling_convention.GetFpuRegisterAt(1))); |
| 2989 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2990 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2991 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2992 | |
| 2993 | default: |
| 2994 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2995 | << " to " << result_type; |
| 2996 | } |
| 2997 | break; |
| 2998 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2999 | case Primitive::kPrimChar: |
| 3000 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3001 | case Primitive::kPrimLong: |
| 3002 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3003 | case Primitive::kPrimBoolean: |
| 3004 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3005 | case Primitive::kPrimByte: |
| 3006 | case Primitive::kPrimShort: |
| 3007 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3008 | // Processing a Dex `int-to-char' instruction. |
| 3009 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3010 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3011 | break; |
| 3012 | |
| 3013 | default: |
| 3014 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3015 | << " to " << result_type; |
| 3016 | } |
| 3017 | break; |
| 3018 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3019 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3020 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3021 | case Primitive::kPrimBoolean: |
| 3022 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3023 | case Primitive::kPrimByte: |
| 3024 | case Primitive::kPrimShort: |
| 3025 | case Primitive::kPrimInt: |
| 3026 | case Primitive::kPrimChar: |
| 3027 | // Processing a Dex `int-to-float' instruction. |
| 3028 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3029 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3030 | break; |
| 3031 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3032 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3033 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3034 | InvokeRuntimeCallingConvention calling_convention; |
| 3035 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3036 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3037 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3038 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3039 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3040 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3041 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3042 | // Processing a Dex `double-to-float' instruction. |
| 3043 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3044 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3045 | break; |
| 3046 | |
| 3047 | default: |
| 3048 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3049 | << " to " << result_type; |
| 3050 | }; |
| 3051 | break; |
| 3052 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3053 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3054 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3055 | case Primitive::kPrimBoolean: |
| 3056 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3057 | case Primitive::kPrimByte: |
| 3058 | case Primitive::kPrimShort: |
| 3059 | case Primitive::kPrimInt: |
| 3060 | case Primitive::kPrimChar: |
| 3061 | // Processing a Dex `int-to-double' instruction. |
| 3062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3063 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3064 | break; |
| 3065 | |
| 3066 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3067 | // Processing a Dex `long-to-double' instruction. |
| 3068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3069 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3070 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3071 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3072 | break; |
| 3073 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3074 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3075 | // Processing a Dex `float-to-double' instruction. |
| 3076 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3077 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3078 | break; |
| 3079 | |
| 3080 | default: |
| 3081 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3082 | << " to " << result_type; |
| 3083 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3084 | break; |
| 3085 | |
| 3086 | default: |
| 3087 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3088 | << " to " << result_type; |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3093 | LocationSummary* locations = conversion->GetLocations(); |
| 3094 | Location out = locations->Out(); |
| 3095 | Location in = locations->InAt(0); |
| 3096 | Primitive::Type result_type = conversion->GetResultType(); |
| 3097 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3098 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3099 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3100 | case Primitive::kPrimByte: |
| 3101 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3102 | case Primitive::kPrimLong: |
| 3103 | // Type conversion from long to byte is a result of code transformations. |
| 3104 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3105 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3106 | case Primitive::kPrimBoolean: |
| 3107 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3108 | case Primitive::kPrimShort: |
| 3109 | case Primitive::kPrimInt: |
| 3110 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3111 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3112 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3113 | break; |
| 3114 | |
| 3115 | default: |
| 3116 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3117 | << " to " << result_type; |
| 3118 | } |
| 3119 | break; |
| 3120 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3121 | case Primitive::kPrimShort: |
| 3122 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3123 | case Primitive::kPrimLong: |
| 3124 | // Type conversion from long to short is a result of code transformations. |
| 3125 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3126 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3127 | case Primitive::kPrimBoolean: |
| 3128 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3129 | case Primitive::kPrimByte: |
| 3130 | case Primitive::kPrimInt: |
| 3131 | case Primitive::kPrimChar: |
| 3132 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3133 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3134 | break; |
| 3135 | |
| 3136 | default: |
| 3137 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3138 | << " to " << result_type; |
| 3139 | } |
| 3140 | break; |
| 3141 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3142 | case Primitive::kPrimInt: |
| 3143 | switch (input_type) { |
| 3144 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3145 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3146 | DCHECK(out.IsRegister()); |
| 3147 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3148 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3149 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3150 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3151 | } else { |
| 3152 | DCHECK(in.IsConstant()); |
| 3153 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3154 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3155 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3156 | } |
| 3157 | break; |
| 3158 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3159 | case Primitive::kPrimFloat: { |
| 3160 | // Processing a Dex `float-to-int' instruction. |
| 3161 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3162 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3163 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 3164 | break; |
| 3165 | } |
| 3166 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3167 | case Primitive::kPrimDouble: { |
| 3168 | // Processing a Dex `double-to-int' instruction. |
| 3169 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3170 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3171 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3172 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3173 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3174 | |
| 3175 | default: |
| 3176 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3177 | << " to " << result_type; |
| 3178 | } |
| 3179 | break; |
| 3180 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3181 | case Primitive::kPrimLong: |
| 3182 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3183 | case Primitive::kPrimBoolean: |
| 3184 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3185 | case Primitive::kPrimByte: |
| 3186 | case Primitive::kPrimShort: |
| 3187 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3188 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3189 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3190 | DCHECK(out.IsRegisterPair()); |
| 3191 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3192 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3193 | // Sign extension. |
| 3194 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3195 | out.AsRegisterPairLow<Register>(), |
| 3196 | 31); |
| 3197 | break; |
| 3198 | |
| 3199 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3200 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3201 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3202 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3203 | break; |
| 3204 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3205 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3206 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3207 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3208 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3209 | break; |
| 3210 | |
| 3211 | default: |
| 3212 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3213 | << " to " << result_type; |
| 3214 | } |
| 3215 | break; |
| 3216 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3217 | case Primitive::kPrimChar: |
| 3218 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3219 | case Primitive::kPrimLong: |
| 3220 | // Type conversion from long to char is a result of code transformations. |
| 3221 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3222 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3223 | case Primitive::kPrimBoolean: |
| 3224 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3225 | case Primitive::kPrimByte: |
| 3226 | case Primitive::kPrimShort: |
| 3227 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3228 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3229 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3230 | break; |
| 3231 | |
| 3232 | default: |
| 3233 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3234 | << " to " << result_type; |
| 3235 | } |
| 3236 | break; |
| 3237 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3238 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3239 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3240 | case Primitive::kPrimBoolean: |
| 3241 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3242 | case Primitive::kPrimByte: |
| 3243 | case Primitive::kPrimShort: |
| 3244 | case Primitive::kPrimInt: |
| 3245 | case Primitive::kPrimChar: { |
| 3246 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3247 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3248 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | } |
| 3251 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3252 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3253 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3254 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3255 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3256 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3257 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3258 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3259 | // Processing a Dex `double-to-float' instruction. |
| 3260 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3261 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3262 | break; |
| 3263 | |
| 3264 | default: |
| 3265 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3266 | << " to " << result_type; |
| 3267 | }; |
| 3268 | break; |
| 3269 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3270 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3271 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3272 | case Primitive::kPrimBoolean: |
| 3273 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3274 | case Primitive::kPrimByte: |
| 3275 | case Primitive::kPrimShort: |
| 3276 | case Primitive::kPrimInt: |
| 3277 | case Primitive::kPrimChar: { |
| 3278 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3279 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3280 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3281 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3282 | break; |
| 3283 | } |
| 3284 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3285 | case Primitive::kPrimLong: { |
| 3286 | // Processing a Dex `long-to-double' instruction. |
| 3287 | Register low = in.AsRegisterPairLow<Register>(); |
| 3288 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3289 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3290 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3291 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3292 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3293 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3294 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3295 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3296 | // temp_d = int-to-double(high) |
| 3297 | __ vmovsr(temp_s, high); |
| 3298 | __ vcvtdi(temp_d, temp_s); |
| 3299 | // constant_d = k2Pow32EncodingForDouble |
| 3300 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3301 | // out_d = unsigned-to-double(low) |
| 3302 | __ vmovsr(out_s, low); |
| 3303 | __ vcvtdu(out_d, out_s); |
| 3304 | // out_d += temp_d * constant_d |
| 3305 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3306 | break; |
| 3307 | } |
| 3308 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3309 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3310 | // Processing a Dex `float-to-double' instruction. |
| 3311 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3312 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3313 | break; |
| 3314 | |
| 3315 | default: |
| 3316 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3317 | << " to " << result_type; |
| 3318 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3319 | break; |
| 3320 | |
| 3321 | default: |
| 3322 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3323 | << " to " << result_type; |
| 3324 | } |
| 3325 | } |
| 3326 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3327 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3328 | LocationSummary* locations = |
| 3329 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3330 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3331 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3333 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3334 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3335 | break; |
| 3336 | } |
| 3337 | |
| 3338 | case Primitive::kPrimLong: { |
| 3339 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3340 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3342 | break; |
| 3343 | } |
| 3344 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3345 | case Primitive::kPrimFloat: |
| 3346 | case Primitive::kPrimDouble: { |
| 3347 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3348 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3349 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3350 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3351 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3352 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3353 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3354 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3355 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3359 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3360 | Location out = locations->Out(); |
| 3361 | Location first = locations->InAt(0); |
| 3362 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3363 | switch (add->GetResultType()) { |
| 3364 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3365 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3366 | __ add(out.AsRegister<Register>(), |
| 3367 | first.AsRegister<Register>(), |
| 3368 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3369 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3370 | __ AddConstant(out.AsRegister<Register>(), |
| 3371 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3372 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3373 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3374 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3375 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3376 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3377 | if (second.IsConstant()) { |
| 3378 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3379 | GenerateAddLongConst(out, first, value); |
| 3380 | } else { |
| 3381 | DCHECK(second.IsRegisterPair()); |
| 3382 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3383 | first.AsRegisterPairLow<Register>(), |
| 3384 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3385 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3386 | first.AsRegisterPairHigh<Register>(), |
| 3387 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3388 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3389 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3390 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3391 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3392 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3393 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3394 | first.AsFpuRegister<SRegister>(), |
| 3395 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3396 | break; |
| 3397 | |
| 3398 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3399 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3400 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3401 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3402 | break; |
| 3403 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3404 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3405 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3409 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3410 | LocationSummary* locations = |
| 3411 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3412 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3413 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3415 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3416 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3417 | break; |
| 3418 | } |
| 3419 | |
| 3420 | case Primitive::kPrimLong: { |
| 3421 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3422 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3423 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3424 | break; |
| 3425 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3426 | case Primitive::kPrimFloat: |
| 3427 | case Primitive::kPrimDouble: { |
| 3428 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3429 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3430 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3431 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3432 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3433 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3434 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3435 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3439 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3440 | Location out = locations->Out(); |
| 3441 | Location first = locations->InAt(0); |
| 3442 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3443 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3444 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3445 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3446 | __ sub(out.AsRegister<Register>(), |
| 3447 | first.AsRegister<Register>(), |
| 3448 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3449 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3450 | __ AddConstant(out.AsRegister<Register>(), |
| 3451 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3452 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3453 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3454 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3455 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3456 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3457 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3458 | if (second.IsConstant()) { |
| 3459 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3460 | GenerateAddLongConst(out, first, -value); |
| 3461 | } else { |
| 3462 | DCHECK(second.IsRegisterPair()); |
| 3463 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3464 | first.AsRegisterPairLow<Register>(), |
| 3465 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3466 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3467 | first.AsRegisterPairHigh<Register>(), |
| 3468 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3469 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3470 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3471 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3472 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3473 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3474 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3475 | first.AsFpuRegister<SRegister>(), |
| 3476 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3477 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3481 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3482 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3483 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3484 | break; |
| 3485 | } |
| 3486 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3487 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3488 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3489 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3493 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3494 | LocationSummary* locations = |
| 3495 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3496 | switch (mul->GetResultType()) { |
| 3497 | case Primitive::kPrimInt: |
| 3498 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3499 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3500 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3505 | case Primitive::kPrimFloat: |
| 3506 | case Primitive::kPrimDouble: { |
| 3507 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3508 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3509 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3510 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3511 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3512 | |
| 3513 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3514 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3519 | LocationSummary* locations = mul->GetLocations(); |
| 3520 | Location out = locations->Out(); |
| 3521 | Location first = locations->InAt(0); |
| 3522 | Location second = locations->InAt(1); |
| 3523 | switch (mul->GetResultType()) { |
| 3524 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3525 | __ mul(out.AsRegister<Register>(), |
| 3526 | first.AsRegister<Register>(), |
| 3527 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3528 | break; |
| 3529 | } |
| 3530 | case Primitive::kPrimLong: { |
| 3531 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3532 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3533 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3534 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3535 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3536 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3537 | |
| 3538 | // Extra checks to protect caused by the existence of R1_R2. |
| 3539 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3540 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3541 | DCHECK_NE(out_hi, in1_lo); |
| 3542 | DCHECK_NE(out_hi, in2_lo); |
| 3543 | |
| 3544 | // input: in1 - 64 bits, in2 - 64 bits |
| 3545 | // output: out |
| 3546 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3547 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3548 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3549 | |
| 3550 | // IP <- in1.lo * in2.hi |
| 3551 | __ mul(IP, in1_lo, in2_hi); |
| 3552 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3553 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3554 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3555 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3556 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3557 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3558 | break; |
| 3559 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3560 | |
| 3561 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3562 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3563 | first.AsFpuRegister<SRegister>(), |
| 3564 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3565 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3569 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3570 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3571 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3572 | break; |
| 3573 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3574 | |
| 3575 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3576 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3580 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3581 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3582 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3583 | |
| 3584 | LocationSummary* locations = instruction->GetLocations(); |
| 3585 | Location second = locations->InAt(1); |
| 3586 | DCHECK(second.IsConstant()); |
| 3587 | |
| 3588 | Register out = locations->Out().AsRegister<Register>(); |
| 3589 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3590 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3591 | DCHECK(imm == 1 || imm == -1); |
| 3592 | |
| 3593 | if (instruction->IsRem()) { |
| 3594 | __ LoadImmediate(out, 0); |
| 3595 | } else { |
| 3596 | if (imm == 1) { |
| 3597 | __ Mov(out, dividend); |
| 3598 | } else { |
| 3599 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3600 | } |
| 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3605 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3606 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3607 | |
| 3608 | LocationSummary* locations = instruction->GetLocations(); |
| 3609 | Location second = locations->InAt(1); |
| 3610 | DCHECK(second.IsConstant()); |
| 3611 | |
| 3612 | Register out = locations->Out().AsRegister<Register>(); |
| 3613 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3614 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3615 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3616 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3617 | int ctz_imm = CTZ(abs_imm); |
| 3618 | |
| 3619 | if (ctz_imm == 1) { |
| 3620 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3621 | } else { |
| 3622 | __ Asr(temp, dividend, 31); |
| 3623 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3624 | } |
| 3625 | __ add(out, temp, ShifterOperand(dividend)); |
| 3626 | |
| 3627 | if (instruction->IsDiv()) { |
| 3628 | __ Asr(out, out, ctz_imm); |
| 3629 | if (imm < 0) { |
| 3630 | __ rsb(out, out, ShifterOperand(0)); |
| 3631 | } |
| 3632 | } else { |
| 3633 | __ ubfx(out, out, 0, ctz_imm); |
| 3634 | __ sub(out, out, ShifterOperand(temp)); |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3639 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3640 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3641 | |
| 3642 | LocationSummary* locations = instruction->GetLocations(); |
| 3643 | Location second = locations->InAt(1); |
| 3644 | DCHECK(second.IsConstant()); |
| 3645 | |
| 3646 | Register out = locations->Out().AsRegister<Register>(); |
| 3647 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3648 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3649 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3650 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3651 | |
| 3652 | int64_t magic; |
| 3653 | int shift; |
| 3654 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3655 | |
| 3656 | __ LoadImmediate(temp1, magic); |
| 3657 | __ smull(temp2, temp1, dividend, temp1); |
| 3658 | |
| 3659 | if (imm > 0 && magic < 0) { |
| 3660 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3661 | } else if (imm < 0 && magic > 0) { |
| 3662 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3663 | } |
| 3664 | |
| 3665 | if (shift != 0) { |
| 3666 | __ Asr(temp1, temp1, shift); |
| 3667 | } |
| 3668 | |
| 3669 | if (instruction->IsDiv()) { |
| 3670 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3671 | } else { |
| 3672 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3673 | // TODO: Strength reduction for mls. |
| 3674 | __ LoadImmediate(temp2, imm); |
| 3675 | __ mls(out, temp1, temp2, dividend); |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3680 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3681 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3682 | |
| 3683 | LocationSummary* locations = instruction->GetLocations(); |
| 3684 | Location second = locations->InAt(1); |
| 3685 | DCHECK(second.IsConstant()); |
| 3686 | |
| 3687 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3688 | if (imm == 0) { |
| 3689 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3690 | } else if (imm == 1 || imm == -1) { |
| 3691 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3692 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3693 | DivRemByPowerOfTwo(instruction); |
| 3694 | } else { |
| 3695 | DCHECK(imm <= -2 || imm >= 2); |
| 3696 | GenerateDivRemWithAnyConstant(instruction); |
| 3697 | } |
| 3698 | } |
| 3699 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3700 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3701 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3702 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3703 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3704 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3705 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3706 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3707 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3708 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3709 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3710 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3713 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3714 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3715 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3716 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3717 | if (div->InputAt(1)->IsConstant()) { |
| 3718 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3719 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3720 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3721 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3722 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3723 | // No temp register required. |
| 3724 | } else { |
| 3725 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3726 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3727 | locations->AddTemp(Location::RequiresRegister()); |
| 3728 | } |
| 3729 | } |
| 3730 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3732 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3733 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3734 | } else { |
| 3735 | InvokeRuntimeCallingConvention calling_convention; |
| 3736 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3737 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3738 | // 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] | 3739 | // we only need the former. |
| 3740 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3741 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3742 | break; |
| 3743 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3744 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3745 | InvokeRuntimeCallingConvention calling_convention; |
| 3746 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3747 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3748 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3749 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3750 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | } |
| 3753 | case Primitive::kPrimFloat: |
| 3754 | case Primitive::kPrimDouble: { |
| 3755 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3756 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3757 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3758 | break; |
| 3759 | } |
| 3760 | |
| 3761 | default: |
| 3762 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3767 | LocationSummary* locations = div->GetLocations(); |
| 3768 | Location out = locations->Out(); |
| 3769 | Location first = locations->InAt(0); |
| 3770 | Location second = locations->InAt(1); |
| 3771 | |
| 3772 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3773 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3774 | if (second.IsConstant()) { |
| 3775 | GenerateDivRemConstantIntegral(div); |
| 3776 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3777 | __ sdiv(out.AsRegister<Register>(), |
| 3778 | first.AsRegister<Register>(), |
| 3779 | second.AsRegister<Register>()); |
| 3780 | } else { |
| 3781 | InvokeRuntimeCallingConvention calling_convention; |
| 3782 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3783 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3784 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3785 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3786 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3787 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3788 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3789 | break; |
| 3790 | } |
| 3791 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3792 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3793 | InvokeRuntimeCallingConvention calling_convention; |
| 3794 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3795 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3796 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3797 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3798 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3799 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3800 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3801 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3802 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3803 | break; |
| 3804 | } |
| 3805 | |
| 3806 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3807 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3808 | first.AsFpuRegister<SRegister>(), |
| 3809 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3810 | break; |
| 3811 | } |
| 3812 | |
| 3813 | case Primitive::kPrimDouble: { |
| 3814 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3815 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3816 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3817 | break; |
| 3818 | } |
| 3819 | |
| 3820 | default: |
| 3821 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3822 | } |
| 3823 | } |
| 3824 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3825 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3826 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3827 | |
| 3828 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3829 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3830 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3831 | // sdiv will be replaced by other instruction sequence. |
| 3832 | call_kind = LocationSummary::kNoCall; |
| 3833 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3834 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3835 | // Have hardware divide instruction for int, do it with three instructions. |
| 3836 | call_kind = LocationSummary::kNoCall; |
| 3837 | } |
| 3838 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3839 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3840 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3841 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3842 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3843 | if (rem->InputAt(1)->IsConstant()) { |
| 3844 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3845 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3846 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3847 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3848 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3849 | // No temp register required. |
| 3850 | } else { |
| 3851 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3852 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3853 | locations->AddTemp(Location::RequiresRegister()); |
| 3854 | } |
| 3855 | } |
| 3856 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3857 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3858 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3859 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3860 | locations->AddTemp(Location::RequiresRegister()); |
| 3861 | } else { |
| 3862 | InvokeRuntimeCallingConvention calling_convention; |
| 3863 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3864 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3865 | // 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] | 3866 | // we only need the latter. |
| 3867 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3868 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3869 | break; |
| 3870 | } |
| 3871 | case Primitive::kPrimLong: { |
| 3872 | InvokeRuntimeCallingConvention calling_convention; |
| 3873 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3874 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3875 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3876 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3877 | // The runtime helper puts the output in R2,R3. |
| 3878 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3879 | break; |
| 3880 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3881 | case Primitive::kPrimFloat: { |
| 3882 | InvokeRuntimeCallingConvention calling_convention; |
| 3883 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3884 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3885 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3886 | break; |
| 3887 | } |
| 3888 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3889 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3890 | InvokeRuntimeCallingConvention calling_convention; |
| 3891 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3892 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3893 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3894 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3895 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3896 | break; |
| 3897 | } |
| 3898 | |
| 3899 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3900 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3905 | LocationSummary* locations = rem->GetLocations(); |
| 3906 | Location out = locations->Out(); |
| 3907 | Location first = locations->InAt(0); |
| 3908 | Location second = locations->InAt(1); |
| 3909 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3910 | Primitive::Type type = rem->GetResultType(); |
| 3911 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3912 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3913 | if (second.IsConstant()) { |
| 3914 | GenerateDivRemConstantIntegral(rem); |
| 3915 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3916 | Register reg1 = first.AsRegister<Register>(); |
| 3917 | Register reg2 = second.AsRegister<Register>(); |
| 3918 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3919 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3920 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3921 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3922 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3923 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3924 | } else { |
| 3925 | InvokeRuntimeCallingConvention calling_convention; |
| 3926 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3927 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3928 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3929 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3930 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3931 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3932 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3933 | break; |
| 3934 | } |
| 3935 | |
| 3936 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3937 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3938 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3939 | break; |
| 3940 | } |
| 3941 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3942 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3943 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3944 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3945 | break; |
| 3946 | } |
| 3947 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3948 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3949 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3950 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3951 | break; |
| 3952 | } |
| 3953 | |
| 3954 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3955 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3956 | } |
| 3957 | } |
| 3958 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3959 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3960 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3961 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3965 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3966 | codegen_->AddSlowPath(slow_path); |
| 3967 | |
| 3968 | LocationSummary* locations = instruction->GetLocations(); |
| 3969 | Location value = locations->InAt(0); |
| 3970 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3971 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3972 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3973 | case Primitive::kPrimByte: |
| 3974 | case Primitive::kPrimChar: |
| 3975 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3976 | case Primitive::kPrimInt: { |
| 3977 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3978 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3979 | } else { |
| 3980 | DCHECK(value.IsConstant()) << value; |
| 3981 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3982 | __ b(slow_path->GetEntryLabel()); |
| 3983 | } |
| 3984 | } |
| 3985 | break; |
| 3986 | } |
| 3987 | case Primitive::kPrimLong: { |
| 3988 | if (value.IsRegisterPair()) { |
| 3989 | __ orrs(IP, |
| 3990 | value.AsRegisterPairLow<Register>(), |
| 3991 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3992 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3993 | } else { |
| 3994 | DCHECK(value.IsConstant()) << value; |
| 3995 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3996 | __ b(slow_path->GetEntryLabel()); |
| 3997 | } |
| 3998 | } |
| 3999 | break; |
| 4000 | default: |
| 4001 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4002 | } |
| 4003 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4006 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4007 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4008 | Location rhs = locations->InAt(1); |
| 4009 | Register out = locations->Out().AsRegister<Register>(); |
| 4010 | |
| 4011 | if (rhs.IsConstant()) { |
| 4012 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4013 | // so map all rotations to a +ve. equivalent in that range. |
| 4014 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4015 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4016 | if (rot) { |
| 4017 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4018 | // (e.g. left by 2 bits == right by 30.) |
| 4019 | __ Ror(out, in, rot); |
| 4020 | } else if (out != in) { |
| 4021 | __ Mov(out, in); |
| 4022 | } |
| 4023 | } else { |
| 4024 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4025 | } |
| 4026 | } |
| 4027 | |
| 4028 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4029 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4030 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4031 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4032 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 4033 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4034 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4035 | Location rhs = locations->InAt(1); |
| 4036 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4037 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4038 | |
| 4039 | if (rhs.IsConstant()) { |
| 4040 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4041 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4042 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4043 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4044 | // logic below to a simple pair of binary orr. |
| 4045 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4046 | if (rot >= kArmBitsPerWord) { |
| 4047 | rot -= kArmBitsPerWord; |
| 4048 | std::swap(in_reg_hi, in_reg_lo); |
| 4049 | } |
| 4050 | // Rotate, or mov to out for zero or word size rotations. |
| 4051 | if (rot != 0u) { |
| 4052 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4053 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4054 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4055 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4056 | } else { |
| 4057 | __ Mov(out_reg_lo, in_reg_lo); |
| 4058 | __ Mov(out_reg_hi, in_reg_hi); |
| 4059 | } |
| 4060 | } else { |
| 4061 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4062 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4063 | Label end; |
| 4064 | Label shift_by_32_plus_shift_right; |
| 4065 | |
| 4066 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4067 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4068 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4069 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4070 | |
| 4071 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4072 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4073 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4074 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4075 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4076 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4077 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4078 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 4079 | __ b(&end); |
| 4080 | |
| 4081 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4082 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4083 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4084 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4085 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4086 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4087 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4088 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4089 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4090 | |
| 4091 | __ Bind(&end); |
| 4092 | } |
| 4093 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4094 | |
| 4095 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4096 | LocationSummary* locations = |
| 4097 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4098 | switch (ror->GetResultType()) { |
| 4099 | case Primitive::kPrimInt: { |
| 4100 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4101 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4102 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4103 | break; |
| 4104 | } |
| 4105 | case Primitive::kPrimLong: { |
| 4106 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4107 | if (ror->InputAt(1)->IsConstant()) { |
| 4108 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4109 | } else { |
| 4110 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4111 | locations->AddTemp(Location::RequiresRegister()); |
| 4112 | locations->AddTemp(Location::RequiresRegister()); |
| 4113 | } |
| 4114 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4115 | break; |
| 4116 | } |
| 4117 | default: |
| 4118 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4119 | } |
| 4120 | } |
| 4121 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4122 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4123 | LocationSummary* locations = ror->GetLocations(); |
| 4124 | Primitive::Type type = ror->GetResultType(); |
| 4125 | switch (type) { |
| 4126 | case Primitive::kPrimInt: { |
| 4127 | HandleIntegerRotate(locations); |
| 4128 | break; |
| 4129 | } |
| 4130 | case Primitive::kPrimLong: { |
| 4131 | HandleLongRotate(locations); |
| 4132 | break; |
| 4133 | } |
| 4134 | default: |
| 4135 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4136 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4137 | } |
| 4138 | } |
| 4139 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4140 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 4141 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4142 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4143 | LocationSummary* locations = |
| 4144 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4145 | |
| 4146 | switch (op->GetResultType()) { |
| 4147 | case Primitive::kPrimInt: { |
| 4148 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4149 | if (op->InputAt(1)->IsConstant()) { |
| 4150 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4151 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4152 | } else { |
| 4153 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4154 | // Make the output overlap, as it will be used to hold the masked |
| 4155 | // second input. |
| 4156 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4157 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4158 | break; |
| 4159 | } |
| 4160 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4161 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4162 | if (op->InputAt(1)->IsConstant()) { |
| 4163 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4164 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4165 | // don't clash with high registers which the register allocator currently guarantees. |
| 4166 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4167 | } else { |
| 4168 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4169 | locations->AddTemp(Location::RequiresRegister()); |
| 4170 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4171 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4172 | break; |
| 4173 | } |
| 4174 | default: |
| 4175 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 4180 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4181 | |
| 4182 | LocationSummary* locations = op->GetLocations(); |
| 4183 | Location out = locations->Out(); |
| 4184 | Location first = locations->InAt(0); |
| 4185 | Location second = locations->InAt(1); |
| 4186 | |
| 4187 | Primitive::Type type = op->GetResultType(); |
| 4188 | switch (type) { |
| 4189 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4190 | Register out_reg = out.AsRegister<Register>(); |
| 4191 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4192 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4193 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4194 | // 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] | 4195 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4196 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4197 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4198 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4199 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4200 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4201 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4202 | } |
| 4203 | } else { |
| 4204 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4205 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4206 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4207 | __ Mov(out_reg, first_reg); |
| 4208 | } else if (op->IsShl()) { |
| 4209 | __ Lsl(out_reg, first_reg, shift_value); |
| 4210 | } else if (op->IsShr()) { |
| 4211 | __ Asr(out_reg, first_reg, shift_value); |
| 4212 | } else { |
| 4213 | __ Lsr(out_reg, first_reg, shift_value); |
| 4214 | } |
| 4215 | } |
| 4216 | break; |
| 4217 | } |
| 4218 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4219 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4220 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4221 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4222 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4223 | Register low = first.AsRegisterPairLow<Register>(); |
| 4224 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4225 | if (second.IsRegister()) { |
| 4226 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4227 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4228 | Register second_reg = second.AsRegister<Register>(); |
| 4229 | |
| 4230 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4231 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4232 | // Shift the high part |
| 4233 | __ Lsl(o_h, high, o_l); |
| 4234 | // Shift the low part and `or` what overflew on the high part |
| 4235 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4236 | __ Lsr(temp, low, temp); |
| 4237 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4238 | // If the shift is > 32 bits, override the high part |
| 4239 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4240 | __ it(PL); |
| 4241 | __ Lsl(o_h, low, temp, PL); |
| 4242 | // Shift the low part |
| 4243 | __ Lsl(o_l, low, o_l); |
| 4244 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4245 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4246 | // Shift the low part |
| 4247 | __ Lsr(o_l, low, o_h); |
| 4248 | // Shift the high part and `or` what underflew on the low part |
| 4249 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4250 | __ Lsl(temp, high, temp); |
| 4251 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4252 | // If the shift is > 32 bits, override the low part |
| 4253 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4254 | __ it(PL); |
| 4255 | __ Asr(o_l, high, temp, PL); |
| 4256 | // Shift the high part |
| 4257 | __ Asr(o_h, high, o_h); |
| 4258 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4259 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4260 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4261 | __ Lsr(o_l, low, o_h); |
| 4262 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4263 | __ Lsl(temp, high, temp); |
| 4264 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4265 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4266 | __ it(PL); |
| 4267 | __ Lsr(o_l, high, temp, PL); |
| 4268 | __ Lsr(o_h, high, o_h); |
| 4269 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4270 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4271 | // Register allocator doesn't create partial overlap. |
| 4272 | DCHECK_NE(o_l, high); |
| 4273 | DCHECK_NE(o_h, low); |
| 4274 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4275 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4276 | if (shift_value > 32) { |
| 4277 | if (op->IsShl()) { |
| 4278 | __ Lsl(o_h, low, shift_value - 32); |
| 4279 | __ LoadImmediate(o_l, 0); |
| 4280 | } else if (op->IsShr()) { |
| 4281 | __ Asr(o_l, high, shift_value - 32); |
| 4282 | __ Asr(o_h, high, 31); |
| 4283 | } else { |
| 4284 | __ Lsr(o_l, high, shift_value - 32); |
| 4285 | __ LoadImmediate(o_h, 0); |
| 4286 | } |
| 4287 | } else if (shift_value == 32) { |
| 4288 | if (op->IsShl()) { |
| 4289 | __ mov(o_h, ShifterOperand(low)); |
| 4290 | __ LoadImmediate(o_l, 0); |
| 4291 | } else if (op->IsShr()) { |
| 4292 | __ mov(o_l, ShifterOperand(high)); |
| 4293 | __ Asr(o_h, high, 31); |
| 4294 | } else { |
| 4295 | __ mov(o_l, ShifterOperand(high)); |
| 4296 | __ LoadImmediate(o_h, 0); |
| 4297 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4298 | } else if (shift_value == 1) { |
| 4299 | if (op->IsShl()) { |
| 4300 | __ Lsls(o_l, low, 1); |
| 4301 | __ adc(o_h, high, ShifterOperand(high)); |
| 4302 | } else if (op->IsShr()) { |
| 4303 | __ Asrs(o_h, high, 1); |
| 4304 | __ Rrx(o_l, low); |
| 4305 | } else { |
| 4306 | __ Lsrs(o_h, high, 1); |
| 4307 | __ Rrx(o_l, low); |
| 4308 | } |
| 4309 | } else { |
| 4310 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4311 | if (op->IsShl()) { |
| 4312 | __ Lsl(o_h, high, shift_value); |
| 4313 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4314 | __ Lsl(o_l, low, shift_value); |
| 4315 | } else if (op->IsShr()) { |
| 4316 | __ Lsr(o_l, low, shift_value); |
| 4317 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4318 | __ Asr(o_h, high, shift_value); |
| 4319 | } else { |
| 4320 | __ Lsr(o_l, low, shift_value); |
| 4321 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4322 | __ Lsr(o_h, high, shift_value); |
| 4323 | } |
| 4324 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4325 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4326 | break; |
| 4327 | } |
| 4328 | default: |
| 4329 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4330 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4335 | HandleShift(shl); |
| 4336 | } |
| 4337 | |
| 4338 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4339 | HandleShift(shl); |
| 4340 | } |
| 4341 | |
| 4342 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4343 | HandleShift(shr); |
| 4344 | } |
| 4345 | |
| 4346 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4347 | HandleShift(shr); |
| 4348 | } |
| 4349 | |
| 4350 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4351 | HandleShift(ushr); |
| 4352 | } |
| 4353 | |
| 4354 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4355 | HandleShift(ushr); |
| 4356 | } |
| 4357 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4358 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4359 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4360 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4361 | if (instruction->IsStringAlloc()) { |
| 4362 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4363 | } else { |
| 4364 | InvokeRuntimeCallingConvention calling_convention; |
| 4365 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4366 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4367 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4371 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4372 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4373 | if (instruction->IsStringAlloc()) { |
| 4374 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4375 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4376 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4377 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4378 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4379 | __ blx(LR); |
| 4380 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4381 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4382 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4383 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4384 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4385 | } |
| 4386 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4387 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4388 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4389 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4390 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4391 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4392 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4393 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4397 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4398 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4399 | QuickEntrypointEnum entrypoint = |
| 4400 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4401 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4402 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4403 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4406 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4407 | LocationSummary* locations = |
| 4408 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4409 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4410 | if (location.IsStackSlot()) { |
| 4411 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4412 | } else if (location.IsDoubleStackSlot()) { |
| 4413 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4414 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4415 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4416 | } |
| 4417 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4418 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4419 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4420 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4424 | LocationSummary* locations = |
| 4425 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4426 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4427 | } |
| 4428 | |
| 4429 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4430 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4431 | } |
| 4432 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4433 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4434 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4435 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4436 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4437 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4440 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4441 | LocationSummary* locations = not_->GetLocations(); |
| 4442 | Location out = locations->Out(); |
| 4443 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4444 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4445 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4446 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4447 | break; |
| 4448 | |
| 4449 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4450 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4451 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4452 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4453 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4454 | break; |
| 4455 | |
| 4456 | default: |
| 4457 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4458 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4459 | } |
| 4460 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4461 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4462 | LocationSummary* locations = |
| 4463 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4465 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4466 | } |
| 4467 | |
| 4468 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4469 | LocationSummary* locations = bool_not->GetLocations(); |
| 4470 | Location out = locations->Out(); |
| 4471 | Location in = locations->InAt(0); |
| 4472 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4473 | } |
| 4474 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4475 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4476 | LocationSummary* locations = |
| 4477 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4478 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4479 | case Primitive::kPrimBoolean: |
| 4480 | case Primitive::kPrimByte: |
| 4481 | case Primitive::kPrimShort: |
| 4482 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4483 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4484 | case Primitive::kPrimLong: { |
| 4485 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4486 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4487 | // Output overlaps because it is written before doing the low comparison. |
| 4488 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4489 | break; |
| 4490 | } |
| 4491 | case Primitive::kPrimFloat: |
| 4492 | case Primitive::kPrimDouble: { |
| 4493 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4494 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4495 | locations->SetOut(Location::RequiresRegister()); |
| 4496 | break; |
| 4497 | } |
| 4498 | default: |
| 4499 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4500 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4504 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4505 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4506 | Location left = locations->InAt(0); |
| 4507 | Location right = locations->InAt(1); |
| 4508 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4509 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4510 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4511 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4512 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4513 | case Primitive::kPrimBoolean: |
| 4514 | case Primitive::kPrimByte: |
| 4515 | case Primitive::kPrimShort: |
| 4516 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4517 | case Primitive::kPrimInt: { |
| 4518 | __ LoadImmediate(out, 0); |
| 4519 | __ cmp(left.AsRegister<Register>(), |
| 4520 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4521 | less_cond = LT; |
| 4522 | break; |
| 4523 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4524 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4525 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4526 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4527 | __ b(&less, LT); |
| 4528 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4529 | // 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] | 4530 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4531 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4532 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4533 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4534 | break; |
| 4535 | } |
| 4536 | case Primitive::kPrimFloat: |
| 4537 | case Primitive::kPrimDouble: { |
| 4538 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4539 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4540 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4541 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4542 | break; |
| 4543 | } |
| 4544 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4545 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4546 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4547 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4548 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4549 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4550 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4551 | |
| 4552 | __ Bind(&greater); |
| 4553 | __ LoadImmediate(out, 1); |
| 4554 | __ b(&done); |
| 4555 | |
| 4556 | __ Bind(&less); |
| 4557 | __ LoadImmediate(out, -1); |
| 4558 | |
| 4559 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4560 | } |
| 4561 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4562 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4563 | LocationSummary* locations = |
| 4564 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4565 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4566 | locations->SetInAt(i, Location::Any()); |
| 4567 | } |
| 4568 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4569 | } |
| 4570 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4571 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4572 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4573 | } |
| 4574 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4575 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4576 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4577 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | switch (kind) { |
| 4579 | case MemBarrierKind::kAnyStore: |
| 4580 | case MemBarrierKind::kLoadAny: |
| 4581 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4582 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4583 | break; |
| 4584 | } |
| 4585 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4586 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4587 | break; |
| 4588 | } |
| 4589 | default: |
| 4590 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4591 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4592 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4596 | uint32_t offset, |
| 4597 | Register out_lo, |
| 4598 | Register out_hi) { |
| 4599 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4600 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4601 | // `offset` into `out_lo` does not clutter `addr`. |
| 4602 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4603 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4604 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4605 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4606 | } |
| 4607 | __ ldrexd(out_lo, out_hi, addr); |
| 4608 | } |
| 4609 | |
| 4610 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4611 | uint32_t offset, |
| 4612 | Register value_lo, |
| 4613 | Register value_hi, |
| 4614 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4615 | Register temp2, |
| 4616 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4617 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4618 | if (offset != 0) { |
| 4619 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4620 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4621 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | } |
| 4623 | __ Bind(&fail); |
| 4624 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4625 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4626 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4627 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4628 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4629 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4633 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4634 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4635 | LocationSummary* locations = |
| 4636 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4637 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4638 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4639 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4640 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4641 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4642 | } else { |
| 4643 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4644 | } |
| 4645 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4647 | bool generate_volatile = field_info.IsVolatile() |
| 4648 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4649 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4650 | bool needs_write_barrier = |
| 4651 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4652 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4653 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4654 | if (needs_write_barrier) { |
| 4655 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4656 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4657 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4658 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | // - registers need to be consecutive |
| 4660 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4661 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4662 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4663 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4664 | |
| 4665 | locations->AddTemp(Location::RequiresRegister()); |
| 4666 | locations->AddTemp(Location::RequiresRegister()); |
| 4667 | if (field_type == Primitive::kPrimDouble) { |
| 4668 | // For doubles we need two more registers to copy the value. |
| 4669 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4670 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4671 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4672 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4675 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4676 | const FieldInfo& field_info, |
| 4677 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4678 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4679 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4680 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4681 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4682 | Location value = locations->InAt(1); |
| 4683 | |
| 4684 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4685 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4686 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4687 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4688 | bool needs_write_barrier = |
| 4689 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4690 | |
| 4691 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4692 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4693 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4694 | |
| 4695 | switch (field_type) { |
| 4696 | case Primitive::kPrimBoolean: |
| 4697 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4698 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4699 | break; |
| 4700 | } |
| 4701 | |
| 4702 | case Primitive::kPrimShort: |
| 4703 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4704 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4705 | break; |
| 4706 | } |
| 4707 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4708 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4709 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4710 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4711 | // Note that in the case where `value` is a null reference, |
| 4712 | // we do not enter this block, as a null reference does not |
| 4713 | // need poisoning. |
| 4714 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4715 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4716 | __ Mov(temp, value.AsRegister<Register>()); |
| 4717 | __ PoisonHeapReference(temp); |
| 4718 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4719 | } else { |
| 4720 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4721 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4722 | break; |
| 4723 | } |
| 4724 | |
| 4725 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4726 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4727 | GenerateWideAtomicStore(base, offset, |
| 4728 | value.AsRegisterPairLow<Register>(), |
| 4729 | value.AsRegisterPairHigh<Register>(), |
| 4730 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4731 | locations->GetTemp(1).AsRegister<Register>(), |
| 4732 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4733 | } else { |
| 4734 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4735 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4736 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4737 | break; |
| 4738 | } |
| 4739 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4740 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4742 | break; |
| 4743 | } |
| 4744 | |
| 4745 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4746 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4747 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4748 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4749 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4750 | |
| 4751 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4752 | |
| 4753 | GenerateWideAtomicStore(base, offset, |
| 4754 | value_reg_lo, |
| 4755 | value_reg_hi, |
| 4756 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4757 | locations->GetTemp(3).AsRegister<Register>(), |
| 4758 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4759 | } else { |
| 4760 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4762 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4763 | break; |
| 4764 | } |
| 4765 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4766 | case Primitive::kPrimVoid: |
| 4767 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4768 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4769 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4771 | // Longs and doubles are handled in the switch. |
| 4772 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4773 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4774 | } |
| 4775 | |
| 4776 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4777 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4778 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4779 | codegen_->MarkGCCard( |
| 4780 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4781 | } |
| 4782 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4784 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4785 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4786 | } |
| 4787 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4788 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4789 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4790 | |
| 4791 | bool object_field_get_with_read_barrier = |
| 4792 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4793 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4794 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4795 | object_field_get_with_read_barrier ? |
| 4796 | LocationSummary::kCallOnSlowPath : |
| 4797 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4798 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4799 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4800 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4801 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4802 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4803 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4804 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4805 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4806 | // The output overlaps in case of volatile long: we don't want the |
| 4807 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4808 | // object's location. Likewise, in the case of an object field get |
| 4809 | // with read barriers enabled, we do not want the load to overwrite |
| 4810 | // the object's location, as we need it to emit the read barrier. |
| 4811 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4812 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4813 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4814 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4815 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4816 | } else { |
| 4817 | locations->SetOut(Location::RequiresRegister(), |
| 4818 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4819 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4820 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4821 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | // - registers need to be consecutive |
| 4823 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4824 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4825 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4826 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4827 | locations->AddTemp(Location::RequiresRegister()); |
| 4828 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4829 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4830 | // We need a temporary register for the read barrier marking slow |
| 4831 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4832 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4833 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4834 | } |
| 4835 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4836 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4837 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4838 | << input->GetType(); |
| 4839 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4840 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4841 | return Location::ConstantLocation(input->AsConstant()); |
| 4842 | } else { |
| 4843 | return Location::RequiresFpuRegister(); |
| 4844 | } |
| 4845 | } |
| 4846 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4847 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4848 | Opcode opcode) { |
| 4849 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4850 | if (constant->IsConstant() && |
| 4851 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4852 | return Location::ConstantLocation(constant->AsConstant()); |
| 4853 | } |
| 4854 | return Location::RequiresRegister(); |
| 4855 | } |
| 4856 | |
| 4857 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4858 | Opcode opcode) { |
| 4859 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4860 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4861 | Opcode high_opcode = opcode; |
| 4862 | SetCc low_set_cc = kCcDontCare; |
| 4863 | switch (opcode) { |
| 4864 | case SUB: |
| 4865 | // Flip the operation to an ADD. |
| 4866 | value = -value; |
| 4867 | opcode = ADD; |
| 4868 | FALLTHROUGH_INTENDED; |
| 4869 | case ADD: |
| 4870 | if (Low32Bits(value) == 0u) { |
| 4871 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4872 | } |
| 4873 | high_opcode = ADC; |
| 4874 | low_set_cc = kCcSet; |
| 4875 | break; |
| 4876 | default: |
| 4877 | break; |
| 4878 | } |
| 4879 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4880 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4881 | } else { |
| 4882 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4883 | } |
| 4884 | } |
| 4885 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4886 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4887 | Opcode opcode, |
| 4888 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4889 | ShifterOperand so; |
| 4890 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4891 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4892 | return true; |
| 4893 | } |
| 4894 | Opcode neg_opcode = kNoOperand; |
| 4895 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4896 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4897 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4898 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4899 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4900 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4901 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4902 | default: |
| 4903 | return false; |
| 4904 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4905 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4906 | } |
| 4907 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4908 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4909 | const FieldInfo& field_info) { |
| 4910 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4911 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4912 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4913 | Location base_loc = locations->InAt(0); |
| 4914 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4915 | Location out = locations->Out(); |
| 4916 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4917 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4918 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4919 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4920 | |
| 4921 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4922 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4923 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4924 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4925 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4926 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4927 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4928 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4929 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4930 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4931 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4932 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4933 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4934 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4935 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4936 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4937 | |
| 4938 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4939 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4940 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4941 | |
| 4942 | case Primitive::kPrimNot: { |
| 4943 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4944 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4945 | Location temp_loc = locations->GetTemp(0); |
| 4946 | // Note that a potential implicit null check is handled in this |
| 4947 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4948 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4949 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4950 | if (is_volatile) { |
| 4951 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4952 | } |
| 4953 | } else { |
| 4954 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4955 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4956 | if (is_volatile) { |
| 4957 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4958 | } |
| 4959 | // If read barriers are enabled, emit read barriers other than |
| 4960 | // Baker's using a slow path (and also unpoison the loaded |
| 4961 | // reference, if heap poisoning is enabled). |
| 4962 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4963 | } |
| 4964 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4965 | } |
| 4966 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4967 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4968 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4969 | GenerateWideAtomicLoad(base, offset, |
| 4970 | out.AsRegisterPairLow<Register>(), |
| 4971 | out.AsRegisterPairHigh<Register>()); |
| 4972 | } else { |
| 4973 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4974 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4975 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4976 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4977 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4978 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4979 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4980 | |
| 4981 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4982 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4983 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4984 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4985 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4986 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4987 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4988 | __ vmovdrr(out_reg, lo, hi); |
| 4989 | } else { |
| 4990 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4991 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4992 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4993 | break; |
| 4994 | } |
| 4995 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4996 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4997 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4998 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4999 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5000 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5001 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5002 | // Potential implicit null checks, in the case of reference or |
| 5003 | // double fields, are handled in the previous switch statement. |
| 5004 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5005 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5006 | } |
| 5007 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5008 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5009 | if (field_type == Primitive::kPrimNot) { |
| 5010 | // Memory barriers, in the case of references, are also handled |
| 5011 | // in the previous switch statement. |
| 5012 | } else { |
| 5013 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5014 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5015 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5019 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5020 | } |
| 5021 | |
| 5022 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5023 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5027 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5028 | } |
| 5029 | |
| 5030 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5031 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5032 | } |
| 5033 | |
| 5034 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5035 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5036 | } |
| 5037 | |
| 5038 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5039 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5040 | } |
| 5041 | |
| 5042 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5043 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5047 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5048 | } |
| 5049 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5050 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5051 | HUnresolvedInstanceFieldGet* instruction) { |
| 5052 | FieldAccessCallingConventionARM calling_convention; |
| 5053 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5054 | instruction, instruction->GetFieldType(), calling_convention); |
| 5055 | } |
| 5056 | |
| 5057 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5058 | HUnresolvedInstanceFieldGet* instruction) { |
| 5059 | FieldAccessCallingConventionARM calling_convention; |
| 5060 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5061 | instruction->GetFieldType(), |
| 5062 | instruction->GetFieldIndex(), |
| 5063 | instruction->GetDexPc(), |
| 5064 | calling_convention); |
| 5065 | } |
| 5066 | |
| 5067 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5068 | HUnresolvedInstanceFieldSet* instruction) { |
| 5069 | FieldAccessCallingConventionARM calling_convention; |
| 5070 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5071 | instruction, instruction->GetFieldType(), calling_convention); |
| 5072 | } |
| 5073 | |
| 5074 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5075 | HUnresolvedInstanceFieldSet* instruction) { |
| 5076 | FieldAccessCallingConventionARM calling_convention; |
| 5077 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5078 | instruction->GetFieldType(), |
| 5079 | instruction->GetFieldIndex(), |
| 5080 | instruction->GetDexPc(), |
| 5081 | calling_convention); |
| 5082 | } |
| 5083 | |
| 5084 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5085 | HUnresolvedStaticFieldGet* instruction) { |
| 5086 | FieldAccessCallingConventionARM calling_convention; |
| 5087 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5088 | instruction, instruction->GetFieldType(), calling_convention); |
| 5089 | } |
| 5090 | |
| 5091 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5092 | HUnresolvedStaticFieldGet* instruction) { |
| 5093 | FieldAccessCallingConventionARM calling_convention; |
| 5094 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5095 | instruction->GetFieldType(), |
| 5096 | instruction->GetFieldIndex(), |
| 5097 | instruction->GetDexPc(), |
| 5098 | calling_convention); |
| 5099 | } |
| 5100 | |
| 5101 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 5102 | HUnresolvedStaticFieldSet* instruction) { |
| 5103 | FieldAccessCallingConventionARM calling_convention; |
| 5104 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5105 | instruction, instruction->GetFieldType(), calling_convention); |
| 5106 | } |
| 5107 | |
| 5108 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 5109 | HUnresolvedStaticFieldSet* instruction) { |
| 5110 | FieldAccessCallingConventionARM calling_convention; |
| 5111 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5112 | instruction->GetFieldType(), |
| 5113 | instruction->GetFieldIndex(), |
| 5114 | instruction->GetDexPc(), |
| 5115 | calling_convention); |
| 5116 | } |
| 5117 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5118 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5119 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5120 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5121 | } |
| 5122 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5123 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5124 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5125 | return; |
| 5126 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5127 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5128 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5129 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5130 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5131 | } |
| 5132 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5133 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5134 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5135 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5136 | |
| 5137 | LocationSummary* locations = instruction->GetLocations(); |
| 5138 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5139 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5140 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5143 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5144 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5145 | } |
| 5146 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5147 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5148 | switch (type) { |
| 5149 | case Primitive::kPrimNot: |
| 5150 | return kLoadWord; |
| 5151 | case Primitive::kPrimBoolean: |
| 5152 | return kLoadUnsignedByte; |
| 5153 | case Primitive::kPrimByte: |
| 5154 | return kLoadSignedByte; |
| 5155 | case Primitive::kPrimChar: |
| 5156 | return kLoadUnsignedHalfword; |
| 5157 | case Primitive::kPrimShort: |
| 5158 | return kLoadSignedHalfword; |
| 5159 | case Primitive::kPrimInt: |
| 5160 | return kLoadWord; |
| 5161 | case Primitive::kPrimLong: |
| 5162 | return kLoadWordPair; |
| 5163 | case Primitive::kPrimFloat: |
| 5164 | return kLoadSWord; |
| 5165 | case Primitive::kPrimDouble: |
| 5166 | return kLoadDWord; |
| 5167 | default: |
| 5168 | LOG(FATAL) << "Unreachable type " << type; |
| 5169 | UNREACHABLE(); |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5174 | switch (type) { |
| 5175 | case Primitive::kPrimNot: |
| 5176 | return kStoreWord; |
| 5177 | case Primitive::kPrimBoolean: |
| 5178 | case Primitive::kPrimByte: |
| 5179 | return kStoreByte; |
| 5180 | case Primitive::kPrimChar: |
| 5181 | case Primitive::kPrimShort: |
| 5182 | return kStoreHalfword; |
| 5183 | case Primitive::kPrimInt: |
| 5184 | return kStoreWord; |
| 5185 | case Primitive::kPrimLong: |
| 5186 | return kStoreWordPair; |
| 5187 | case Primitive::kPrimFloat: |
| 5188 | return kStoreSWord; |
| 5189 | case Primitive::kPrimDouble: |
| 5190 | return kStoreDWord; |
| 5191 | default: |
| 5192 | LOG(FATAL) << "Unreachable type " << type; |
| 5193 | UNREACHABLE(); |
| 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5198 | Location out_loc, |
| 5199 | Register base, |
| 5200 | Register reg_offset, |
| 5201 | Condition cond) { |
| 5202 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5203 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5204 | |
| 5205 | switch (type) { |
| 5206 | case Primitive::kPrimByte: |
| 5207 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5208 | break; |
| 5209 | case Primitive::kPrimBoolean: |
| 5210 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5211 | break; |
| 5212 | case Primitive::kPrimShort: |
| 5213 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5214 | break; |
| 5215 | case Primitive::kPrimChar: |
| 5216 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5217 | break; |
| 5218 | case Primitive::kPrimNot: |
| 5219 | case Primitive::kPrimInt: |
| 5220 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5221 | break; |
| 5222 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5223 | case Primitive::kPrimLong: |
| 5224 | case Primitive::kPrimFloat: |
| 5225 | case Primitive::kPrimDouble: |
| 5226 | default: |
| 5227 | LOG(FATAL) << "Unreachable type " << type; |
| 5228 | UNREACHABLE(); |
| 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5233 | Location loc, |
| 5234 | Register base, |
| 5235 | Register reg_offset, |
| 5236 | Condition cond) { |
| 5237 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5238 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5239 | |
| 5240 | switch (type) { |
| 5241 | case Primitive::kPrimByte: |
| 5242 | case Primitive::kPrimBoolean: |
| 5243 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5244 | break; |
| 5245 | case Primitive::kPrimShort: |
| 5246 | case Primitive::kPrimChar: |
| 5247 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5248 | break; |
| 5249 | case Primitive::kPrimNot: |
| 5250 | case Primitive::kPrimInt: |
| 5251 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5252 | break; |
| 5253 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5254 | case Primitive::kPrimLong: |
| 5255 | case Primitive::kPrimFloat: |
| 5256 | case Primitive::kPrimDouble: |
| 5257 | default: |
| 5258 | LOG(FATAL) << "Unreachable type " << type; |
| 5259 | UNREACHABLE(); |
| 5260 | } |
| 5261 | } |
| 5262 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5263 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5264 | bool object_array_get_with_read_barrier = |
| 5265 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5266 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5267 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5268 | object_array_get_with_read_barrier ? |
| 5269 | LocationSummary::kCallOnSlowPath : |
| 5270 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5271 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5272 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5273 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5275 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5276 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5277 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5278 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5279 | // The output overlaps in the case of an object array get with |
| 5280 | // read barriers enabled: we do not want the move to overwrite the |
| 5281 | // array's location, as we need it to emit the read barrier. |
| 5282 | locations->SetOut( |
| 5283 | Location::RequiresRegister(), |
| 5284 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5285 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5286 | // We need a temporary register for the read barrier marking slow |
| 5287 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5288 | // Also need for String compression feature. |
| 5289 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5290 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5291 | locations->AddTemp(Location::RequiresRegister()); |
| 5292 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5296 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5297 | Location obj_loc = locations->InAt(0); |
| 5298 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5299 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5300 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5301 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5302 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5303 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5304 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5305 | HInstruction* array_instr = instruction->GetArray(); |
| 5306 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5307 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5308 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5309 | case Primitive::kPrimBoolean: |
| 5310 | case Primitive::kPrimByte: |
| 5311 | case Primitive::kPrimShort: |
| 5312 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5313 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5314 | Register length; |
| 5315 | if (maybe_compressed_char_at) { |
| 5316 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5317 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5318 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5319 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5320 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5322 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5323 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5324 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5325 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5326 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5327 | "Expecting 0=compressed, 1=uncompressed"); |
| 5328 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5329 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5330 | out_loc.AsRegister<Register>(), |
| 5331 | obj, |
| 5332 | data_offset + const_index); |
| 5333 | __ b(&done); |
| 5334 | __ Bind(&uncompressed_load); |
| 5335 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5336 | out_loc.AsRegister<Register>(), |
| 5337 | obj, |
| 5338 | data_offset + (const_index << 1)); |
| 5339 | __ Bind(&done); |
| 5340 | } else { |
| 5341 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5342 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5343 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5344 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5345 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5347 | Register temp = IP; |
| 5348 | |
| 5349 | if (has_intermediate_address) { |
| 5350 | // We do not need to compute the intermediate address from the array: the |
| 5351 | // input instruction has done it already. See the comment in |
| 5352 | // `TryExtractArrayAccessAddress()`. |
| 5353 | if (kIsDebugBuild) { |
| 5354 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5355 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5356 | } |
| 5357 | temp = obj; |
| 5358 | } else { |
| 5359 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5360 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5361 | if (maybe_compressed_char_at) { |
| 5362 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5363 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5364 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5365 | "Expecting 0=compressed, 1=uncompressed"); |
| 5366 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5367 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5368 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 5369 | __ b(&done); |
| 5370 | __ Bind(&uncompressed_load); |
| 5371 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5372 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 5373 | __ Bind(&done); |
| 5374 | } else { |
| 5375 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5376 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5377 | } |
| 5378 | break; |
| 5379 | } |
| 5380 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5381 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5382 | // The read barrier instrumentation of object ArrayGet |
| 5383 | // instructions does not support the HIntermediateAddress |
| 5384 | // instruction. |
| 5385 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5386 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5387 | static_assert( |
| 5388 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5389 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5390 | // /* HeapReference<Object> */ out = |
| 5391 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5392 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5393 | Location temp = locations->GetTemp(0); |
| 5394 | // Note that a potential implicit null check is handled in this |
| 5395 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 5396 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5397 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5398 | } else { |
| 5399 | Register out = out_loc.AsRegister<Register>(); |
| 5400 | if (index.IsConstant()) { |
| 5401 | size_t offset = |
| 5402 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5403 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5404 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5405 | // If read barriers are enabled, emit read barriers other than |
| 5406 | // Baker's using a slow path (and also unpoison the loaded |
| 5407 | // reference, if heap poisoning is enabled). |
| 5408 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5409 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5410 | Register temp = IP; |
| 5411 | |
| 5412 | if (has_intermediate_address) { |
| 5413 | // We do not need to compute the intermediate address from the array: the |
| 5414 | // input instruction has done it already. See the comment in |
| 5415 | // `TryExtractArrayAccessAddress()`. |
| 5416 | if (kIsDebugBuild) { |
| 5417 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5418 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5419 | } |
| 5420 | temp = obj; |
| 5421 | } else { |
| 5422 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5423 | } |
| 5424 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5425 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5427 | // If read barriers are enabled, emit read barriers other than |
| 5428 | // Baker's using a slow path (and also unpoison the loaded |
| 5429 | // reference, if heap poisoning is enabled). |
| 5430 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5431 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5432 | } |
| 5433 | } |
| 5434 | break; |
| 5435 | } |
| 5436 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5437 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5438 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5439 | size_t offset = |
| 5440 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5441 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5442 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5443 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5444 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5445 | } |
| 5446 | break; |
| 5447 | } |
| 5448 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5449 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5450 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5451 | if (index.IsConstant()) { |
| 5452 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5453 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5454 | } else { |
| 5455 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5456 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5457 | } |
| 5458 | break; |
| 5459 | } |
| 5460 | |
| 5461 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5462 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5463 | if (index.IsConstant()) { |
| 5464 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5465 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5466 | } else { |
| 5467 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5468 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5469 | } |
| 5470 | break; |
| 5471 | } |
| 5472 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5473 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5474 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5475 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5476 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5477 | |
| 5478 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5479 | // Potential implicit null checks, in the case of reference |
| 5480 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5481 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5482 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5483 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5487 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5488 | |
| 5489 | bool needs_write_barrier = |
| 5490 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5491 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5492 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5493 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5494 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5495 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5496 | LocationSummary::kCallOnSlowPath : |
| 5497 | LocationSummary::kNoCall); |
| 5498 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5499 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5500 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5501 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5502 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5503 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5504 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5505 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5506 | if (needs_write_barrier) { |
| 5507 | // Temporary registers for the write barrier. |
| 5508 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5509 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5510 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5514 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5515 | Location array_loc = locations->InAt(0); |
| 5516 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5517 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5518 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5519 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5520 | bool needs_write_barrier = |
| 5521 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5522 | uint32_t data_offset = |
| 5523 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5524 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5525 | HInstruction* array_instr = instruction->GetArray(); |
| 5526 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5527 | |
| 5528 | switch (value_type) { |
| 5529 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5530 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5531 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5532 | case Primitive::kPrimChar: |
| 5533 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5534 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5535 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5536 | uint32_t full_offset = |
| 5537 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5538 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5539 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5541 | Register temp = IP; |
| 5542 | |
| 5543 | if (has_intermediate_address) { |
| 5544 | // We do not need to compute the intermediate address from the array: the |
| 5545 | // input instruction has done it already. See the comment in |
| 5546 | // `TryExtractArrayAccessAddress()`. |
| 5547 | if (kIsDebugBuild) { |
| 5548 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5549 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5550 | } |
| 5551 | temp = array; |
| 5552 | } else { |
| 5553 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5554 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5555 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5556 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5557 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5558 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5559 | } |
| 5560 | break; |
| 5561 | } |
| 5562 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5563 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5564 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5565 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5566 | // See the comment in instruction_simplifier_shared.cc. |
| 5567 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5568 | |
| 5569 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5570 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5571 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5572 | size_t offset = |
| 5573 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5574 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5575 | } else { |
| 5576 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5577 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5578 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5579 | value_loc, |
| 5580 | IP, |
| 5581 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5582 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5583 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5584 | DCHECK(!needs_write_barrier); |
| 5585 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5586 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5587 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5588 | |
| 5589 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5590 | Location temp1_loc = locations->GetTemp(0); |
| 5591 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5592 | Location temp2_loc = locations->GetTemp(1); |
| 5593 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5594 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5595 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5596 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5597 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5598 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5599 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5600 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5601 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5602 | codegen_->AddSlowPath(slow_path); |
| 5603 | if (instruction->GetValueCanBeNull()) { |
| 5604 | Label non_zero; |
| 5605 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5606 | if (index.IsConstant()) { |
| 5607 | size_t offset = |
| 5608 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5609 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5610 | } else { |
| 5611 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5612 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5613 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5614 | value_loc, |
| 5615 | IP, |
| 5616 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5617 | } |
| 5618 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5619 | __ b(&done); |
| 5620 | __ Bind(&non_zero); |
| 5621 | } |
| 5622 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5623 | // Note that when read barriers are enabled, the type checks |
| 5624 | // are performed without read barriers. This is fine, even in |
| 5625 | // the case where a class object is in the from-space after |
| 5626 | // the flip, as a comparison involving such a type would not |
| 5627 | // produce a false positive; it may of course produce a false |
| 5628 | // negative, in which case we would take the ArraySet slow |
| 5629 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5630 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5631 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5632 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5633 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5634 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5635 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5636 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5637 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5638 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5639 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5640 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5641 | // nor `temp2`, as we are comparing two poisoned references. |
| 5642 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5643 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5644 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5645 | Label do_put; |
| 5646 | __ b(&do_put, EQ); |
| 5647 | // If heap poisoning is enabled, the `temp1` reference has |
| 5648 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5649 | __ MaybeUnpoisonHeapReference(temp1); |
| 5650 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5651 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5652 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5653 | // If heap poisoning is enabled, no need to unpoison |
| 5654 | // `temp1`, as we are comparing against null below. |
| 5655 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5656 | __ Bind(&do_put); |
| 5657 | } else { |
| 5658 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5659 | } |
| 5660 | } |
| 5661 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5662 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5663 | if (kPoisonHeapReferences) { |
| 5664 | // Note that in the case where `value` is a null reference, |
| 5665 | // we do not enter this block, as a null reference does not |
| 5666 | // need poisoning. |
| 5667 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5668 | __ Mov(temp1, value); |
| 5669 | __ PoisonHeapReference(temp1); |
| 5670 | source = temp1; |
| 5671 | } |
| 5672 | |
| 5673 | if (index.IsConstant()) { |
| 5674 | size_t offset = |
| 5675 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5676 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5677 | } else { |
| 5678 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5679 | |
| 5680 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5681 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5682 | Location::RegisterLocation(source), |
| 5683 | IP, |
| 5684 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5685 | } |
| 5686 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5687 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5688 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5689 | } |
| 5690 | |
| 5691 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5692 | |
| 5693 | if (done.IsLinked()) { |
| 5694 | __ Bind(&done); |
| 5695 | } |
| 5696 | |
| 5697 | if (slow_path != nullptr) { |
| 5698 | __ Bind(slow_path->GetExitLabel()); |
| 5699 | } |
| 5700 | |
| 5701 | break; |
| 5702 | } |
| 5703 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5704 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5705 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5706 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5707 | size_t offset = |
| 5708 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5709 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5710 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5711 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5712 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5713 | } |
| 5714 | break; |
| 5715 | } |
| 5716 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5717 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5718 | Location value = locations->InAt(2); |
| 5719 | DCHECK(value.IsFpuRegister()); |
| 5720 | if (index.IsConstant()) { |
| 5721 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5722 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5723 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5724 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5725 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5726 | } |
| 5727 | break; |
| 5728 | } |
| 5729 | |
| 5730 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5731 | Location value = locations->InAt(2); |
| 5732 | DCHECK(value.IsFpuRegisterPair()); |
| 5733 | if (index.IsConstant()) { |
| 5734 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5735 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5736 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5737 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5738 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5739 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5740 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5741 | break; |
| 5742 | } |
| 5743 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5744 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5745 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5746 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5747 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5748 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5749 | // Objects are handled in the switch. |
| 5750 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5751 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5752 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5756 | LocationSummary* locations = |
| 5757 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5758 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5759 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5763 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5764 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5765 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5766 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5767 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5768 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5769 | // Mask out compression flag from String's array length. |
| 5770 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5771 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5772 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5773 | } |
| 5774 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5775 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5776 | LocationSummary* locations = |
| 5777 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5778 | |
| 5779 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5780 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5781 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5782 | } |
| 5783 | |
| 5784 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5785 | LocationSummary* locations = instruction->GetLocations(); |
| 5786 | Location out = locations->Out(); |
| 5787 | Location first = locations->InAt(0); |
| 5788 | Location second = locations->InAt(1); |
| 5789 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5790 | if (second.IsRegister()) { |
| 5791 | __ add(out.AsRegister<Register>(), |
| 5792 | first.AsRegister<Register>(), |
| 5793 | ShifterOperand(second.AsRegister<Register>())); |
| 5794 | } else { |
| 5795 | __ AddConstant(out.AsRegister<Register>(), |
| 5796 | first.AsRegister<Register>(), |
| 5797 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5798 | } |
| 5799 | } |
| 5800 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5801 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5802 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5803 | InvokeRuntimeCallingConvention calling_convention; |
| 5804 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5805 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5806 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5807 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5808 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5812 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5813 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5814 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5815 | codegen_->AddSlowPath(slow_path); |
| 5816 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5817 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5818 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5819 | |
| 5820 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5821 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5822 | } |
| 5823 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5824 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5825 | Register card, |
| 5826 | Register object, |
| 5827 | Register value, |
| 5828 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5829 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5830 | if (can_be_null) { |
| 5831 | __ CompareAndBranchIfZero(value, &is_null); |
| 5832 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5833 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5834 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5835 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5836 | if (can_be_null) { |
| 5837 | __ Bind(&is_null); |
| 5838 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5839 | } |
| 5840 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5841 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5842 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5846 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5847 | } |
| 5848 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5849 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5850 | LocationSummary* locations = |
| 5851 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5852 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5856 | HBasicBlock* block = instruction->GetBlock(); |
| 5857 | if (block->GetLoopInformation() != nullptr) { |
| 5858 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5859 | // The back edge will generate the suspend check. |
| 5860 | return; |
| 5861 | } |
| 5862 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5863 | // The goto will generate the suspend check. |
| 5864 | return; |
| 5865 | } |
| 5866 | GenerateSuspendCheck(instruction, nullptr); |
| 5867 | } |
| 5868 | |
| 5869 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5870 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5871 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5872 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5873 | if (slow_path == nullptr) { |
| 5874 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5875 | instruction->SetSlowPath(slow_path); |
| 5876 | codegen_->AddSlowPath(slow_path); |
| 5877 | if (successor != nullptr) { |
| 5878 | DCHECK(successor->IsLoopHeader()); |
| 5879 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5880 | } |
| 5881 | } else { |
| 5882 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5883 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5884 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5885 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5886 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5887 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5888 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5889 | __ Bind(slow_path->GetReturnLabel()); |
| 5890 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5891 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5892 | __ b(slow_path->GetEntryLabel()); |
| 5893 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5894 | } |
| 5895 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5896 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5897 | return codegen_->GetAssembler(); |
| 5898 | } |
| 5899 | |
| 5900 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5901 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5902 | Location source = move->GetSource(); |
| 5903 | Location destination = move->GetDestination(); |
| 5904 | |
| 5905 | if (source.IsRegister()) { |
| 5906 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5907 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5908 | } else if (destination.IsFpuRegister()) { |
| 5909 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5910 | } else { |
| 5911 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5912 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5913 | SP, destination.GetStackIndex()); |
| 5914 | } |
| 5915 | } else if (source.IsStackSlot()) { |
| 5916 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5917 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5918 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5919 | } else if (destination.IsFpuRegister()) { |
| 5920 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5921 | } else { |
| 5922 | DCHECK(destination.IsStackSlot()); |
| 5923 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5924 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5925 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5926 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5927 | if (destination.IsRegister()) { |
| 5928 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5929 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5930 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5931 | } else { |
| 5932 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5933 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5934 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5935 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5936 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5937 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5938 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5939 | } else if (destination.IsRegisterPair()) { |
| 5940 | DCHECK(ExpectedPairLayout(destination)); |
| 5941 | __ LoadFromOffset( |
| 5942 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5943 | } else { |
| 5944 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5945 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5946 | SP, |
| 5947 | source.GetStackIndex()); |
| 5948 | } |
| 5949 | } else if (source.IsRegisterPair()) { |
| 5950 | if (destination.IsRegisterPair()) { |
| 5951 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5952 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5953 | } else if (destination.IsFpuRegisterPair()) { |
| 5954 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5955 | source.AsRegisterPairLow<Register>(), |
| 5956 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5957 | } else { |
| 5958 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5959 | DCHECK(ExpectedPairLayout(source)); |
| 5960 | __ StoreToOffset( |
| 5961 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5962 | } |
| 5963 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5964 | if (destination.IsRegisterPair()) { |
| 5965 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5966 | destination.AsRegisterPairHigh<Register>(), |
| 5967 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5968 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5969 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5970 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5971 | } else { |
| 5972 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5973 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5974 | SP, |
| 5975 | destination.GetStackIndex()); |
| 5976 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5977 | } else { |
| 5978 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5979 | HConstant* constant = source.GetConstant(); |
| 5980 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5981 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5982 | if (destination.IsRegister()) { |
| 5983 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5984 | } else { |
| 5985 | DCHECK(destination.IsStackSlot()); |
| 5986 | __ LoadImmediate(IP, value); |
| 5987 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5988 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5989 | } else if (constant->IsLongConstant()) { |
| 5990 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5991 | if (destination.IsRegisterPair()) { |
| 5992 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5993 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5994 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5995 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5996 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5997 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5998 | __ LoadImmediate(IP, High32Bits(value)); |
| 5999 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6000 | } |
| 6001 | } else if (constant->IsDoubleConstant()) { |
| 6002 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6003 | if (destination.IsFpuRegisterPair()) { |
| 6004 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6005 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6006 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6007 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6008 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 6009 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6010 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 6011 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6012 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6013 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6014 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6015 | float value = constant->AsFloatConstant()->GetValue(); |
| 6016 | if (destination.IsFpuRegister()) { |
| 6017 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 6018 | } else { |
| 6019 | DCHECK(destination.IsStackSlot()); |
| 6020 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 6021 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6022 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6023 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 6028 | __ Mov(IP, reg); |
| 6029 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 6030 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 6031 | } |
| 6032 | |
| 6033 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 6034 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 6035 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6036 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6037 | SP, mem1 + stack_offset); |
| 6038 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 6039 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6040 | SP, mem2 + stack_offset); |
| 6041 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 6042 | } |
| 6043 | |
| 6044 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6045 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6046 | Location source = move->GetSource(); |
| 6047 | Location destination = move->GetDestination(); |
| 6048 | |
| 6049 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6050 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 6051 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 6052 | __ Mov(IP, source.AsRegister<Register>()); |
| 6053 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6054 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6055 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6056 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6057 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6058 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6059 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 6060 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6061 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6062 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6063 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6064 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6065 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6066 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6067 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6068 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6069 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6070 | destination.AsRegisterPairHigh<Register>(), |
| 6071 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6072 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6073 | Register low_reg = source.IsRegisterPair() |
| 6074 | ? source.AsRegisterPairLow<Register>() |
| 6075 | : destination.AsRegisterPairLow<Register>(); |
| 6076 | int mem = source.IsRegisterPair() |
| 6077 | ? destination.GetStackIndex() |
| 6078 | : source.GetStackIndex(); |
| 6079 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6080 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6081 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6082 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6083 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6084 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 6085 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6086 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6087 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6088 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6089 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 6090 | DRegister reg = source.IsFpuRegisterPair() |
| 6091 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 6092 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 6093 | int mem = source.IsFpuRegisterPair() |
| 6094 | ? destination.GetStackIndex() |
| 6095 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6096 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6097 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6098 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6099 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 6100 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 6101 | : destination.AsFpuRegister<SRegister>(); |
| 6102 | int mem = source.IsFpuRegister() |
| 6103 | ? destination.GetStackIndex() |
| 6104 | : source.GetStackIndex(); |
| 6105 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6106 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6107 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6108 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6109 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6110 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 6111 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6112 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6113 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 6118 | __ Push(static_cast<Register>(reg)); |
| 6119 | } |
| 6120 | |
| 6121 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 6122 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6123 | } |
| 6124 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6125 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 6126 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6127 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6128 | case HLoadClass::LoadKind::kInvalid: |
| 6129 | LOG(FATAL) << "UNREACHABLE"; |
| 6130 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6131 | case HLoadClass::LoadKind::kReferrersClass: |
| 6132 | break; |
| 6133 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6134 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6135 | break; |
| 6136 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6137 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6138 | break; |
| 6139 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6140 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6141 | case HLoadClass::LoadKind::kBssEntry: |
| 6142 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6143 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6144 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6145 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6146 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6147 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6148 | break; |
| 6149 | } |
| 6150 | return desired_class_load_kind; |
| 6151 | } |
| 6152 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6153 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6154 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6155 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6156 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6157 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6158 | cls, |
| 6159 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6160 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6161 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6162 | return; |
| 6163 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6164 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6165 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6166 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6167 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6168 | ? LocationSummary::kCallOnSlowPath |
| 6169 | : LocationSummary::kNoCall; |
| 6170 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6171 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6172 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6173 | } |
| 6174 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6175 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6177 | } |
| 6178 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6179 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6180 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6181 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6182 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6183 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6184 | locations->AddTemp(Location::RequiresRegister()); |
| 6185 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6186 | InvokeRuntimeCallingConvention calling_convention; |
| 6187 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6188 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6189 | // that the the kPrimNot result register is the same as the first argument register. |
| 6190 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6191 | } else { |
| 6192 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6193 | } |
| 6194 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6195 | } |
| 6196 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6197 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6198 | // move. |
| 6199 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6200 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6201 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6202 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6203 | return; |
| 6204 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6205 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6206 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6207 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6208 | Location out_loc = locations->Out(); |
| 6209 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6210 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6211 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6212 | ? kWithoutReadBarrier |
| 6213 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6214 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6215 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6216 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6217 | DCHECK(!cls->CanCallRuntime()); |
| 6218 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6219 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6220 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6221 | GenerateGcRootFieldLoad(cls, |
| 6222 | out_loc, |
| 6223 | current_method, |
| 6224 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6225 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6226 | break; |
| 6227 | } |
| 6228 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6229 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6230 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6231 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6232 | cls->GetTypeIndex())); |
| 6233 | break; |
| 6234 | } |
| 6235 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6236 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6237 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6238 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6239 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6240 | __ BindTrackedLabel(&labels->movw_label); |
| 6241 | __ movw(out, /* placeholder */ 0u); |
| 6242 | __ BindTrackedLabel(&labels->movt_label); |
| 6243 | __ movt(out, /* placeholder */ 0u); |
| 6244 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6245 | __ add(out, out, ShifterOperand(PC)); |
| 6246 | break; |
| 6247 | } |
| 6248 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6249 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6250 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6251 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6252 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6253 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6254 | break; |
| 6255 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6256 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6257 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6258 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6259 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6260 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6261 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6262 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6263 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6264 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6265 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6266 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6267 | __ add(temp, temp, ShifterOperand(PC)); |
| 6268 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6269 | generate_null_check = true; |
| 6270 | break; |
| 6271 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6272 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6273 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6274 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6275 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6276 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6277 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6278 | break; |
| 6279 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6280 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6281 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6282 | LOG(FATAL) << "UNREACHABLE"; |
| 6283 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6284 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6285 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6286 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6287 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6288 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6289 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6290 | codegen_->AddSlowPath(slow_path); |
| 6291 | if (generate_null_check) { |
| 6292 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6293 | } |
| 6294 | if (cls->MustGenerateClinitCheck()) { |
| 6295 | GenerateClassInitializationCheck(slow_path, out); |
| 6296 | } else { |
| 6297 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6298 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6299 | } |
| 6300 | } |
| 6301 | |
| 6302 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6303 | LocationSummary* locations = |
| 6304 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6306 | if (check->HasUses()) { |
| 6307 | locations->SetOut(Location::SameAsFirstInput()); |
| 6308 | } |
| 6309 | } |
| 6310 | |
| 6311 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6312 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6313 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6314 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6315 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6316 | GenerateClassInitializationCheck(slow_path, |
| 6317 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6318 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6319 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6320 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6321 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6322 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6323 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6324 | __ b(slow_path->GetEntryLabel(), LT); |
| 6325 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6326 | // properly. Therefore, we do a memory fence. |
| 6327 | __ dmb(ISH); |
| 6328 | __ Bind(slow_path->GetExitLabel()); |
| 6329 | } |
| 6330 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6331 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6332 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6333 | switch (desired_string_load_kind) { |
| 6334 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6335 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6336 | break; |
| 6337 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6338 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6339 | break; |
| 6340 | case HLoadString::LoadKind::kBootImageAddress: |
| 6341 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6342 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6343 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6344 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6345 | case HLoadString::LoadKind::kJitTableAddress: |
| 6346 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6347 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6348 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6349 | break; |
| 6350 | } |
| 6351 | return desired_string_load_kind; |
| 6352 | } |
| 6353 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6354 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6355 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6356 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6357 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6358 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6359 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6360 | } else { |
| 6361 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6362 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6363 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6364 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6365 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6366 | // 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] | 6367 | locations->AddTemp(Location::RequiresRegister()); |
| 6368 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6369 | InvokeRuntimeCallingConvention calling_convention; |
| 6370 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6371 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6372 | // that the the kPrimNot result register is the same as the first argument register. |
| 6373 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6374 | } else { |
| 6375 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6376 | } |
| 6377 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6378 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6379 | } |
| 6380 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6381 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6382 | // move. |
| 6383 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6384 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6385 | Location out_loc = locations->Out(); |
| 6386 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6387 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6388 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6389 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6390 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6391 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6392 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6393 | load->GetStringIndex())); |
| 6394 | return; // No dex cache slow path. |
| 6395 | } |
| 6396 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6397 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6398 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6399 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6400 | __ BindTrackedLabel(&labels->movw_label); |
| 6401 | __ movw(out, /* placeholder */ 0u); |
| 6402 | __ BindTrackedLabel(&labels->movt_label); |
| 6403 | __ movt(out, /* placeholder */ 0u); |
| 6404 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6405 | __ add(out, out, ShifterOperand(PC)); |
| 6406 | return; // No dex cache slow path. |
| 6407 | } |
| 6408 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6409 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6410 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6411 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6412 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6413 | return; // No dex cache slow path. |
| 6414 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6415 | case HLoadString::LoadKind::kBssEntry: { |
| 6416 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6417 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6418 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6419 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6420 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6421 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6422 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6423 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6424 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6425 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6426 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6427 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6428 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6429 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 6430 | codegen_->AddSlowPath(slow_path); |
| 6431 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6432 | __ Bind(slow_path->GetExitLabel()); |
| 6433 | return; |
| 6434 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6435 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6436 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6437 | load->GetStringIndex(), |
| 6438 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6439 | // /* GcRoot<mirror::String> */ out = *out |
| 6440 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6441 | return; |
| 6442 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6443 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6444 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6445 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6446 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6447 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6448 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6449 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6450 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6451 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6452 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6453 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6456 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6457 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6458 | } |
| 6459 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6460 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6461 | LocationSummary* locations = |
| 6462 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6463 | locations->SetOut(Location::RequiresRegister()); |
| 6464 | } |
| 6465 | |
| 6466 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6467 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6468 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6469 | } |
| 6470 | |
| 6471 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6472 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6473 | } |
| 6474 | |
| 6475 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6476 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6477 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6481 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6482 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6483 | InvokeRuntimeCallingConvention calling_convention; |
| 6484 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6485 | } |
| 6486 | |
| 6487 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6488 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6489 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6492 | // Temp is used for read barrier. |
| 6493 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6494 | if (kEmitCompilerReadBarrier && |
| 6495 | (kUseBakerReadBarrier || |
| 6496 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6497 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6498 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6499 | return 1; |
| 6500 | } |
| 6501 | return 0; |
| 6502 | } |
| 6503 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6504 | // 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] | 6505 | // interface pointer, one for loading the current interface. |
| 6506 | // The other checks have one temp for loading the object's class. |
| 6507 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6508 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6509 | return 3; |
| 6510 | } |
| 6511 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6512 | } |
| 6513 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6514 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6515 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6516 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6517 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6518 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6519 | case TypeCheckKind::kExactCheck: |
| 6520 | case TypeCheckKind::kAbstractClassCheck: |
| 6521 | case TypeCheckKind::kClassHierarchyCheck: |
| 6522 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6523 | call_kind = |
| 6524 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6525 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6526 | break; |
| 6527 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6528 | case TypeCheckKind::kUnresolvedCheck: |
| 6529 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6530 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6531 | break; |
| 6532 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6533 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6534 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6535 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6536 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6537 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6538 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6539 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6540 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6541 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6542 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6543 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6544 | } |
| 6545 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6546 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6547 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6548 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6549 | Location obj_loc = locations->InAt(0); |
| 6550 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6551 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6552 | Location out_loc = locations->Out(); |
| 6553 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6554 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6555 | DCHECK_LE(num_temps, 1u); |
| 6556 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6557 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6558 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6559 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6560 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6561 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6562 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6563 | |
| 6564 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6565 | // avoid null check if we know obj is not null. |
| 6566 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6567 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6568 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6569 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6570 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6571 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6572 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6573 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6574 | out_loc, |
| 6575 | obj_loc, |
| 6576 | class_offset, |
| 6577 | maybe_temp_loc, |
| 6578 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6579 | __ cmp(out, ShifterOperand(cls)); |
| 6580 | // Classes must be equal for the instanceof to succeed. |
| 6581 | __ b(&zero, NE); |
| 6582 | __ LoadImmediate(out, 1); |
| 6583 | __ b(&done); |
| 6584 | break; |
| 6585 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6586 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6587 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6588 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6589 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6590 | out_loc, |
| 6591 | obj_loc, |
| 6592 | class_offset, |
| 6593 | maybe_temp_loc, |
| 6594 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6595 | // If the class is abstract, we eagerly fetch the super class of the |
| 6596 | // object to avoid doing a comparison we know will fail. |
| 6597 | Label loop; |
| 6598 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6599 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6600 | GenerateReferenceLoadOneRegister(instruction, |
| 6601 | out_loc, |
| 6602 | super_offset, |
| 6603 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6604 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6606 | __ CompareAndBranchIfZero(out, &done); |
| 6607 | __ cmp(out, ShifterOperand(cls)); |
| 6608 | __ b(&loop, NE); |
| 6609 | __ LoadImmediate(out, 1); |
| 6610 | if (zero.IsLinked()) { |
| 6611 | __ b(&done); |
| 6612 | } |
| 6613 | break; |
| 6614 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6615 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6616 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6617 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6618 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6619 | out_loc, |
| 6620 | obj_loc, |
| 6621 | class_offset, |
| 6622 | maybe_temp_loc, |
| 6623 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6624 | // Walk over the class hierarchy to find a match. |
| 6625 | Label loop, success; |
| 6626 | __ Bind(&loop); |
| 6627 | __ cmp(out, ShifterOperand(cls)); |
| 6628 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6629 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6630 | GenerateReferenceLoadOneRegister(instruction, |
| 6631 | out_loc, |
| 6632 | super_offset, |
| 6633 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6634 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6635 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6636 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6637 | __ b(&done); |
| 6638 | __ Bind(&success); |
| 6639 | __ LoadImmediate(out, 1); |
| 6640 | if (zero.IsLinked()) { |
| 6641 | __ b(&done); |
| 6642 | } |
| 6643 | break; |
| 6644 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6645 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6646 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6647 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6648 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6649 | out_loc, |
| 6650 | obj_loc, |
| 6651 | class_offset, |
| 6652 | maybe_temp_loc, |
| 6653 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6654 | // Do an exact check. |
| 6655 | Label exact_check; |
| 6656 | __ cmp(out, ShifterOperand(cls)); |
| 6657 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6658 | // 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] | 6659 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6660 | GenerateReferenceLoadOneRegister(instruction, |
| 6661 | out_loc, |
| 6662 | component_offset, |
| 6663 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6664 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6665 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6666 | __ CompareAndBranchIfZero(out, &done); |
| 6667 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6668 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6669 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6670 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6671 | __ LoadImmediate(out, 1); |
| 6672 | __ b(&done); |
| 6673 | break; |
| 6674 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6675 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6676 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6677 | // No read barrier since the slow path will retry upon failure. |
| 6678 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6679 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6680 | out_loc, |
| 6681 | obj_loc, |
| 6682 | class_offset, |
| 6683 | maybe_temp_loc, |
| 6684 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6685 | __ cmp(out, ShifterOperand(cls)); |
| 6686 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6687 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6688 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6689 | codegen_->AddSlowPath(slow_path); |
| 6690 | __ b(slow_path->GetEntryLabel(), NE); |
| 6691 | __ LoadImmediate(out, 1); |
| 6692 | if (zero.IsLinked()) { |
| 6693 | __ b(&done); |
| 6694 | } |
| 6695 | break; |
| 6696 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6697 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6698 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6699 | case TypeCheckKind::kInterfaceCheck: { |
| 6700 | // 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] | 6701 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6702 | // cases. |
| 6703 | // |
| 6704 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6705 | // entry point without resorting to a type checking slow path |
| 6706 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6707 | // require to assign fixed registers for the inputs of this |
| 6708 | // HInstanceOf instruction (following the runtime calling |
| 6709 | // convention), which might be cluttered by the potential first |
| 6710 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6711 | // |
| 6712 | // TODO: Introduce a new runtime entry point taking the object |
| 6713 | // to test (instead of its class) as argument, and let it deal |
| 6714 | // with the read barrier issues. This will let us refactor this |
| 6715 | // case of the `switch` code as it was previously (with a direct |
| 6716 | // call to the runtime not using a type checking slow path). |
| 6717 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6718 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6719 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6720 | /* is_fatal */ false); |
| 6721 | codegen_->AddSlowPath(slow_path); |
| 6722 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6723 | if (zero.IsLinked()) { |
| 6724 | __ b(&done); |
| 6725 | } |
| 6726 | break; |
| 6727 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6728 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6729 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6731 | __ Bind(&zero); |
| 6732 | __ LoadImmediate(out, 0); |
| 6733 | } |
| 6734 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6735 | if (done.IsLinked()) { |
| 6736 | __ Bind(&done); |
| 6737 | } |
| 6738 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6739 | if (slow_path != nullptr) { |
| 6740 | __ Bind(slow_path->GetExitLabel()); |
| 6741 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6742 | } |
| 6743 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6744 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6745 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6746 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6747 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6748 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6749 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6750 | case TypeCheckKind::kExactCheck: |
| 6751 | case TypeCheckKind::kAbstractClassCheck: |
| 6752 | case TypeCheckKind::kClassHierarchyCheck: |
| 6753 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6754 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6755 | LocationSummary::kCallOnSlowPath : |
| 6756 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6757 | break; |
| 6758 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6759 | case TypeCheckKind::kUnresolvedCheck: |
| 6760 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6761 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6762 | break; |
| 6763 | } |
| 6764 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6765 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6766 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6767 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6768 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6772 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6773 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6774 | Location obj_loc = locations->InAt(0); |
| 6775 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6776 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6777 | Location temp_loc = locations->GetTemp(0); |
| 6778 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6779 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6780 | DCHECK_LE(num_temps, 3u); |
| 6781 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6782 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6783 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6784 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6785 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6786 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6787 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6788 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6789 | const uint32_t object_array_data_offset = |
| 6790 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6791 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6792 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6793 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6794 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6795 | bool is_type_check_slow_path_fatal = false; |
| 6796 | if (!kEmitCompilerReadBarrier) { |
| 6797 | is_type_check_slow_path_fatal = |
| 6798 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6799 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6800 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6801 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6802 | !instruction->CanThrowIntoCatchBlock(); |
| 6803 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6804 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6805 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6806 | is_type_check_slow_path_fatal); |
| 6807 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6808 | |
| 6809 | Label done; |
| 6810 | // Avoid null check if we know obj is not null. |
| 6811 | if (instruction->MustDoNullCheck()) { |
| 6812 | __ CompareAndBranchIfZero(obj, &done); |
| 6813 | } |
| 6814 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6815 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6816 | case TypeCheckKind::kExactCheck: |
| 6817 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6818 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6819 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6820 | temp_loc, |
| 6821 | obj_loc, |
| 6822 | class_offset, |
| 6823 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6824 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6825 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6826 | __ cmp(temp, ShifterOperand(cls)); |
| 6827 | // Jump to slow path for throwing the exception or doing a |
| 6828 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6829 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6830 | break; |
| 6831 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6832 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6833 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6834 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6835 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6836 | temp_loc, |
| 6837 | obj_loc, |
| 6838 | class_offset, |
| 6839 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6840 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6841 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6842 | // If the class is abstract, we eagerly fetch the super class of the |
| 6843 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6844 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6845 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6846 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6847 | GenerateReferenceLoadOneRegister(instruction, |
| 6848 | temp_loc, |
| 6849 | super_offset, |
| 6850 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6851 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6852 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6853 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6854 | // exception. |
| 6855 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6856 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6857 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6858 | __ cmp(temp, ShifterOperand(cls)); |
| 6859 | __ b(&loop, NE); |
| 6860 | break; |
| 6861 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6862 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6863 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6864 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6865 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6866 | temp_loc, |
| 6867 | obj_loc, |
| 6868 | class_offset, |
| 6869 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6870 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6871 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6872 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6873 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6874 | __ Bind(&loop); |
| 6875 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6876 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6877 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6878 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6879 | GenerateReferenceLoadOneRegister(instruction, |
| 6880 | temp_loc, |
| 6881 | super_offset, |
| 6882 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6883 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6884 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6885 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6886 | // exception. |
| 6887 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6888 | // Otherwise, jump to the beginning of the loop. |
| 6889 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6890 | break; |
| 6891 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6892 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6893 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6894 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6895 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6896 | temp_loc, |
| 6897 | obj_loc, |
| 6898 | class_offset, |
| 6899 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6900 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6901 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6902 | // Do an exact check. |
| 6903 | __ cmp(temp, ShifterOperand(cls)); |
| 6904 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6905 | |
| 6906 | // 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] | 6907 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6908 | GenerateReferenceLoadOneRegister(instruction, |
| 6909 | temp_loc, |
| 6910 | component_offset, |
| 6911 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6912 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6913 | // If the component type is null, jump to the slow path to throw the exception. |
| 6914 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6915 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6916 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6917 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6918 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6919 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6920 | break; |
| 6921 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6922 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6923 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6924 | // 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] | 6925 | // We cannot directly call the CheckCast runtime entry point |
| 6926 | // without resorting to a type checking slow path here (i.e. by |
| 6927 | // calling InvokeRuntime directly), as it would require to |
| 6928 | // assign fixed registers for the inputs of this HInstanceOf |
| 6929 | // instruction (following the runtime calling convention), which |
| 6930 | // might be cluttered by the potential first read barrier |
| 6931 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6932 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6933 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6934 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6935 | |
| 6936 | case TypeCheckKind::kInterfaceCheck: { |
| 6937 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6938 | // positives by doing this. |
| 6939 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6940 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6941 | temp_loc, |
| 6942 | obj_loc, |
| 6943 | class_offset, |
| 6944 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6945 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6946 | |
| 6947 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6948 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6949 | temp_loc, |
| 6950 | temp_loc, |
| 6951 | iftable_offset, |
| 6952 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6953 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6954 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6955 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6956 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6957 | Label start_loop; |
| 6958 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6959 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 6960 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6961 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6962 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6963 | // Go to next interface. |
| 6964 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 6965 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 6966 | maybe_temp2_loc.AsRegister<Register>(), |
| 6967 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6968 | // Compare the classes and continue the loop if they do not match. |
| 6969 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 6970 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6971 | break; |
| 6972 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6973 | } |
| 6974 | __ Bind(&done); |
| 6975 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6976 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6977 | } |
| 6978 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6979 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6980 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6981 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6982 | InvokeRuntimeCallingConvention calling_convention; |
| 6983 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6984 | } |
| 6985 | |
| 6986 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6987 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6988 | instruction, |
| 6989 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6990 | if (instruction->IsEnter()) { |
| 6991 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6992 | } else { |
| 6993 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6994 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6995 | } |
| 6996 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6997 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6998 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6999 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7000 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7001 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7002 | LocationSummary* locations = |
| 7003 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7004 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7005 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7006 | // 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] | 7007 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7008 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 7009 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 7013 | HandleBitwiseOperation(instruction); |
| 7014 | } |
| 7015 | |
| 7016 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 7017 | HandleBitwiseOperation(instruction); |
| 7018 | } |
| 7019 | |
| 7020 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 7021 | HandleBitwiseOperation(instruction); |
| 7022 | } |
| 7023 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 7024 | |
| 7025 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7026 | LocationSummary* locations = |
| 7027 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7028 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7029 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7030 | |
| 7031 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7032 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7033 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7034 | } |
| 7035 | |
| 7036 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7037 | LocationSummary* locations = instruction->GetLocations(); |
| 7038 | Location first = locations->InAt(0); |
| 7039 | Location second = locations->InAt(1); |
| 7040 | Location out = locations->Out(); |
| 7041 | |
| 7042 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7043 | Register first_reg = first.AsRegister<Register>(); |
| 7044 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7045 | Register out_reg = out.AsRegister<Register>(); |
| 7046 | |
| 7047 | switch (instruction->GetOpKind()) { |
| 7048 | case HInstruction::kAnd: |
| 7049 | __ bic(out_reg, first_reg, second_reg); |
| 7050 | break; |
| 7051 | case HInstruction::kOr: |
| 7052 | __ orn(out_reg, first_reg, second_reg); |
| 7053 | break; |
| 7054 | // There is no EON on arm. |
| 7055 | case HInstruction::kXor: |
| 7056 | default: |
| 7057 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7058 | UNREACHABLE(); |
| 7059 | } |
| 7060 | return; |
| 7061 | |
| 7062 | } else { |
| 7063 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7064 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7065 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7066 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7067 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7068 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7069 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7070 | |
| 7071 | switch (instruction->GetOpKind()) { |
| 7072 | case HInstruction::kAnd: |
| 7073 | __ bic(out_low, first_low, second_low); |
| 7074 | __ bic(out_high, first_high, second_high); |
| 7075 | break; |
| 7076 | case HInstruction::kOr: |
| 7077 | __ orn(out_low, first_low, second_low); |
| 7078 | __ orn(out_high, first_high, second_high); |
| 7079 | break; |
| 7080 | // There is no EON on arm. |
| 7081 | case HInstruction::kXor: |
| 7082 | default: |
| 7083 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7084 | UNREACHABLE(); |
| 7085 | } |
| 7086 | } |
| 7087 | } |
| 7088 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7089 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 7090 | HDataProcWithShifterOp* instruction) { |
| 7091 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7092 | instruction->GetType() == Primitive::kPrimLong); |
| 7093 | LocationSummary* locations = |
| 7094 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7095 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7096 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7097 | |
| 7098 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7099 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7100 | locations->SetOut(Location::RequiresRegister(), |
| 7101 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7102 | } |
| 7103 | |
| 7104 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 7105 | HDataProcWithShifterOp* instruction) { |
| 7106 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7107 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7108 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7109 | const Location left = locations->InAt(0); |
| 7110 | const Location right = locations->InAt(1); |
| 7111 | const Location out = locations->Out(); |
| 7112 | |
| 7113 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7114 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7115 | |
| 7116 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7117 | ? right.AsRegisterPairLow<Register>() |
| 7118 | : right.AsRegister<Register>(); |
| 7119 | |
| 7120 | GenerateDataProcInstruction(kind, |
| 7121 | out.AsRegister<Register>(), |
| 7122 | left.AsRegister<Register>(), |
| 7123 | ShifterOperand(second, |
| 7124 | ShiftFromOpKind(op_kind), |
| 7125 | instruction->GetShiftAmount()), |
| 7126 | codegen_); |
| 7127 | } else { |
| 7128 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7129 | |
| 7130 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7131 | const Register second = right.AsRegister<Register>(); |
| 7132 | |
| 7133 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 7134 | GenerateDataProc(kind, |
| 7135 | out, |
| 7136 | left, |
| 7137 | ShifterOperand(second), |
| 7138 | ShifterOperand(second, ASR, 31), |
| 7139 | codegen_); |
| 7140 | } else { |
| 7141 | GenerateLongDataProc(instruction, codegen_); |
| 7142 | } |
| 7143 | } |
| 7144 | } |
| 7145 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7146 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 7147 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7148 | if (value == 0xffffffffu) { |
| 7149 | if (out != first) { |
| 7150 | __ mov(out, ShifterOperand(first)); |
| 7151 | } |
| 7152 | return; |
| 7153 | } |
| 7154 | if (value == 0u) { |
| 7155 | __ mov(out, ShifterOperand(0)); |
| 7156 | return; |
| 7157 | } |
| 7158 | ShifterOperand so; |
| 7159 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 7160 | __ and_(out, first, so); |
| 7161 | } else { |
| 7162 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 7163 | __ bic(out, first, ShifterOperand(~value)); |
| 7164 | } |
| 7165 | } |
| 7166 | |
| 7167 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 7168 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7169 | if (value == 0u) { |
| 7170 | if (out != first) { |
| 7171 | __ mov(out, ShifterOperand(first)); |
| 7172 | } |
| 7173 | return; |
| 7174 | } |
| 7175 | if (value == 0xffffffffu) { |
| 7176 | __ mvn(out, ShifterOperand(0)); |
| 7177 | return; |
| 7178 | } |
| 7179 | ShifterOperand so; |
| 7180 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 7181 | __ orr(out, first, so); |
| 7182 | } else { |
| 7183 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 7184 | __ orn(out, first, ShifterOperand(~value)); |
| 7185 | } |
| 7186 | } |
| 7187 | |
| 7188 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7189 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7190 | if (value == 0u) { |
| 7191 | if (out != first) { |
| 7192 | __ mov(out, ShifterOperand(first)); |
| 7193 | } |
| 7194 | return; |
| 7195 | } |
| 7196 | __ eor(out, first, ShifterOperand(value)); |
| 7197 | } |
| 7198 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7199 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7200 | Location first, |
| 7201 | uint64_t value) { |
| 7202 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7203 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7204 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7205 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7206 | uint32_t value_low = Low32Bits(value); |
| 7207 | uint32_t value_high = High32Bits(value); |
| 7208 | if (value_low == 0u) { |
| 7209 | if (out_low != first_low) { |
| 7210 | __ mov(out_low, ShifterOperand(first_low)); |
| 7211 | } |
| 7212 | __ AddConstant(out_high, first_high, value_high); |
| 7213 | return; |
| 7214 | } |
| 7215 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7216 | ShifterOperand so; |
| 7217 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7218 | __ adc(out_high, first_high, so); |
| 7219 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7220 | __ sbc(out_high, first_high, so); |
| 7221 | } else { |
| 7222 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7223 | UNREACHABLE(); |
| 7224 | } |
| 7225 | } |
| 7226 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7227 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7228 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7229 | Location first = locations->InAt(0); |
| 7230 | Location second = locations->InAt(1); |
| 7231 | Location out = locations->Out(); |
| 7232 | |
| 7233 | if (second.IsConstant()) { |
| 7234 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7235 | uint32_t value_low = Low32Bits(value); |
| 7236 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7237 | Register first_reg = first.AsRegister<Register>(); |
| 7238 | Register out_reg = out.AsRegister<Register>(); |
| 7239 | if (instruction->IsAnd()) { |
| 7240 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7241 | } else if (instruction->IsOr()) { |
| 7242 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7243 | } else { |
| 7244 | DCHECK(instruction->IsXor()); |
| 7245 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7246 | } |
| 7247 | } else { |
| 7248 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7249 | uint32_t value_high = High32Bits(value); |
| 7250 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7251 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7252 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7253 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7254 | if (instruction->IsAnd()) { |
| 7255 | GenerateAndConst(out_low, first_low, value_low); |
| 7256 | GenerateAndConst(out_high, first_high, value_high); |
| 7257 | } else if (instruction->IsOr()) { |
| 7258 | GenerateOrrConst(out_low, first_low, value_low); |
| 7259 | GenerateOrrConst(out_high, first_high, value_high); |
| 7260 | } else { |
| 7261 | DCHECK(instruction->IsXor()); |
| 7262 | GenerateEorConst(out_low, first_low, value_low); |
| 7263 | GenerateEorConst(out_high, first_high, value_high); |
| 7264 | } |
| 7265 | } |
| 7266 | return; |
| 7267 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7268 | |
| 7269 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7270 | Register first_reg = first.AsRegister<Register>(); |
| 7271 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7272 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7273 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7274 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7275 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7276 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7277 | } else { |
| 7278 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7279 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7280 | } |
| 7281 | } else { |
| 7282 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7283 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7284 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7285 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7286 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7287 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7288 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7289 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7290 | __ and_(out_low, first_low, second_low); |
| 7291 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7292 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7293 | __ orr(out_low, first_low, second_low); |
| 7294 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7295 | } else { |
| 7296 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7297 | __ eor(out_low, first_low, second_low); |
| 7298 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7299 | } |
| 7300 | } |
| 7301 | } |
| 7302 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7303 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7304 | HInstruction* instruction, |
| 7305 | Location out, |
| 7306 | uint32_t offset, |
| 7307 | Location maybe_temp, |
| 7308 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7309 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7310 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7311 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7312 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7313 | if (kUseBakerReadBarrier) { |
| 7314 | // Load with fast path based Baker's read barrier. |
| 7315 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7316 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7317 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7318 | } else { |
| 7319 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7320 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7321 | // in the following move operation, as we will need it for the |
| 7322 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7323 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7324 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7325 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7326 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7327 | } |
| 7328 | } else { |
| 7329 | // Plain load with no read barrier. |
| 7330 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7331 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7332 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7333 | } |
| 7334 | } |
| 7335 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7336 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7337 | HInstruction* instruction, |
| 7338 | Location out, |
| 7339 | Location obj, |
| 7340 | uint32_t offset, |
| 7341 | Location maybe_temp, |
| 7342 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7343 | Register out_reg = out.AsRegister<Register>(); |
| 7344 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7345 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7346 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7347 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7348 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7349 | // Load with fast path based Baker's read barrier. |
| 7350 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7351 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7352 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7353 | } else { |
| 7354 | // Load with slow path based read barrier. |
| 7355 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7356 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7357 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7358 | } |
| 7359 | } else { |
| 7360 | // Plain load with no read barrier. |
| 7361 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7362 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7363 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7364 | } |
| 7365 | } |
| 7366 | |
| 7367 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7368 | Location root, |
| 7369 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7370 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7371 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7372 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7373 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7374 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7375 | if (kUseBakerReadBarrier) { |
| 7376 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7377 | // Baker's read barrier are used. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7378 | // |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7379 | // Note that we do not actually check the value of |
| 7380 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 7381 | // root or not. Instead, we load into `temp` the read barrier |
| 7382 | // mark entry point corresponding to register `root`. If `temp` |
| 7383 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 7384 | // versa. |
| 7385 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7386 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7387 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7388 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 7389 | // // Slow path. |
| 7390 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7391 | // } |
| 7392 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7393 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 7394 | Location temp = Location::RegisterLocation(LR); |
| 7395 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 7396 | instruction, root, /* entrypoint */ temp); |
| 7397 | codegen_->AddSlowPath(slow_path); |
| 7398 | |
| 7399 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7400 | const int32_t entry_point_offset = |
| 7401 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 7402 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7403 | // threads are suspended or running a checkpoint. |
| 7404 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 7405 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7406 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7407 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7408 | static_assert( |
| 7409 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7410 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7411 | "have different sizes."); |
| 7412 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7413 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7414 | "have different sizes."); |
| 7415 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7416 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 7417 | // checking GetIsGcMarking. |
| 7418 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7419 | __ Bind(slow_path->GetExitLabel()); |
| 7420 | } else { |
| 7421 | // GC root loaded through a slow path for read barriers other |
| 7422 | // than Baker's. |
| 7423 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7424 | __ AddConstant(root_reg, obj, offset); |
| 7425 | // /* mirror::Object* */ root = root->Read() |
| 7426 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7427 | } |
| 7428 | } else { |
| 7429 | // Plain GC root load with no read barrier. |
| 7430 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7431 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7432 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7433 | // do not have to unpoison `root_reg` here. |
| 7434 | } |
| 7435 | } |
| 7436 | |
| 7437 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7438 | Location ref, |
| 7439 | Register obj, |
| 7440 | uint32_t offset, |
| 7441 | Location temp, |
| 7442 | bool needs_null_check) { |
| 7443 | DCHECK(kEmitCompilerReadBarrier); |
| 7444 | DCHECK(kUseBakerReadBarrier); |
| 7445 | |
| 7446 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7447 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7448 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7449 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7450 | 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] | 7451 | } |
| 7452 | |
| 7453 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7454 | Location ref, |
| 7455 | Register obj, |
| 7456 | uint32_t data_offset, |
| 7457 | Location index, |
| 7458 | Location temp, |
| 7459 | bool needs_null_check) { |
| 7460 | DCHECK(kEmitCompilerReadBarrier); |
| 7461 | DCHECK(kUseBakerReadBarrier); |
| 7462 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7463 | static_assert( |
| 7464 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7465 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7466 | // /* HeapReference<Object> */ ref = |
| 7467 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7468 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7469 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7470 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7474 | Location ref, |
| 7475 | Register obj, |
| 7476 | uint32_t offset, |
| 7477 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7478 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7479 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7480 | bool needs_null_check, |
| 7481 | bool always_update_field, |
| 7482 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7483 | DCHECK(kEmitCompilerReadBarrier); |
| 7484 | DCHECK(kUseBakerReadBarrier); |
| 7485 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 7486 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 7487 | // whether we need to enter the slow path to mark the reference. |
| 7488 | // Then, in the slow path, check the gray bit in the lock word of |
| 7489 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 7490 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7491 | // |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7492 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 7493 | // instead, we load into `temp3` the read barrier mark entry point |
| 7494 | // corresponding to register `ref`. If `temp3` is null, it means |
| 7495 | // that `GetIsGcMarking()` is false, and vice versa. |
| 7496 | // |
| 7497 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7498 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 7499 | // // Slow path. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 7500 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7501 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7502 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 7503 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7504 | // if (is_gray) { |
| 7505 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 7506 | // } |
| 7507 | // } else { |
| 7508 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7509 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7510 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7511 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7512 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7513 | // Slow path marking the object `ref` when the GC is marking. The |
| 7514 | // entrypoint will already be loaded in `temp3`. |
| 7515 | Location temp3 = Location::RegisterLocation(LR); |
| 7516 | SlowPathCodeARM* slow_path; |
| 7517 | if (always_update_field) { |
| 7518 | DCHECK(temp2 != nullptr); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 7519 | // LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM only |
| 7520 | // supports address of the form `obj + field_offset`, where `obj` |
| 7521 | // is a register and `field_offset` is a register pair (of which |
| 7522 | // only the lower half is used). Thus `offset` and `scale_factor` |
| 7523 | // above are expected to be null in this code path. |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7524 | DCHECK_EQ(offset, 0u); |
| 7525 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 7526 | Location field_offset = index; |
| 7527 | slow_path = |
| 7528 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 7529 | instruction, |
| 7530 | ref, |
| 7531 | obj, |
| 7532 | offset, |
| 7533 | /* index */ field_offset, |
| 7534 | scale_factor, |
| 7535 | needs_null_check, |
| 7536 | temp_reg, |
| 7537 | *temp2, |
| 7538 | /* entrypoint */ temp3); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7539 | } else { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 7540 | slow_path = new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 7541 | instruction, |
| 7542 | ref, |
| 7543 | obj, |
| 7544 | offset, |
| 7545 | index, |
| 7546 | scale_factor, |
| 7547 | needs_null_check, |
| 7548 | temp_reg, |
| 7549 | /* entrypoint */ temp3); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7550 | } |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7551 | AddSlowPath(slow_path); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7552 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7553 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 7554 | const int32_t entry_point_offset = |
| 7555 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 7556 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7557 | // threads are suspended or running a checkpoint. |
| 7558 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7559 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 7560 | // checking GetIsGcMarking. |
| 7561 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame^] | 7562 | // Fast path: just load the reference. |
| 7563 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7564 | __ Bind(slow_path->GetExitLabel()); |
| 7565 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7566 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7567 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 7568 | Location ref, |
| 7569 | Register obj, |
| 7570 | uint32_t offset, |
| 7571 | Location index, |
| 7572 | ScaleFactor scale_factor, |
| 7573 | bool needs_null_check) { |
| 7574 | Register ref_reg = ref.AsRegister<Register>(); |
| 7575 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7576 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7577 | // Load types involving an "index": ArrayGet, |
| 7578 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7579 | // intrinsics. |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7580 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7581 | if (index.IsConstant()) { |
| 7582 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7583 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7584 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7585 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7586 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7587 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7588 | // intrinsics, which use a register pair as index ("long |
| 7589 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7590 | Register index_reg = index.IsRegisterPair() |
| 7591 | ? index.AsRegisterPairLow<Register>() |
| 7592 | : index.AsRegister<Register>(); |
| 7593 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7594 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7595 | } |
| 7596 | } else { |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7597 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7598 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7599 | } |
| 7600 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7601 | if (needs_null_check) { |
| 7602 | MaybeRecordImplicitNullCheck(instruction); |
| 7603 | } |
| 7604 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7605 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7606 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7607 | } |
| 7608 | |
| 7609 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7610 | Location out, |
| 7611 | Location ref, |
| 7612 | Location obj, |
| 7613 | uint32_t offset, |
| 7614 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7615 | DCHECK(kEmitCompilerReadBarrier); |
| 7616 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7617 | // Insert a slow path based read barrier *after* the reference load. |
| 7618 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7619 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7620 | // reference will be carried out by the runtime within the slow |
| 7621 | // path. |
| 7622 | // |
| 7623 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7624 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7625 | // not used by the artReadBarrierSlow entry point. |
| 7626 | // |
| 7627 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7628 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7629 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7630 | AddSlowPath(slow_path); |
| 7631 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7632 | __ b(slow_path->GetEntryLabel()); |
| 7633 | __ Bind(slow_path->GetExitLabel()); |
| 7634 | } |
| 7635 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7636 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7637 | Location out, |
| 7638 | Location ref, |
| 7639 | Location obj, |
| 7640 | uint32_t offset, |
| 7641 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7642 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7643 | // Baker's read barriers shall be handled by the fast path |
| 7644 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7645 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7646 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7647 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7648 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7649 | } else if (kPoisonHeapReferences) { |
| 7650 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7651 | } |
| 7652 | } |
| 7653 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7654 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7655 | Location out, |
| 7656 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7657 | DCHECK(kEmitCompilerReadBarrier); |
| 7658 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7659 | // Insert a slow path based read barrier *after* the GC root load. |
| 7660 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7661 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7662 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7663 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7664 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7665 | AddSlowPath(slow_path); |
| 7666 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7667 | __ b(slow_path->GetEntryLabel()); |
| 7668 | __ Bind(slow_path->GetExitLabel()); |
| 7669 | } |
| 7670 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7671 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7672 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7673 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 7674 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7675 | } |
| 7676 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7677 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7678 | Register temp) { |
| 7679 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7680 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7681 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7682 | return location.AsRegister<Register>(); |
| 7683 | } |
| 7684 | // For intrinsics we allow any location, so it may be on the stack. |
| 7685 | if (!location.IsRegister()) { |
| 7686 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7687 | return temp; |
| 7688 | } |
| 7689 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7690 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7691 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7692 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7693 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7694 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7695 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7696 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7697 | return temp; |
| 7698 | } |
| 7699 | return location.AsRegister<Register>(); |
| 7700 | } |
| 7701 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7702 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 7703 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7704 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7705 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7706 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7707 | uint32_t offset = |
| 7708 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7709 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7710 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7711 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7712 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7713 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7714 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7715 | break; |
| 7716 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7717 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7718 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7719 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7720 | HArmDexCacheArraysBase* base = |
| 7721 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7722 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7723 | temp.AsRegister<Register>()); |
| 7724 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7725 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7726 | break; |
| 7727 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7728 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7729 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7730 | Register method_reg; |
| 7731 | Register reg = temp.AsRegister<Register>(); |
| 7732 | if (current_method.IsRegister()) { |
| 7733 | method_reg = current_method.AsRegister<Register>(); |
| 7734 | } else { |
| 7735 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7736 | DCHECK(!current_method.IsValid()); |
| 7737 | method_reg = reg; |
| 7738 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7739 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7740 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7741 | __ LoadFromOffset(kLoadWord, |
| 7742 | reg, |
| 7743 | method_reg, |
| 7744 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7745 | // temp = temp[index_in_cache]; |
| 7746 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7747 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7748 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7749 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7750 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7751 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7752 | return callee_method; |
| 7753 | } |
| 7754 | |
| 7755 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 7756 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7757 | |
| 7758 | switch (invoke->GetCodePtrLocation()) { |
| 7759 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7760 | __ bl(GetFrameEntryLabel()); |
| 7761 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7762 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7763 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7764 | __ LoadFromOffset( |
| 7765 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7766 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7767 | // LR() |
| 7768 | __ blx(LR); |
| 7769 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7770 | } |
| 7771 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7772 | DCHECK(!IsLeafMethod()); |
| 7773 | } |
| 7774 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7775 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7776 | Register temp = temp_location.AsRegister<Register>(); |
| 7777 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7778 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7779 | |
| 7780 | // Use the calling convention instead of the location of the receiver, as |
| 7781 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7782 | // slow path, the arguments have been moved to the right place, so here we are |
| 7783 | // guaranteed that the receiver is the first register of the calling convention. |
| 7784 | InvokeDexCallingConvention calling_convention; |
| 7785 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7786 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7787 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7788 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7789 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7790 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7791 | // emit a read barrier for the previous class reference load. |
| 7792 | // However this is not required in practice, as this is an |
| 7793 | // intermediate/temporary reference and because the current |
| 7794 | // concurrent copying collector keeps the from-space memory |
| 7795 | // intact/accessible until the end of the marking phase (the |
| 7796 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7797 | __ MaybeUnpoisonHeapReference(temp); |
| 7798 | // temp = temp->GetMethodAt(method_offset); |
| 7799 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7800 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7801 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7802 | // LR = temp->GetEntryPoint(); |
| 7803 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7804 | // LR(); |
| 7805 | __ blx(LR); |
| 7806 | } |
| 7807 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7808 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7809 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7810 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7811 | } |
| 7812 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7813 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7814 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7815 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7816 | } |
| 7817 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7818 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 7819 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7820 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7821 | } |
| 7822 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7823 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7824 | const DexFile& dex_file, uint32_t element_offset) { |
| 7825 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7826 | } |
| 7827 | |
| 7828 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7829 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7830 | patches->emplace_back(dex_file, offset_or_index); |
| 7831 | return &patches->back(); |
| 7832 | } |
| 7833 | |
| 7834 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7835 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7836 | return boot_image_string_patches_.GetOrCreate( |
| 7837 | StringReference(&dex_file, string_index), |
| 7838 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7839 | } |
| 7840 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7841 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7842 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7843 | return boot_image_type_patches_.GetOrCreate( |
| 7844 | TypeReference(&dex_file, type_index), |
| 7845 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7846 | } |
| 7847 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7848 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7849 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7850 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7851 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7852 | } |
| 7853 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7854 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7855 | dex::StringIndex string_index, |
| 7856 | Handle<mirror::String> handle) { |
| 7857 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7858 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7859 | return jit_string_patches_.GetOrCreate( |
| 7860 | StringReference(&dex_file, string_index), |
| 7861 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7862 | } |
| 7863 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7864 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7865 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7866 | Handle<mirror::Class> handle) { |
| 7867 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 7868 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7869 | return jit_class_patches_.GetOrCreate( |
| 7870 | TypeReference(&dex_file, type_index), |
| 7871 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7872 | } |
| 7873 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7874 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7875 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7876 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7877 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7878 | for (const PcRelativePatchInfo& info : infos) { |
| 7879 | const DexFile& dex_file = info.target_dex_file; |
| 7880 | size_t offset_or_index = info.offset_or_index; |
| 7881 | DCHECK(info.add_pc_label.IsBound()); |
| 7882 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7883 | // Add MOVW patch. |
| 7884 | DCHECK(info.movw_label.IsBound()); |
| 7885 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7886 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7887 | // Add MOVT patch. |
| 7888 | DCHECK(info.movt_label.IsBound()); |
| 7889 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7890 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7891 | } |
| 7892 | } |
| 7893 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7894 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7895 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7896 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7897 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7898 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7899 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7900 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7901 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7902 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7903 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7904 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7905 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7906 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7907 | for (const auto& entry : boot_image_string_patches_) { |
| 7908 | const StringReference& target_string = entry.first; |
| 7909 | Literal* literal = entry.second; |
| 7910 | DCHECK(literal->GetLabel()->IsBound()); |
| 7911 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7912 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7913 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7914 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7915 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7916 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7917 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7918 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7919 | linker_patches); |
| 7920 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7921 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7922 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7923 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7924 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7925 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7926 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7927 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7928 | for (const auto& entry : boot_image_type_patches_) { |
| 7929 | const TypeReference& target_type = entry.first; |
| 7930 | Literal* literal = entry.second; |
| 7931 | DCHECK(literal->GetLabel()->IsBound()); |
| 7932 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7933 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7934 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7935 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7936 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7937 | for (const auto& entry : boot_image_address_patches_) { |
| 7938 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7939 | Literal* literal = entry.second; |
| 7940 | DCHECK(literal->GetLabel()->IsBound()); |
| 7941 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7942 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7943 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7944 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7945 | } |
| 7946 | |
| 7947 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7948 | return map->GetOrCreate( |
| 7949 | value, |
| 7950 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7951 | } |
| 7952 | |
| 7953 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7954 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7955 | return map->GetOrCreate( |
| 7956 | target_method, |
| 7957 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7958 | } |
| 7959 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7960 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7961 | LocationSummary* locations = |
| 7962 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7963 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7964 | Location::RequiresRegister()); |
| 7965 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7966 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7967 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7968 | } |
| 7969 | |
| 7970 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7971 | LocationSummary* locations = instr->GetLocations(); |
| 7972 | Register res = locations->Out().AsRegister<Register>(); |
| 7973 | Register accumulator = |
| 7974 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7975 | Register mul_left = |
| 7976 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7977 | Register mul_right = |
| 7978 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7979 | |
| 7980 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7981 | __ mla(res, mul_left, mul_right, accumulator); |
| 7982 | } else { |
| 7983 | __ mls(res, mul_left, mul_right, accumulator); |
| 7984 | } |
| 7985 | } |
| 7986 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7987 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7988 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7989 | LOG(FATAL) << "Unreachable"; |
| 7990 | } |
| 7991 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7992 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7993 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7994 | LOG(FATAL) << "Unreachable"; |
| 7995 | } |
| 7996 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7997 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7998 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7999 | LocationSummary* locations = |
| 8000 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8001 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8002 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8003 | codegen_->GetAssembler()->IsThumb()) { |
| 8004 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8005 | if (switch_instr->GetStartValue() != 0) { |
| 8006 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8007 | } |
| 8008 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8009 | } |
| 8010 | |
| 8011 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8012 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8013 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8014 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8015 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8016 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8017 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8018 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8019 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8020 | Register temp_reg = IP; |
| 8021 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8022 | // the immediate, because IP is used as the destination register. For the other |
| 8023 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8024 | // and they can be encoded in the instruction without making use of IP register. |
| 8025 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 8026 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8027 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8028 | // Jump to successors[0] if value == lower_bound. |
| 8029 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 8030 | int32_t last_index = 0; |
| 8031 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8032 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 8033 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8034 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 8035 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8036 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 8037 | } |
| 8038 | if (num_entries - last_index == 2) { |
| 8039 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 8040 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8041 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8042 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8043 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8044 | // And the default for any other value. |
| 8045 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8046 | __ b(codegen_->GetLabelOf(default_block)); |
| 8047 | } |
| 8048 | } else { |
| 8049 | // Create a table lookup. |
| 8050 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8051 | |
| 8052 | // Materialize a pointer to the switch table |
| 8053 | std::vector<Label*> labels(num_entries); |
| 8054 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8055 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8056 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8057 | } |
| 8058 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 8059 | |
| 8060 | // Remove the bias. |
| 8061 | Register key_reg; |
| 8062 | if (lower_bound != 0) { |
| 8063 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 8064 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 8065 | } else { |
| 8066 | key_reg = value_reg; |
| 8067 | } |
| 8068 | |
| 8069 | // Check whether the value is in the table, jump to default block if not. |
| 8070 | __ CmpConstant(key_reg, num_entries - 1); |
| 8071 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 8072 | |
| 8073 | // Load the displacement from the table. |
| 8074 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 8075 | |
| 8076 | // Dispatch is a direct add to the PC (for Thumb2). |
| 8077 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8078 | } |
| 8079 | } |
| 8080 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8081 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8082 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8083 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8084 | } |
| 8085 | |
| 8086 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8087 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8088 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 8089 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8090 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8091 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8092 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8093 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8094 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8095 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 8096 | } |
| 8097 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8098 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8099 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8100 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8101 | return; |
| 8102 | } |
| 8103 | |
| 8104 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8105 | |
| 8106 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 8107 | if (return_loc.Equals(trg)) { |
| 8108 | return; |
| 8109 | } |
| 8110 | |
| 8111 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8112 | // with the last branch. |
| 8113 | if (type == Primitive::kPrimLong) { |
| 8114 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8115 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 8116 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 8117 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8118 | } else if (type == Primitive::kPrimDouble) { |
| 8119 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8120 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 8121 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 8122 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8123 | } else { |
| 8124 | // Let the parallel move resolver take care of all of this. |
| 8125 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8126 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8127 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8128 | } |
| 8129 | } |
| 8130 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8131 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8132 | LocationSummary* locations = |
| 8133 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8134 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8135 | locations->SetOut(Location::RequiresRegister()); |
| 8136 | } |
| 8137 | |
| 8138 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8139 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8140 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8141 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8142 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8143 | __ LoadFromOffset(kLoadWord, |
| 8144 | locations->Out().AsRegister<Register>(), |
| 8145 | locations->InAt(0).AsRegister<Register>(), |
| 8146 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8147 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8148 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 8149 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8150 | __ LoadFromOffset(kLoadWord, |
| 8151 | locations->Out().AsRegister<Register>(), |
| 8152 | locations->InAt(0).AsRegister<Register>(), |
| 8153 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8154 | __ LoadFromOffset(kLoadWord, |
| 8155 | locations->Out().AsRegister<Register>(), |
| 8156 | locations->Out().AsRegister<Register>(), |
| 8157 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8158 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8159 | } |
| 8160 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8161 | static void PatchJitRootUse(uint8_t* code, |
| 8162 | const uint8_t* roots_data, |
| 8163 | Literal* literal, |
| 8164 | uint64_t index_in_table) { |
| 8165 | DCHECK(literal->GetLabel()->IsBound()); |
| 8166 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8167 | uintptr_t address = |
| 8168 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8169 | uint8_t* data = code + literal_offset; |
| 8170 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8171 | } |
| 8172 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8173 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8174 | for (const auto& entry : jit_string_patches_) { |
| 8175 | const auto& it = jit_string_roots_.find(entry.first); |
| 8176 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8177 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8178 | } |
| 8179 | for (const auto& entry : jit_class_patches_) { |
| 8180 | const auto& it = jit_class_roots_.find(entry.first); |
| 8181 | DCHECK(it != jit_class_roots_.end()); |
| 8182 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8183 | } |
| 8184 | } |
| 8185 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8186 | #undef __ |
| 8187 | #undef QUICK_ENTRY_POINT |
| 8188 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8189 | } // namespace arm |
| 8190 | } // namespace art |