Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 66 | static constexpr int kRegListThreshold = 4; |
| 67 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 68 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 69 | // for each live D registers they treat two corresponding S registers as live ones. |
| 70 | // |
| 71 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 72 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 73 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 74 | // - decreasing code size |
| 75 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 76 | // restored and then used in regular non SlowPath code as D register. |
| 77 | // |
| 78 | // For the following example (v means the S register is live): |
| 79 | // D names: | D0 | D1 | D2 | D4 | ... |
| 80 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 81 | // Live? | | v | v | v | v | v | v | | ... |
| 82 | // |
| 83 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 84 | // as D registers. |
| 85 | static size_t SaveContiguousSRegisterList(size_t first, |
| 86 | size_t last, |
| 87 | CodeGenerator* codegen, |
| 88 | size_t stack_offset) { |
| 89 | DCHECK_LE(first, last); |
| 90 | if ((first == last) && (first == 0)) { |
| 91 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 92 | return stack_offset; |
| 93 | } |
| 94 | if (first % 2 == 1) { |
| 95 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 96 | } |
| 97 | |
| 98 | bool save_last = false; |
| 99 | if (last % 2 == 0) { |
| 100 | save_last = true; |
| 101 | --last; |
| 102 | } |
| 103 | |
| 104 | if (first < last) { |
| 105 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 106 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 107 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 108 | |
| 109 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 110 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 111 | } else if (number_of_d_regs > 1) { |
| 112 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 113 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 114 | } |
| 115 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 116 | } |
| 117 | |
| 118 | if (save_last) { |
| 119 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 120 | } |
| 121 | |
| 122 | return stack_offset; |
| 123 | } |
| 124 | |
| 125 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 126 | size_t last, |
| 127 | CodeGenerator* codegen, |
| 128 | size_t stack_offset) { |
| 129 | DCHECK_LE(first, last); |
| 130 | if ((first == last) && (first == 0)) { |
| 131 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 132 | return stack_offset; |
| 133 | } |
| 134 | if (first % 2 == 1) { |
| 135 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 136 | } |
| 137 | |
| 138 | bool restore_last = false; |
| 139 | if (last % 2 == 0) { |
| 140 | restore_last = true; |
| 141 | --last; |
| 142 | } |
| 143 | |
| 144 | if (first < last) { |
| 145 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 146 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 147 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 148 | if (number_of_d_regs == 1) { |
| 149 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 150 | } else if (number_of_d_regs > 1) { |
| 151 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 152 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 153 | } |
| 154 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 155 | } |
| 156 | |
| 157 | if (restore_last) { |
| 158 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 159 | } |
| 160 | |
| 161 | return stack_offset; |
| 162 | } |
| 163 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 164 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 165 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 166 | size_t orig_offset = stack_offset; |
| 167 | |
| 168 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 169 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 170 | // If the register holds an object, update the stack mask. |
| 171 | if (locations->RegisterContainsObject(i)) { |
| 172 | locations->SetStackBit(stack_offset / kVRegSize); |
| 173 | } |
| 174 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 175 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 176 | saved_core_stack_offsets_[i] = stack_offset; |
| 177 | stack_offset += kArmWordSize; |
| 178 | } |
| 179 | |
| 180 | int reg_num = POPCOUNT(core_spills); |
| 181 | if (reg_num != 0) { |
| 182 | if (reg_num > kRegListThreshold) { |
| 183 | __ StoreList(RegList(core_spills), orig_offset); |
| 184 | } else { |
| 185 | stack_offset = orig_offset; |
| 186 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 187 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 192 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 193 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 197 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 199 | |
| 200 | stack_offset = orig_offset; |
| 201 | while (fp_spills != 0u) { |
| 202 | uint32_t begin = CTZ(fp_spills); |
| 203 | uint32_t tmp = fp_spills + (1u << begin); |
| 204 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 205 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 206 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 207 | } |
| 208 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 212 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 213 | size_t orig_offset = stack_offset; |
| 214 | |
| 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 218 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 219 | stack_offset += kArmWordSize; |
| 220 | } |
| 221 | |
| 222 | int reg_num = POPCOUNT(core_spills); |
| 223 | if (reg_num != 0) { |
| 224 | if (reg_num > kRegListThreshold) { |
| 225 | __ LoadList(RegList(core_spills), orig_offset); |
| 226 | } else { |
| 227 | stack_offset = orig_offset; |
| 228 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 229 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 234 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 235 | while (fp_spills != 0u) { |
| 236 | uint32_t begin = CTZ(fp_spills); |
| 237 | uint32_t tmp = fp_spills + (1u << begin); |
| 238 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 239 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 240 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 241 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 246 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 251 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 252 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 253 | // Live registers will be restored in the catch block if caught. |
| 254 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 255 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 257 | instruction_, |
| 258 | instruction_->GetDexPc(), |
| 259 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 260 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 263 | bool IsFatal() const OVERRIDE { return true; } |
| 264 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 265 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 266 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 267 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 269 | }; |
| 270 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 271 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 272 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 273 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 276 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 277 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 278 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 282 | bool IsFatal() const OVERRIDE { return true; } |
| 283 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 285 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 286 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 288 | }; |
| 289 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 290 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 291 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 293 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 296 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 297 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 298 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 300 | if (successor_ == nullptr) { |
| 301 | __ b(GetReturnLabel()); |
| 302 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 303 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 304 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 307 | Label* GetReturnLabel() { |
| 308 | DCHECK(successor_ == nullptr); |
| 309 | return &return_label_; |
| 310 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 311 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 312 | HBasicBlock* GetSuccessor() const { |
| 313 | return successor_; |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 317 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 318 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 319 | // If not null, the block to branch to after the suspend check. |
| 320 | HBasicBlock* const successor_; |
| 321 | |
| 322 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 323 | Label return_label_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 329 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 330 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | LocationSummary* locations = instruction_->GetLocations(); |
| 336 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 337 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 338 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 339 | // Live registers will be restored in the catch block if caught. |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 341 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 342 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 343 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 344 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 346 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 351 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 352 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 353 | ? kQuickThrowStringBounds |
| 354 | : kQuickThrowArrayBounds; |
| 355 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return true; } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 364 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 366 | }; |
| 367 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 368 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 369 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 370 | LoadClassSlowPathARM(HLoadClass* cls, |
| 371 | HInstruction* at, |
| 372 | uint32_t dex_pc, |
| 373 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 374 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 375 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 376 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 377 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 378 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 379 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 380 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 381 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 382 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 383 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 385 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 386 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 387 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 388 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 389 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 390 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 391 | if (do_clinit_) { |
| 392 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 393 | } else { |
| 394 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 395 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 396 | |
| 397 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 398 | Location out = locations->Out(); |
| 399 | if (out.IsValid()) { |
| 400 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 401 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 402 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 403 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 404 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 405 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 406 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 407 | DCHECK(out.IsValid()); |
| 408 | // TODO: Change art_quick_initialize_type/art_quick_initialize_static_storage to |
| 409 | // kSaveEverything and use a temporary for the .bss entry address in the fast path, |
| 410 | // so that we can avoid another calculation here. |
| 411 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 412 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 413 | __ BindTrackedLabel(&labels->movw_label); |
| 414 | __ movw(IP, /* placeholder */ 0u); |
| 415 | __ BindTrackedLabel(&labels->movt_label); |
| 416 | __ movt(IP, /* placeholder */ 0u); |
| 417 | __ BindTrackedLabel(&labels->add_pc_label); |
| 418 | __ add(IP, IP, ShifterOperand(PC)); |
| 419 | __ str(locations->Out().AsRegister<Register>(), Address(IP)); |
| 420 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 421 | __ b(GetExitLabel()); |
| 422 | } |
| 423 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 424 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 425 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 426 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 427 | // The class this slow path will load. |
| 428 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 429 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 430 | // The dex PC of `at_`. |
| 431 | const uint32_t dex_pc_; |
| 432 | |
| 433 | // Whether to initialize the class. |
| 434 | const bool do_clinit_; |
| 435 | |
| 436 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 437 | }; |
| 438 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 439 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 440 | public: |
| 441 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 442 | |
| 443 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 444 | LocationSummary* locations = instruction_->GetLocations(); |
| 445 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 446 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 447 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 448 | Register out = locations->Out().AsRegister<Register>(); |
| 449 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 450 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 451 | |
| 452 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 453 | __ Bind(GetEntryLabel()); |
| 454 | SaveLiveRegisters(codegen, locations); |
| 455 | |
| 456 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 457 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 458 | // the kSaveEverything call (or use `out` for the address after non-kSaveEverything call). |
| 459 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 460 | Register entry_address = temp_is_r0 ? out : temp; |
| 461 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 462 | if (call_saves_everything_except_r0 && temp_is_r0) { |
| 463 | __ mov(entry_address, ShifterOperand(temp)); |
| 464 | } |
| 465 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 466 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 467 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 468 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 469 | |
| 470 | // Store the resolved String to the .bss entry. |
| 471 | if (call_saves_everything_except_r0) { |
| 472 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 473 | __ str(R0, Address(entry_address)); |
| 474 | } else { |
| 475 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 476 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 477 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 478 | __ BindTrackedLabel(&labels->movw_label); |
| 479 | __ movw(entry_address, /* placeholder */ 0u); |
| 480 | __ BindTrackedLabel(&labels->movt_label); |
| 481 | __ movt(entry_address, /* placeholder */ 0u); |
| 482 | __ BindTrackedLabel(&labels->add_pc_label); |
| 483 | __ add(entry_address, entry_address, ShifterOperand(PC)); |
| 484 | __ str(R0, Address(entry_address)); |
| 485 | } |
| 486 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 487 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 488 | RestoreLiveRegisters(codegen, locations); |
| 489 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 490 | __ b(GetExitLabel()); |
| 491 | } |
| 492 | |
| 493 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 494 | |
| 495 | private: |
| 496 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 497 | }; |
| 498 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 499 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 500 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 501 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 502 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 503 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 504 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 505 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 506 | DCHECK(instruction_->IsCheckCast() |
| 507 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 508 | |
| 509 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 510 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 511 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 512 | if (!is_fatal_) { |
| 513 | SaveLiveRegisters(codegen, locations); |
| 514 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 515 | |
| 516 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 517 | // move resolver. |
| 518 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 519 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 520 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 521 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 522 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 523 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 524 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 525 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 526 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 527 | instruction_, |
| 528 | instruction_->GetDexPc(), |
| 529 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 530 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 531 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 532 | } else { |
| 533 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 534 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 535 | instruction_, |
| 536 | instruction_->GetDexPc(), |
| 537 | this); |
| 538 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 539 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 540 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 541 | if (!is_fatal_) { |
| 542 | RestoreLiveRegisters(codegen, locations); |
| 543 | __ b(GetExitLabel()); |
| 544 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 547 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 548 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 549 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 550 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 551 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 552 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 553 | |
| 554 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 555 | }; |
| 556 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 557 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 558 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 559 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 560 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 561 | |
| 562 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 563 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 564 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 565 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 566 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 569 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 570 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 571 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 572 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 573 | }; |
| 574 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 575 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 576 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 577 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 578 | |
| 579 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 580 | LocationSummary* locations = instruction_->GetLocations(); |
| 581 | __ Bind(GetEntryLabel()); |
| 582 | SaveLiveRegisters(codegen, locations); |
| 583 | |
| 584 | InvokeRuntimeCallingConvention calling_convention; |
| 585 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 586 | parallel_move.AddMove( |
| 587 | locations->InAt(0), |
| 588 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 589 | Primitive::kPrimNot, |
| 590 | nullptr); |
| 591 | parallel_move.AddMove( |
| 592 | locations->InAt(1), |
| 593 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 594 | Primitive::kPrimInt, |
| 595 | nullptr); |
| 596 | parallel_move.AddMove( |
| 597 | locations->InAt(2), |
| 598 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 599 | Primitive::kPrimNot, |
| 600 | nullptr); |
| 601 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 602 | |
| 603 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 604 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 605 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 606 | RestoreLiveRegisters(codegen, locations); |
| 607 | __ b(GetExitLabel()); |
| 608 | } |
| 609 | |
| 610 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 611 | |
| 612 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 613 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 614 | }; |
| 615 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 616 | // Slow path marking an object reference `ref` during a read |
| 617 | // barrier. The field `obj.field` in the object `obj` holding this |
| 618 | // reference does not get updated by this slow path after marking (see |
| 619 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
| 620 | // |
| 621 | // This means that after the execution of this slow path, `ref` will |
| 622 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 623 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 624 | // probably still be a from-space reference (unless it gets updated by |
| 625 | // another thread, or if another thread installed another object |
| 626 | // reference (different from `ref`) in `obj.field`). |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 627 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 628 | public: |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 629 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 630 | Location ref, |
| 631 | Location entrypoint = Location::NoLocation()) |
| 632 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 633 | DCHECK(kEmitCompilerReadBarrier); |
| 634 | } |
| 635 | |
| 636 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 637 | |
| 638 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 639 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 640 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 641 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 642 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 643 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 644 | instruction_->IsStaticFieldGet() || |
| 645 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 646 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 647 | instruction_->IsLoadClass() || |
| 648 | instruction_->IsLoadString() || |
| 649 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 650 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 651 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 652 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 653 | << "Unexpected instruction in read barrier marking slow path: " |
| 654 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 655 | // The read barrier instrumentation of object ArrayGet |
| 656 | // instructions does not support the HIntermediateAddress |
| 657 | // instruction. |
| 658 | DCHECK(!(instruction_->IsArrayGet() && |
| 659 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 660 | |
| 661 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 662 | // No need to save live registers; it's taken care of by the |
| 663 | // entrypoint. Also, there is no need to update the stack mask, |
| 664 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 665 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 666 | DCHECK_NE(ref_reg, SP); |
| 667 | DCHECK_NE(ref_reg, LR); |
| 668 | DCHECK_NE(ref_reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 669 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 670 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 671 | DCHECK_NE(ref_reg, IP); |
| 672 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 673 | // "Compact" slow path, saving two moves. |
| 674 | // |
| 675 | // Instead of using the standard runtime calling convention (input |
| 676 | // and output in R0): |
| 677 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 678 | // R0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 679 | // R0 <- ReadBarrierMark(R0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 680 | // ref <- R0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 681 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 682 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 683 | // of a dedicated entrypoint: |
| 684 | // |
| 685 | // rX <- ReadBarrierMarkRegX(rX) |
| 686 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 687 | if (entrypoint_.IsValid()) { |
| 688 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 689 | __ blx(entrypoint_.AsRegister<Register>()); |
| 690 | } else { |
| 691 | int32_t entry_point_offset = |
| 692 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 693 | // This runtime call does not require a stack map. |
| 694 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 695 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 696 | __ b(GetExitLabel()); |
| 697 | } |
| 698 | |
| 699 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 700 | // The location (register) of the marked object reference. |
| 701 | const Location ref_; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 702 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 703 | // The location of the entrypoint if already loaded. |
| 704 | const Location entrypoint_; |
| 705 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 706 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 707 | }; |
| 708 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 709 | // Slow path marking an object reference `ref` during a read barrier, |
| 710 | // and if needed, atomically updating the field `obj.field` in the |
| 711 | // object `obj` holding this reference after marking (contrary to |
| 712 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 713 | // `obj.field`). |
| 714 | // |
| 715 | // This means that after the execution of this slow path, both `ref` |
| 716 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 717 | // hold the same to-space reference (unless another thread installed |
| 718 | // another object reference (different from `ref`) in `obj.field`). |
| 719 | class ReadBarrierMarkAndUpdateFieldSlowPathARM : public SlowPathCodeARM { |
| 720 | public: |
| 721 | ReadBarrierMarkAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 722 | Location ref, |
| 723 | Register obj, |
| 724 | Location field_offset, |
| 725 | Register temp1, |
| 726 | Register temp2) |
| 727 | : SlowPathCodeARM(instruction), |
| 728 | ref_(ref), |
| 729 | obj_(obj), |
| 730 | field_offset_(field_offset), |
| 731 | temp1_(temp1), |
| 732 | temp2_(temp2) { |
| 733 | DCHECK(kEmitCompilerReadBarrier); |
| 734 | } |
| 735 | |
| 736 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathARM"; } |
| 737 | |
| 738 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 739 | LocationSummary* locations = instruction_->GetLocations(); |
| 740 | Register ref_reg = ref_.AsRegister<Register>(); |
| 741 | DCHECK(locations->CanCall()); |
| 742 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 743 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 744 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 745 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 746 | << instruction_->DebugName(); |
| 747 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 748 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 749 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 750 | |
| 751 | __ Bind(GetEntryLabel()); |
| 752 | |
| 753 | // Save the old reference. |
| 754 | // Note that we cannot use IP to save the old reference, as IP is |
| 755 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 756 | // need the old reference after the call to that entry point. |
| 757 | DCHECK_NE(temp1_, IP); |
| 758 | __ Mov(temp1_, ref_reg); |
| 759 | |
| 760 | // No need to save live registers; it's taken care of by the |
| 761 | // entrypoint. Also, there is no need to update the stack mask, |
| 762 | // as this runtime call will not trigger a garbage collection. |
| 763 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 764 | DCHECK_NE(ref_reg, SP); |
| 765 | DCHECK_NE(ref_reg, LR); |
| 766 | DCHECK_NE(ref_reg, PC); |
| 767 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 768 | // as a temporary, it cannot be the entry point's input/output. |
| 769 | DCHECK_NE(ref_reg, IP); |
| 770 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 771 | // "Compact" slow path, saving two moves. |
| 772 | // |
| 773 | // Instead of using the standard runtime calling convention (input |
| 774 | // and output in R0): |
| 775 | // |
| 776 | // R0 <- ref |
| 777 | // R0 <- ReadBarrierMark(R0) |
| 778 | // ref <- R0 |
| 779 | // |
| 780 | // we just use rX (the register containing `ref`) as input and output |
| 781 | // of a dedicated entrypoint: |
| 782 | // |
| 783 | // rX <- ReadBarrierMarkRegX(rX) |
| 784 | // |
| 785 | int32_t entry_point_offset = |
| 786 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 787 | // This runtime call does not require a stack map. |
| 788 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 789 | |
| 790 | // If the new reference is different from the old reference, |
| 791 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 792 | // |
| 793 | // Note that this field could also hold a different object, if |
| 794 | // another thread had concurrently changed it. In that case, the |
| 795 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 796 | // (CAS) operation below would abort the CAS, leaving the field |
| 797 | // as-is. |
| 798 | Label done; |
| 799 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
| 800 | __ b(&done, EQ); |
| 801 | |
| 802 | // Update the the holder's field atomically. This may fail if |
| 803 | // mutator updates before us, but it's OK. This is achieved |
| 804 | // using a strong compare-and-set (CAS) operation with relaxed |
| 805 | // memory synchronization ordering, where the expected value is |
| 806 | // the old reference and the desired value is the new reference. |
| 807 | |
| 808 | // Convenience aliases. |
| 809 | Register base = obj_; |
| 810 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 811 | // offset ("long offset"), of which only the low part contains |
| 812 | // data. |
| 813 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 814 | Register expected = temp1_; |
| 815 | Register value = ref_reg; |
| 816 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 817 | Register tmp = temp2_; // Value in memory. |
| 818 | |
| 819 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 820 | |
| 821 | if (kPoisonHeapReferences) { |
| 822 | __ PoisonHeapReference(expected); |
| 823 | if (value == expected) { |
| 824 | // Do not poison `value`, as it is the same register as |
| 825 | // `expected`, which has just been poisoned. |
| 826 | } else { |
| 827 | __ PoisonHeapReference(value); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | // do { |
| 832 | // tmp = [r_ptr] - expected; |
| 833 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 834 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 835 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 836 | __ Bind(&loop_head); |
| 837 | |
| 838 | __ ldrex(tmp, tmp_ptr); |
| 839 | |
| 840 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 841 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 842 | __ it(NE); |
| 843 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 844 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 845 | __ b(&exit_loop, NE); |
| 846 | |
| 847 | __ strex(tmp, value, tmp_ptr); |
| 848 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 849 | __ b(&loop_head, EQ); |
| 850 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 851 | __ Bind(&exit_loop); |
| 852 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 853 | if (kPoisonHeapReferences) { |
| 854 | __ UnpoisonHeapReference(expected); |
| 855 | if (value == expected) { |
| 856 | // Do not unpoison `value`, as it is the same register as |
| 857 | // `expected`, which has just been unpoisoned. |
| 858 | } else { |
| 859 | __ UnpoisonHeapReference(value); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | __ Bind(&done); |
| 864 | __ b(GetExitLabel()); |
| 865 | } |
| 866 | |
| 867 | private: |
| 868 | // The location (register) of the marked object reference. |
| 869 | const Location ref_; |
| 870 | // The register containing the object holding the marked object reference field. |
| 871 | const Register obj_; |
| 872 | // The location of the offset of the marked reference field within `obj_`. |
| 873 | Location field_offset_; |
| 874 | |
| 875 | const Register temp1_; |
| 876 | const Register temp2_; |
| 877 | |
| 878 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM); |
| 879 | }; |
| 880 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 881 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 882 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 883 | public: |
| 884 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 885 | Location out, |
| 886 | Location ref, |
| 887 | Location obj, |
| 888 | uint32_t offset, |
| 889 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 890 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 891 | out_(out), |
| 892 | ref_(ref), |
| 893 | obj_(obj), |
| 894 | offset_(offset), |
| 895 | index_(index) { |
| 896 | DCHECK(kEmitCompilerReadBarrier); |
| 897 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 898 | // has been overwritten by (or after) the heap object reference load |
| 899 | // to be instrumented, e.g.: |
| 900 | // |
| 901 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 902 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 903 | // |
| 904 | // In that case, we have lost the information about the original |
| 905 | // object, and the emitted read barrier cannot work properly. |
| 906 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 907 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 908 | } |
| 909 | |
| 910 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 911 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 912 | LocationSummary* locations = instruction_->GetLocations(); |
| 913 | Register reg_out = out_.AsRegister<Register>(); |
| 914 | DCHECK(locations->CanCall()); |
| 915 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 916 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 917 | instruction_->IsStaticFieldGet() || |
| 918 | instruction_->IsArrayGet() || |
| 919 | instruction_->IsInstanceOf() || |
| 920 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 921 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 922 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 923 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 924 | // The read barrier instrumentation of object ArrayGet |
| 925 | // instructions does not support the HIntermediateAddress |
| 926 | // instruction. |
| 927 | DCHECK(!(instruction_->IsArrayGet() && |
| 928 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 929 | |
| 930 | __ Bind(GetEntryLabel()); |
| 931 | SaveLiveRegisters(codegen, locations); |
| 932 | |
| 933 | // We may have to change the index's value, but as `index_` is a |
| 934 | // constant member (like other "inputs" of this slow path), |
| 935 | // introduce a copy of it, `index`. |
| 936 | Location index = index_; |
| 937 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 938 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 939 | if (instruction_->IsArrayGet()) { |
| 940 | // Compute the actual memory offset and store it in `index`. |
| 941 | Register index_reg = index_.AsRegister<Register>(); |
| 942 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 943 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 944 | // We are about to change the value of `index_reg` (see the |
| 945 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 946 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 947 | // not been saved by the previous call to |
| 948 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 949 | // callee-save register -- |
| 950 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 951 | // callee-save registers, as it has been designed with the |
| 952 | // assumption that callee-save registers are supposed to be |
| 953 | // handled by the called function. So, as a callee-save |
| 954 | // register, `index_reg` _would_ eventually be saved onto |
| 955 | // the stack, but it would be too late: we would have |
| 956 | // changed its value earlier. Therefore, we manually save |
| 957 | // it here into another freely available register, |
| 958 | // `free_reg`, chosen of course among the caller-save |
| 959 | // registers (as a callee-save `free_reg` register would |
| 960 | // exhibit the same problem). |
| 961 | // |
| 962 | // Note we could have requested a temporary register from |
| 963 | // the register allocator instead; but we prefer not to, as |
| 964 | // this is a slow path, and we know we can find a |
| 965 | // caller-save register that is available. |
| 966 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 967 | __ Mov(free_reg, index_reg); |
| 968 | index_reg = free_reg; |
| 969 | index = Location::RegisterLocation(index_reg); |
| 970 | } else { |
| 971 | // The initial register stored in `index_` has already been |
| 972 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 973 | // (as it is not a callee-save register), so we can freely |
| 974 | // use it. |
| 975 | } |
| 976 | // Shifting the index value contained in `index_reg` by the scale |
| 977 | // factor (2) cannot overflow in practice, as the runtime is |
| 978 | // unable to allocate object arrays with a size larger than |
| 979 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 980 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 981 | static_assert( |
| 982 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 983 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 984 | __ AddConstant(index_reg, index_reg, offset_); |
| 985 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 986 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 987 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 988 | // (as in the case of ArrayGet), as it is actually an offset |
| 989 | // to an object field within an object. |
| 990 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 991 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 992 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 993 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 994 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 995 | DCHECK_EQ(offset_, 0U); |
| 996 | DCHECK(index_.IsRegisterPair()); |
| 997 | // UnsafeGet's offset location is a register pair, the low |
| 998 | // part contains the correct offset. |
| 999 | index = index_.ToLow(); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | // We're moving two or three locations to locations that could |
| 1004 | // overlap, so we need a parallel move resolver. |
| 1005 | InvokeRuntimeCallingConvention calling_convention; |
| 1006 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1007 | parallel_move.AddMove(ref_, |
| 1008 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1009 | Primitive::kPrimNot, |
| 1010 | nullptr); |
| 1011 | parallel_move.AddMove(obj_, |
| 1012 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1013 | Primitive::kPrimNot, |
| 1014 | nullptr); |
| 1015 | if (index.IsValid()) { |
| 1016 | parallel_move.AddMove(index, |
| 1017 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1018 | Primitive::kPrimInt, |
| 1019 | nullptr); |
| 1020 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1021 | } else { |
| 1022 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1023 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1024 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1025 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1026 | CheckEntrypointTypes< |
| 1027 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1028 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1029 | |
| 1030 | RestoreLiveRegisters(codegen, locations); |
| 1031 | __ b(GetExitLabel()); |
| 1032 | } |
| 1033 | |
| 1034 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1035 | |
| 1036 | private: |
| 1037 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1038 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1039 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1040 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1041 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1042 | return static_cast<Register>(i); |
| 1043 | } |
| 1044 | } |
| 1045 | // We shall never fail to find a free caller-save register, as |
| 1046 | // there are more than two core caller-save registers on ARM |
| 1047 | // (meaning it is possible to find one which is different from |
| 1048 | // `ref` and `obj`). |
| 1049 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1050 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1051 | UNREACHABLE(); |
| 1052 | } |
| 1053 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1054 | const Location out_; |
| 1055 | const Location ref_; |
| 1056 | const Location obj_; |
| 1057 | const uint32_t offset_; |
| 1058 | // An additional location containing an index to an array. |
| 1059 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1060 | // UnsafeGetObjectVolatile intrinsics. |
| 1061 | const Location index_; |
| 1062 | |
| 1063 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1064 | }; |
| 1065 | |
| 1066 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1067 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1068 | public: |
| 1069 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1070 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1071 | DCHECK(kEmitCompilerReadBarrier); |
| 1072 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1073 | |
| 1074 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1075 | LocationSummary* locations = instruction_->GetLocations(); |
| 1076 | Register reg_out = out_.AsRegister<Register>(); |
| 1077 | DCHECK(locations->CanCall()); |
| 1078 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1079 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1080 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1081 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1082 | |
| 1083 | __ Bind(GetEntryLabel()); |
| 1084 | SaveLiveRegisters(codegen, locations); |
| 1085 | |
| 1086 | InvokeRuntimeCallingConvention calling_convention; |
| 1087 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1088 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1089 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1090 | instruction_, |
| 1091 | instruction_->GetDexPc(), |
| 1092 | this); |
| 1093 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1094 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1095 | |
| 1096 | RestoreLiveRegisters(codegen, locations); |
| 1097 | __ b(GetExitLabel()); |
| 1098 | } |
| 1099 | |
| 1100 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1101 | |
| 1102 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1103 | const Location out_; |
| 1104 | const Location root_; |
| 1105 | |
| 1106 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1107 | }; |
| 1108 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1109 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1110 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1111 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1112 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1113 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1114 | switch (cond) { |
| 1115 | case kCondEQ: return EQ; |
| 1116 | case kCondNE: return NE; |
| 1117 | case kCondLT: return LT; |
| 1118 | case kCondLE: return LE; |
| 1119 | case kCondGT: return GT; |
| 1120 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1121 | case kCondB: return LO; |
| 1122 | case kCondBE: return LS; |
| 1123 | case kCondA: return HI; |
| 1124 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1125 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1126 | LOG(FATAL) << "Unreachable"; |
| 1127 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1130 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1131 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1132 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1133 | case kCondEQ: return EQ; |
| 1134 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1135 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1136 | case kCondLT: return LO; |
| 1137 | case kCondLE: return LS; |
| 1138 | case kCondGT: return HI; |
| 1139 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1140 | // Unsigned remain unchanged. |
| 1141 | case kCondB: return LO; |
| 1142 | case kCondBE: return LS; |
| 1143 | case kCondA: return HI; |
| 1144 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1145 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1146 | LOG(FATAL) << "Unreachable"; |
| 1147 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1150 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1151 | // The ARM condition codes can express all the necessary branches, see the |
| 1152 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1153 | // There is no dex instruction or HIR that would need the missing conditions |
| 1154 | // "equal or unordered" or "not equal". |
| 1155 | switch (cond) { |
| 1156 | case kCondEQ: return EQ; |
| 1157 | case kCondNE: return NE /* unordered */; |
| 1158 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1159 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1160 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1161 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1162 | default: |
| 1163 | LOG(FATAL) << "UNREACHABLE"; |
| 1164 | UNREACHABLE(); |
| 1165 | } |
| 1166 | } |
| 1167 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1168 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1169 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1173 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1176 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1177 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1178 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1181 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1182 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1183 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1184 | } |
| 1185 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1186 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1187 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1188 | return kArmWordSize; |
| 1189 | } |
| 1190 | |
| 1191 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1192 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1193 | return kArmWordSize; |
| 1194 | } |
| 1195 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1196 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1197 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1198 | const CompilerOptions& compiler_options, |
| 1199 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1200 | : CodeGenerator(graph, |
| 1201 | kNumberOfCoreRegisters, |
| 1202 | kNumberOfSRegisters, |
| 1203 | kNumberOfRegisterPairs, |
| 1204 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1205 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1206 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1207 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1208 | compiler_options, |
| 1209 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1210 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1211 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1212 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1213 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1214 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1215 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1216 | uint32_literals_(std::less<uint32_t>(), |
| 1217 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1218 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1219 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1220 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1221 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1222 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1223 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1224 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1225 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1226 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1227 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1228 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1229 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1230 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1231 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1232 | // Always save the LR register to mimic Quick. |
| 1233 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1234 | } |
| 1235 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1236 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1237 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1238 | __ FinalizeCode(); |
| 1239 | |
| 1240 | // Adjust native pc offsets in stack maps. |
| 1241 | 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] | 1242 | uint32_t old_position = |
| 1243 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1244 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1245 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1246 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1247 | // Adjust pc offsets for the disassembly information. |
| 1248 | if (disasm_info_ != nullptr) { |
| 1249 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1250 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1251 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1252 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1253 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1254 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1255 | } |
| 1256 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1257 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1258 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1259 | } |
| 1260 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1261 | |
| 1262 | CodeGenerator::Finalize(allocator); |
| 1263 | } |
| 1264 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1265 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1266 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1267 | blocked_core_registers_[SP] = true; |
| 1268 | blocked_core_registers_[LR] = true; |
| 1269 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1270 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1271 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1272 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1273 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1274 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1275 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1276 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1277 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1278 | // Stubs do not save callee-save floating point registers. If the graph |
| 1279 | // is debuggable, we need to deal with these registers differently. For |
| 1280 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1281 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1282 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1283 | } |
| 1284 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1287 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1288 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1289 | assembler_(codegen->GetAssembler()), |
| 1290 | codegen_(codegen) {} |
| 1291 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1292 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1293 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1294 | 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] | 1295 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1296 | // restore another arbitrary register. |
| 1297 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1298 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1299 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1300 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1301 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1302 | // but in the range. |
| 1303 | if (fpu_spill_mask_ != 0) { |
| 1304 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1305 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1306 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1307 | fpu_spill_mask_ |= (1 << i); |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1312 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1313 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1317 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1320 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1321 | bool skip_overflow_check = |
| 1322 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1323 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1324 | __ Bind(&frame_entry_label_); |
| 1325 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1326 | if (HasEmptyFrame()) { |
| 1327 | return; |
| 1328 | } |
| 1329 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1330 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1331 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1332 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1333 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1334 | } |
| 1335 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1336 | __ PushList(core_spill_mask_); |
| 1337 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1338 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1339 | if (fpu_spill_mask_ != 0) { |
| 1340 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1341 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1342 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1343 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1344 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1345 | |
| 1346 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1347 | // Initialize should_deoptimize flag to 0. |
| 1348 | __ mov(IP, ShifterOperand(0)); |
| 1349 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1350 | } |
| 1351 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1352 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1353 | __ AddConstant(SP, -adjust); |
| 1354 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1355 | |
| 1356 | // Save the current method if we need it. Note that we do not |
| 1357 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1358 | // in the SSA graph. |
| 1359 | if (RequiresCurrentMethod()) { |
| 1360 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1361 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1365 | if (HasEmptyFrame()) { |
| 1366 | __ bx(LR); |
| 1367 | return; |
| 1368 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1369 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1370 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1371 | __ AddConstant(SP, adjust); |
| 1372 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1373 | if (fpu_spill_mask_ != 0) { |
| 1374 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1375 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1376 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1377 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1378 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1379 | // Pop LR into PC to return. |
| 1380 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1381 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1382 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1383 | __ cfi().RestoreState(); |
| 1384 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1387 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1388 | Label* label = GetLabelOf(block); |
| 1389 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1392 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1393 | switch (type) { |
| 1394 | case Primitive::kPrimBoolean: |
| 1395 | case Primitive::kPrimByte: |
| 1396 | case Primitive::kPrimChar: |
| 1397 | case Primitive::kPrimShort: |
| 1398 | case Primitive::kPrimInt: |
| 1399 | case Primitive::kPrimNot: { |
| 1400 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1401 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1402 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1403 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1404 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1405 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1406 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1407 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1408 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1409 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1410 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1411 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1412 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1413 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1414 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1415 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1416 | // Skip R1, and use R2_R3 instead. |
| 1417 | gp_index_++; |
| 1418 | index++; |
| 1419 | } |
| 1420 | } |
| 1421 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1422 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1423 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1424 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1425 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1426 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1427 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1428 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | case Primitive::kPrimFloat: { |
| 1433 | uint32_t stack_index = stack_index_++; |
| 1434 | if (float_index_ % 2 == 0) { |
| 1435 | float_index_ = std::max(double_index_, float_index_); |
| 1436 | } |
| 1437 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1438 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1439 | } else { |
| 1440 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | case Primitive::kPrimDouble: { |
| 1445 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1446 | uint32_t stack_index = stack_index_; |
| 1447 | stack_index_ += 2; |
| 1448 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1449 | uint32_t index = double_index_; |
| 1450 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1451 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1452 | calling_convention.GetFpuRegisterAt(index), |
| 1453 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1454 | DCHECK(ExpectedPairLayout(result)); |
| 1455 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1456 | } else { |
| 1457 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1461 | case Primitive::kPrimVoid: |
| 1462 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1463 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1464 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1465 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1466 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1467 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1468 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1469 | switch (type) { |
| 1470 | case Primitive::kPrimBoolean: |
| 1471 | case Primitive::kPrimByte: |
| 1472 | case Primitive::kPrimChar: |
| 1473 | case Primitive::kPrimShort: |
| 1474 | case Primitive::kPrimInt: |
| 1475 | case Primitive::kPrimNot: { |
| 1476 | return Location::RegisterLocation(R0); |
| 1477 | } |
| 1478 | |
| 1479 | case Primitive::kPrimFloat: { |
| 1480 | return Location::FpuRegisterLocation(S0); |
| 1481 | } |
| 1482 | |
| 1483 | case Primitive::kPrimLong: { |
| 1484 | return Location::RegisterPairLocation(R0, R1); |
| 1485 | } |
| 1486 | |
| 1487 | case Primitive::kPrimDouble: { |
| 1488 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1489 | } |
| 1490 | |
| 1491 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1492 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1493 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1494 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1495 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1498 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1499 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1500 | } |
| 1501 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1502 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1503 | if (source.Equals(destination)) { |
| 1504 | return; |
| 1505 | } |
| 1506 | if (destination.IsRegister()) { |
| 1507 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1508 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1509 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1510 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1511 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1512 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1513 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1514 | } else if (destination.IsFpuRegister()) { |
| 1515 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1516 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1517 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1518 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1519 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1520 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1521 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1522 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1523 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1524 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1525 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1526 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1527 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1528 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1529 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1530 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1531 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1537 | if (source.Equals(destination)) { |
| 1538 | return; |
| 1539 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1540 | if (destination.IsRegisterPair()) { |
| 1541 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1542 | EmitParallelMoves( |
| 1543 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1544 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1545 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1546 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1547 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1548 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1549 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1550 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1551 | } else if (source.IsFpuRegisterPair()) { |
| 1552 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1553 | destination.AsRegisterPairHigh<Register>(), |
| 1554 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1555 | } else { |
| 1556 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1557 | DCHECK(ExpectedPairLayout(destination)); |
| 1558 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1559 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1560 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1561 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1562 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1563 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1564 | SP, |
| 1565 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1566 | } else if (source.IsRegisterPair()) { |
| 1567 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1568 | source.AsRegisterPairLow<Register>(), |
| 1569 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1570 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1571 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1572 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1573 | } else { |
| 1574 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1575 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1576 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1577 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1578 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1579 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1580 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1581 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1582 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1583 | SP, destination.GetStackIndex()); |
| 1584 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1585 | } else if (source.IsFpuRegisterPair()) { |
| 1586 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1587 | SP, |
| 1588 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1589 | } else { |
| 1590 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1591 | EmitParallelMoves( |
| 1592 | Location::StackSlot(source.GetStackIndex()), |
| 1593 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1594 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1595 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1596 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1597 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1602 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1603 | DCHECK(location.IsRegister()); |
| 1604 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1605 | } |
| 1606 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1607 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1608 | HParallelMove move(GetGraph()->GetArena()); |
| 1609 | move.AddMove(src, dst, dst_type, nullptr); |
| 1610 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1614 | if (location.IsRegister()) { |
| 1615 | locations->AddTemp(location); |
| 1616 | } else if (location.IsRegisterPair()) { |
| 1617 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1618 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1619 | } else { |
| 1620 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1621 | } |
| 1622 | } |
| 1623 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1624 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1625 | HInstruction* instruction, |
| 1626 | uint32_t dex_pc, |
| 1627 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1628 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1629 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1630 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1631 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1632 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1635 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1636 | HInstruction* instruction, |
| 1637 | SlowPathCode* slow_path) { |
| 1638 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1639 | GenerateInvokeRuntime(entry_point_offset); |
| 1640 | } |
| 1641 | |
| 1642 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1643 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1644 | __ blx(LR); |
| 1645 | } |
| 1646 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1647 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1648 | DCHECK(!successor->IsExitBlock()); |
| 1649 | |
| 1650 | HBasicBlock* block = got->GetBlock(); |
| 1651 | HInstruction* previous = got->GetPrevious(); |
| 1652 | |
| 1653 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1654 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1655 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1656 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1661 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1662 | } |
| 1663 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1664 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1668 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1669 | got->SetLocations(nullptr); |
| 1670 | } |
| 1671 | |
| 1672 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1673 | HandleGoto(got, got->GetSuccessor()); |
| 1674 | } |
| 1675 | |
| 1676 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1677 | try_boundary->SetLocations(nullptr); |
| 1678 | } |
| 1679 | |
| 1680 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1681 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1682 | if (!successor->IsExitBlock()) { |
| 1683 | HandleGoto(try_boundary, successor); |
| 1684 | } |
| 1685 | } |
| 1686 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1687 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1688 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1691 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1694 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1695 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1696 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1697 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1698 | if (rhs_loc.IsConstant()) { |
| 1699 | // 0.0 is the only immediate that can be encoded directly in |
| 1700 | // a VCMP instruction. |
| 1701 | // |
| 1702 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1703 | // specify that in a floating-point comparison, positive zero |
| 1704 | // and negative zero are considered equal, so we can use the |
| 1705 | // literal 0.0 for both cases here. |
| 1706 | // |
| 1707 | // Note however that some methods (Float.equal, Float.compare, |
| 1708 | // Float.compareTo, Double.equal, Double.compare, |
| 1709 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1710 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1711 | // -0.0. So if we ever translate calls to these methods into a |
| 1712 | // HCompare instruction, we must handle the -0.0 case with |
| 1713 | // care here. |
| 1714 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1715 | if (type == Primitive::kPrimFloat) { |
| 1716 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1717 | } else { |
| 1718 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1719 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1720 | } |
| 1721 | } else { |
| 1722 | if (type == Primitive::kPrimFloat) { |
| 1723 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1724 | } else { |
| 1725 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1726 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1727 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1732 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1733 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1734 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1735 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1736 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1740 | Label* true_label, |
| 1741 | Label* false_label) { |
| 1742 | LocationSummary* locations = cond->GetLocations(); |
| 1743 | Location left = locations->InAt(0); |
| 1744 | Location right = locations->InAt(1); |
| 1745 | IfCondition if_cond = cond->GetCondition(); |
| 1746 | |
| 1747 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1748 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1749 | IfCondition true_high_cond = if_cond; |
| 1750 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1751 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1752 | |
| 1753 | // Set the conditions for the test, remembering that == needs to be |
| 1754 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1755 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1756 | switch (if_cond) { |
| 1757 | case kCondEQ: |
| 1758 | case kCondNE: |
| 1759 | // Nothing to do. |
| 1760 | break; |
| 1761 | case kCondLT: |
| 1762 | false_high_cond = kCondGT; |
| 1763 | break; |
| 1764 | case kCondLE: |
| 1765 | true_high_cond = kCondLT; |
| 1766 | break; |
| 1767 | case kCondGT: |
| 1768 | false_high_cond = kCondLT; |
| 1769 | break; |
| 1770 | case kCondGE: |
| 1771 | true_high_cond = kCondGT; |
| 1772 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1773 | case kCondB: |
| 1774 | false_high_cond = kCondA; |
| 1775 | break; |
| 1776 | case kCondBE: |
| 1777 | true_high_cond = kCondB; |
| 1778 | break; |
| 1779 | case kCondA: |
| 1780 | false_high_cond = kCondB; |
| 1781 | break; |
| 1782 | case kCondAE: |
| 1783 | true_high_cond = kCondA; |
| 1784 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1785 | } |
| 1786 | if (right.IsConstant()) { |
| 1787 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1788 | int32_t val_low = Low32Bits(value); |
| 1789 | int32_t val_high = High32Bits(value); |
| 1790 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1791 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1792 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1793 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1794 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1795 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1796 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1797 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1798 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1799 | } |
| 1800 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1801 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1802 | } else { |
| 1803 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1804 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1805 | |
| 1806 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1807 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1808 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1809 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1810 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1811 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1812 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1813 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1814 | } |
| 1815 | // Must be equal high, so compare the lows. |
| 1816 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1817 | } |
| 1818 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1820 | __ b(true_label, final_condition); |
| 1821 | } |
| 1822 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1823 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1824 | Label* true_target_in, |
| 1825 | Label* false_target_in) { |
| 1826 | // Generated branching requires both targets to be explicit. If either of the |
| 1827 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1828 | Label fallthrough_target; |
| 1829 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1830 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1831 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1832 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1833 | switch (type) { |
| 1834 | case Primitive::kPrimLong: |
| 1835 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1836 | break; |
| 1837 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1838 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1839 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1840 | GenerateFPJumps(condition, true_target, false_target); |
| 1841 | break; |
| 1842 | default: |
| 1843 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1844 | } |
| 1845 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1846 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1847 | __ b(false_target); |
| 1848 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1849 | |
| 1850 | if (fallthrough_target.IsLinked()) { |
| 1851 | __ Bind(&fallthrough_target); |
| 1852 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1855 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1856 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1857 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1858 | Label* false_target) { |
| 1859 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1860 | |
| 1861 | if (true_target == nullptr && false_target == nullptr) { |
| 1862 | // Nothing to do. The code always falls through. |
| 1863 | return; |
| 1864 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1865 | // Constant condition, statically compared against "true" (integer value 1). |
| 1866 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1867 | if (true_target != nullptr) { |
| 1868 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1869 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1870 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1871 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1872 | if (false_target != nullptr) { |
| 1873 | __ b(false_target); |
| 1874 | } |
| 1875 | } |
| 1876 | return; |
| 1877 | } |
| 1878 | |
| 1879 | // The following code generates these patterns: |
| 1880 | // (1) true_target == nullptr && false_target != nullptr |
| 1881 | // - opposite condition true => branch to false_target |
| 1882 | // (2) true_target != nullptr && false_target == nullptr |
| 1883 | // - condition true => branch to true_target |
| 1884 | // (3) true_target != nullptr && false_target != nullptr |
| 1885 | // - condition true => branch to true_target |
| 1886 | // - branch to false_target |
| 1887 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1888 | // Condition has been materialized, compare the output to 0. |
| 1889 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1890 | DCHECK(cond_val.IsRegister()); |
| 1891 | if (true_target == nullptr) { |
| 1892 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1893 | } else { |
| 1894 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1895 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1896 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1897 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1898 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1899 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1900 | |
| 1901 | // If this is a long or FP comparison that has been folded into |
| 1902 | // the HCondition, generate the comparison directly. |
| 1903 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1904 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1905 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1906 | return; |
| 1907 | } |
| 1908 | |
| 1909 | LocationSummary* locations = cond->GetLocations(); |
| 1910 | DCHECK(locations->InAt(0).IsRegister()); |
| 1911 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1912 | Location right = locations->InAt(1); |
| 1913 | if (right.IsRegister()) { |
| 1914 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1915 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1916 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1917 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1918 | } |
| 1919 | if (true_target == nullptr) { |
| 1920 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1921 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1922 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1923 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1924 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1925 | |
| 1926 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1927 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1928 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1929 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1933 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1934 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1935 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1936 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1941 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1942 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1943 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1944 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1945 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1946 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1947 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1951 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1952 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1953 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1954 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1955 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1960 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1961 | GenerateTestAndBranch(deoptimize, |
| 1962 | /* condition_input_index */ 0, |
| 1963 | slow_path->GetEntryLabel(), |
| 1964 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1965 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1966 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1967 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1968 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1969 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1970 | locations->SetOut(Location::RequiresRegister()); |
| 1971 | } |
| 1972 | |
| 1973 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1974 | __ LoadFromOffset(kLoadWord, |
| 1975 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 1976 | SP, |
| 1977 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1978 | } |
| 1979 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1980 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1981 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1982 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1983 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1984 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1985 | } else { |
| 1986 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1987 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1988 | } |
| 1989 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1990 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1991 | } |
| 1992 | locations->SetOut(Location::SameAsFirstInput()); |
| 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1996 | LocationSummary* locations = select->GetLocations(); |
| 1997 | Label false_target; |
| 1998 | GenerateTestAndBranch(select, |
| 1999 | /* condition_input_index */ 2, |
| 2000 | /* true_target */ nullptr, |
| 2001 | &false_target); |
| 2002 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2003 | __ Bind(&false_target); |
| 2004 | } |
| 2005 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2006 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2007 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2008 | } |
| 2009 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2010 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2011 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | void CodeGeneratorARM::GenerateNop() { |
| 2015 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2018 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2019 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2020 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2021 | // Handle the long/FP comparisons made in instruction simplification. |
| 2022 | switch (cond->InputAt(0)->GetType()) { |
| 2023 | case Primitive::kPrimLong: |
| 2024 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2025 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2026 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2027 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2028 | } |
| 2029 | break; |
| 2030 | |
| 2031 | case Primitive::kPrimFloat: |
| 2032 | case Primitive::kPrimDouble: |
| 2033 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2034 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2035 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2036 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2037 | } |
| 2038 | break; |
| 2039 | |
| 2040 | default: |
| 2041 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2042 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2043 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2044 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2045 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2046 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2049 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2050 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2051 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2052 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2053 | |
| 2054 | LocationSummary* locations = cond->GetLocations(); |
| 2055 | Location left = locations->InAt(0); |
| 2056 | Location right = locations->InAt(1); |
| 2057 | Register out = locations->Out().AsRegister<Register>(); |
| 2058 | Label true_label, false_label; |
| 2059 | |
| 2060 | switch (cond->InputAt(0)->GetType()) { |
| 2061 | default: { |
| 2062 | // Integer case. |
| 2063 | if (right.IsRegister()) { |
| 2064 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2065 | } else { |
| 2066 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2067 | __ CmpConstant(left.AsRegister<Register>(), |
| 2068 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2069 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2070 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2071 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2072 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2073 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2074 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2075 | return; |
| 2076 | } |
| 2077 | case Primitive::kPrimLong: |
| 2078 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2079 | break; |
| 2080 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2081 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2082 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2083 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2084 | break; |
| 2085 | } |
| 2086 | |
| 2087 | // Convert the jumps into the result. |
| 2088 | Label done_label; |
| 2089 | |
| 2090 | // False case: result = 0. |
| 2091 | __ Bind(&false_label); |
| 2092 | __ LoadImmediate(out, 0); |
| 2093 | __ b(&done_label); |
| 2094 | |
| 2095 | // True case: result = 1. |
| 2096 | __ Bind(&true_label); |
| 2097 | __ LoadImmediate(out, 1); |
| 2098 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2102 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2106 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2110 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2114 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2118 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2122 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2126 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2130 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2134 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2138 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2142 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2146 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2149 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2150 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2154 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2158 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2162 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2166 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2170 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2174 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2178 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2181 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2182 | LocationSummary* locations = |
| 2183 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2184 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2187 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2188 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2191 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2192 | LocationSummary* locations = |
| 2193 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2194 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2195 | } |
| 2196 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2197 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2198 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2201 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2202 | LocationSummary* locations = |
| 2203 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2204 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2205 | } |
| 2206 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2207 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2208 | // Will be generated at use site. |
| 2209 | } |
| 2210 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2211 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2212 | LocationSummary* locations = |
| 2213 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2214 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2215 | } |
| 2216 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2217 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2218 | // Will be generated at use site. |
| 2219 | } |
| 2220 | |
| 2221 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2222 | LocationSummary* locations = |
| 2223 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2224 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2225 | } |
| 2226 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2227 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2228 | // Will be generated at use site. |
| 2229 | } |
| 2230 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2231 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2232 | memory_barrier->SetLocations(nullptr); |
| 2233 | } |
| 2234 | |
| 2235 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2236 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2239 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2240 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2243 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2244 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2247 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2248 | LocationSummary* locations = |
| 2249 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2250 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2253 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2254 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2257 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2258 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2259 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2260 | // the method_idx. |
| 2261 | HandleInvoke(invoke); |
| 2262 | } |
| 2263 | |
| 2264 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2265 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2266 | } |
| 2267 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2268 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2269 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2270 | // art::PrepareForRegisterAllocation. |
| 2271 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2272 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2273 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2274 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2275 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2276 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2277 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2278 | return; |
| 2279 | } |
| 2280 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2281 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2282 | |
| 2283 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2284 | if (invoke->HasPcRelativeDexCache()) { |
| 2285 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2286 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2287 | } |
| 2288 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2289 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2290 | if (invoke->GetLocations()->Intrinsified()) { |
| 2291 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2292 | intrinsic.Dispatch(invoke); |
| 2293 | return true; |
| 2294 | } |
| 2295 | return false; |
| 2296 | } |
| 2297 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2298 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2299 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2300 | // art::PrepareForRegisterAllocation. |
| 2301 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2302 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2303 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2304 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2305 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2306 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2307 | LocationSummary* locations = invoke->GetLocations(); |
| 2308 | codegen_->GenerateStaticOrDirectCall( |
| 2309 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2310 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2311 | } |
| 2312 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2313 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2314 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2315 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2318 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2319 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2320 | if (intrinsic.TryDispatch(invoke)) { |
| 2321 | return; |
| 2322 | } |
| 2323 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2324 | HandleInvoke(invoke); |
| 2325 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2326 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2327 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2328 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2329 | return; |
| 2330 | } |
| 2331 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2332 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2333 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2334 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2337 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2338 | HandleInvoke(invoke); |
| 2339 | // Add the hidden argument. |
| 2340 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2341 | } |
| 2342 | |
| 2343 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2344 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2345 | LocationSummary* locations = invoke->GetLocations(); |
| 2346 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2347 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2348 | Location receiver = locations->InAt(0); |
| 2349 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2350 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2351 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2352 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2353 | DCHECK_EQ(R12, hidden_reg); |
| 2354 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2355 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2356 | if (receiver.IsStackSlot()) { |
| 2357 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2358 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2359 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2360 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2361 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2362 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2363 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2364 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2365 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2366 | // emit a read barrier for the previous class reference load. |
| 2367 | // However this is not required in practice, as this is an |
| 2368 | // intermediate/temporary reference and because the current |
| 2369 | // concurrent copying collector keeps the from-space memory |
| 2370 | // intact/accessible until the end of the marking phase (the |
| 2371 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2372 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2373 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2374 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2375 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2376 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2377 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2378 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2379 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2380 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2381 | // LR = temp->GetEntryPoint(); |
| 2382 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2383 | // LR(); |
| 2384 | __ blx(LR); |
| 2385 | DCHECK(!codegen_->IsLeafMethod()); |
| 2386 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2387 | } |
| 2388 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2389 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2390 | HandleInvoke(invoke); |
| 2391 | } |
| 2392 | |
| 2393 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2394 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2395 | } |
| 2396 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2397 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2398 | LocationSummary* locations = |
| 2399 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2400 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2402 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2403 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2404 | break; |
| 2405 | } |
| 2406 | case Primitive::kPrimLong: { |
| 2407 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2408 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2409 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2410 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2411 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2412 | case Primitive::kPrimFloat: |
| 2413 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2414 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2415 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2416 | break; |
| 2417 | |
| 2418 | default: |
| 2419 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2424 | LocationSummary* locations = neg->GetLocations(); |
| 2425 | Location out = locations->Out(); |
| 2426 | Location in = locations->InAt(0); |
| 2427 | switch (neg->GetResultType()) { |
| 2428 | case Primitive::kPrimInt: |
| 2429 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2430 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2431 | break; |
| 2432 | |
| 2433 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2434 | DCHECK(in.IsRegisterPair()); |
| 2435 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2436 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2437 | in.AsRegisterPairLow<Register>(), |
| 2438 | ShifterOperand(0)); |
| 2439 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2440 | // instruction here, as it does not exist in the Thumb-2 |
| 2441 | // instruction set. We use the following approach |
| 2442 | // using SBC and SUB instead. |
| 2443 | // |
| 2444 | // out.hi = -C |
| 2445 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2446 | out.AsRegisterPairHigh<Register>(), |
| 2447 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2448 | // out.hi = out.hi - in.hi |
| 2449 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2450 | out.AsRegisterPairHigh<Register>(), |
| 2451 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2452 | break; |
| 2453 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2454 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2455 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2456 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2457 | break; |
| 2458 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2459 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2460 | DCHECK(in.IsFpuRegisterPair()); |
| 2461 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2462 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2463 | break; |
| 2464 | |
| 2465 | default: |
| 2466 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2467 | } |
| 2468 | } |
| 2469 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2471 | Primitive::Type result_type = conversion->GetResultType(); |
| 2472 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2473 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2474 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2475 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2476 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2477 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2478 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2479 | && result_type == Primitive::kPrimLong) |
| 2480 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2481 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2482 | : LocationSummary::kNoCall; |
| 2483 | LocationSummary* locations = |
| 2484 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2485 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2486 | // The Java language does not allow treating boolean as an integral type but |
| 2487 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2488 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2489 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimByte: |
| 2491 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimLong: |
| 2493 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimBoolean: |
| 2495 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimShort: |
| 2497 | case Primitive::kPrimInt: |
| 2498 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2499 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2500 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2502 | break; |
| 2503 | |
| 2504 | default: |
| 2505 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2506 | << " to " << result_type; |
| 2507 | } |
| 2508 | break; |
| 2509 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2510 | case Primitive::kPrimShort: |
| 2511 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimLong: |
| 2513 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimBoolean: |
| 2515 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimByte: |
| 2517 | case Primitive::kPrimInt: |
| 2518 | case Primitive::kPrimChar: |
| 2519 | // Processing a Dex `int-to-short' instruction. |
| 2520 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2521 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2522 | break; |
| 2523 | |
| 2524 | default: |
| 2525 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2526 | << " to " << result_type; |
| 2527 | } |
| 2528 | break; |
| 2529 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimInt: |
| 2531 | switch (input_type) { |
| 2532 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2533 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2534 | locations->SetInAt(0, Location::Any()); |
| 2535 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2536 | break; |
| 2537 | |
| 2538 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2539 | // Processing a Dex `float-to-int' instruction. |
| 2540 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2541 | locations->SetOut(Location::RequiresRegister()); |
| 2542 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2543 | break; |
| 2544 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2546 | // Processing a Dex `double-to-int' instruction. |
| 2547 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2548 | locations->SetOut(Location::RequiresRegister()); |
| 2549 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | |
| 2552 | default: |
| 2553 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2554 | << " to " << result_type; |
| 2555 | } |
| 2556 | break; |
| 2557 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimLong: |
| 2559 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimBoolean: |
| 2561 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimByte: |
| 2563 | case Primitive::kPrimShort: |
| 2564 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2566 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2568 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2569 | break; |
| 2570 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2571 | case Primitive::kPrimFloat: { |
| 2572 | // Processing a Dex `float-to-long' instruction. |
| 2573 | InvokeRuntimeCallingConvention calling_convention; |
| 2574 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2575 | calling_convention.GetFpuRegisterAt(0))); |
| 2576 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2577 | break; |
| 2578 | } |
| 2579 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2580 | case Primitive::kPrimDouble: { |
| 2581 | // Processing a Dex `double-to-long' instruction. |
| 2582 | InvokeRuntimeCallingConvention calling_convention; |
| 2583 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2584 | calling_convention.GetFpuRegisterAt(0), |
| 2585 | calling_convention.GetFpuRegisterAt(1))); |
| 2586 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2587 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2588 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2589 | |
| 2590 | default: |
| 2591 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2592 | << " to " << result_type; |
| 2593 | } |
| 2594 | break; |
| 2595 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2596 | case Primitive::kPrimChar: |
| 2597 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2598 | case Primitive::kPrimLong: |
| 2599 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2600 | case Primitive::kPrimBoolean: |
| 2601 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimByte: |
| 2603 | case Primitive::kPrimShort: |
| 2604 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2605 | // Processing a Dex `int-to-char' instruction. |
| 2606 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2607 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2608 | break; |
| 2609 | |
| 2610 | default: |
| 2611 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2612 | << " to " << result_type; |
| 2613 | } |
| 2614 | break; |
| 2615 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2617 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2618 | case Primitive::kPrimBoolean: |
| 2619 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2620 | case Primitive::kPrimByte: |
| 2621 | case Primitive::kPrimShort: |
| 2622 | case Primitive::kPrimInt: |
| 2623 | case Primitive::kPrimChar: |
| 2624 | // Processing a Dex `int-to-float' instruction. |
| 2625 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2626 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2627 | break; |
| 2628 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2629 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2630 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2631 | InvokeRuntimeCallingConvention calling_convention; |
| 2632 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2633 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2634 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2635 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2636 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2637 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2639 | // Processing a Dex `double-to-float' instruction. |
| 2640 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2641 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2642 | break; |
| 2643 | |
| 2644 | default: |
| 2645 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2646 | << " to " << result_type; |
| 2647 | }; |
| 2648 | break; |
| 2649 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2650 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2651 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2652 | case Primitive::kPrimBoolean: |
| 2653 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2654 | case Primitive::kPrimByte: |
| 2655 | case Primitive::kPrimShort: |
| 2656 | case Primitive::kPrimInt: |
| 2657 | case Primitive::kPrimChar: |
| 2658 | // Processing a Dex `int-to-double' instruction. |
| 2659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2660 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2661 | break; |
| 2662 | |
| 2663 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2664 | // Processing a Dex `long-to-double' instruction. |
| 2665 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2666 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2667 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2668 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2669 | break; |
| 2670 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2671 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2672 | // Processing a Dex `float-to-double' instruction. |
| 2673 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2674 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2675 | break; |
| 2676 | |
| 2677 | default: |
| 2678 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2679 | << " to " << result_type; |
| 2680 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2681 | break; |
| 2682 | |
| 2683 | default: |
| 2684 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2685 | << " to " << result_type; |
| 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2690 | LocationSummary* locations = conversion->GetLocations(); |
| 2691 | Location out = locations->Out(); |
| 2692 | Location in = locations->InAt(0); |
| 2693 | Primitive::Type result_type = conversion->GetResultType(); |
| 2694 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2695 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2696 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2697 | case Primitive::kPrimByte: |
| 2698 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimLong: |
| 2700 | // Type conversion from long to byte is a result of code transformations. |
| 2701 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2702 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2703 | case Primitive::kPrimBoolean: |
| 2704 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2705 | case Primitive::kPrimShort: |
| 2706 | case Primitive::kPrimInt: |
| 2707 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2708 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2709 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2710 | break; |
| 2711 | |
| 2712 | default: |
| 2713 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2714 | << " to " << result_type; |
| 2715 | } |
| 2716 | break; |
| 2717 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimShort: |
| 2719 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2720 | case Primitive::kPrimLong: |
| 2721 | // Type conversion from long to short is a result of code transformations. |
| 2722 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2723 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2724 | case Primitive::kPrimBoolean: |
| 2725 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimByte: |
| 2727 | case Primitive::kPrimInt: |
| 2728 | case Primitive::kPrimChar: |
| 2729 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2730 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | |
| 2733 | default: |
| 2734 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2735 | << " to " << result_type; |
| 2736 | } |
| 2737 | break; |
| 2738 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2739 | case Primitive::kPrimInt: |
| 2740 | switch (input_type) { |
| 2741 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2742 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2743 | DCHECK(out.IsRegister()); |
| 2744 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2745 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2746 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2747 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2748 | } else { |
| 2749 | DCHECK(in.IsConstant()); |
| 2750 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2751 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2752 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2753 | } |
| 2754 | break; |
| 2755 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2756 | case Primitive::kPrimFloat: { |
| 2757 | // Processing a Dex `float-to-int' instruction. |
| 2758 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2759 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2760 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2761 | break; |
| 2762 | } |
| 2763 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2764 | case Primitive::kPrimDouble: { |
| 2765 | // Processing a Dex `double-to-int' instruction. |
| 2766 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2767 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2768 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2769 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2770 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2771 | |
| 2772 | default: |
| 2773 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2774 | << " to " << result_type; |
| 2775 | } |
| 2776 | break; |
| 2777 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2778 | case Primitive::kPrimLong: |
| 2779 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2780 | case Primitive::kPrimBoolean: |
| 2781 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2782 | case Primitive::kPrimByte: |
| 2783 | case Primitive::kPrimShort: |
| 2784 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2785 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2786 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2787 | DCHECK(out.IsRegisterPair()); |
| 2788 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2789 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2790 | // Sign extension. |
| 2791 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2792 | out.AsRegisterPairLow<Register>(), |
| 2793 | 31); |
| 2794 | break; |
| 2795 | |
| 2796 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2797 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2798 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2799 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2800 | break; |
| 2801 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2802 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2803 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2804 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2805 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2806 | break; |
| 2807 | |
| 2808 | default: |
| 2809 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2810 | << " to " << result_type; |
| 2811 | } |
| 2812 | break; |
| 2813 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2814 | case Primitive::kPrimChar: |
| 2815 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2816 | case Primitive::kPrimLong: |
| 2817 | // Type conversion from long to char is a result of code transformations. |
| 2818 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2819 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2820 | case Primitive::kPrimBoolean: |
| 2821 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2822 | case Primitive::kPrimByte: |
| 2823 | case Primitive::kPrimShort: |
| 2824 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2825 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2826 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2827 | break; |
| 2828 | |
| 2829 | default: |
| 2830 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2831 | << " to " << result_type; |
| 2832 | } |
| 2833 | break; |
| 2834 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2835 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2836 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2837 | case Primitive::kPrimBoolean: |
| 2838 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2839 | case Primitive::kPrimByte: |
| 2840 | case Primitive::kPrimShort: |
| 2841 | case Primitive::kPrimInt: |
| 2842 | case Primitive::kPrimChar: { |
| 2843 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2844 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2845 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2846 | break; |
| 2847 | } |
| 2848 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2849 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2850 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2851 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2852 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2853 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2854 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2855 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2856 | // Processing a Dex `double-to-float' instruction. |
| 2857 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2858 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | |
| 2861 | default: |
| 2862 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2863 | << " to " << result_type; |
| 2864 | }; |
| 2865 | break; |
| 2866 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2867 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2868 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2869 | case Primitive::kPrimBoolean: |
| 2870 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2871 | case Primitive::kPrimByte: |
| 2872 | case Primitive::kPrimShort: |
| 2873 | case Primitive::kPrimInt: |
| 2874 | case Primitive::kPrimChar: { |
| 2875 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2876 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2877 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2878 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2879 | break; |
| 2880 | } |
| 2881 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2882 | case Primitive::kPrimLong: { |
| 2883 | // Processing a Dex `long-to-double' instruction. |
| 2884 | Register low = in.AsRegisterPairLow<Register>(); |
| 2885 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2886 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2887 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2888 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2889 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2890 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2891 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2892 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2893 | // temp_d = int-to-double(high) |
| 2894 | __ vmovsr(temp_s, high); |
| 2895 | __ vcvtdi(temp_d, temp_s); |
| 2896 | // constant_d = k2Pow32EncodingForDouble |
| 2897 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2898 | // out_d = unsigned-to-double(low) |
| 2899 | __ vmovsr(out_s, low); |
| 2900 | __ vcvtdu(out_d, out_s); |
| 2901 | // out_d += temp_d * constant_d |
| 2902 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2903 | break; |
| 2904 | } |
| 2905 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2906 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2907 | // Processing a Dex `float-to-double' instruction. |
| 2908 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2909 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2910 | break; |
| 2911 | |
| 2912 | default: |
| 2913 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2914 | << " to " << result_type; |
| 2915 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2916 | break; |
| 2917 | |
| 2918 | default: |
| 2919 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2920 | << " to " << result_type; |
| 2921 | } |
| 2922 | } |
| 2923 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2924 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2925 | LocationSummary* locations = |
| 2926 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2927 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2928 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2929 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2930 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2931 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2932 | break; |
| 2933 | } |
| 2934 | |
| 2935 | case Primitive::kPrimLong: { |
| 2936 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2937 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2938 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2939 | break; |
| 2940 | } |
| 2941 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2942 | case Primitive::kPrimFloat: |
| 2943 | case Primitive::kPrimDouble: { |
| 2944 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2945 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2946 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2947 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2948 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2949 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2950 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2951 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2952 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2956 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2957 | Location out = locations->Out(); |
| 2958 | Location first = locations->InAt(0); |
| 2959 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2960 | switch (add->GetResultType()) { |
| 2961 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2962 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2963 | __ add(out.AsRegister<Register>(), |
| 2964 | first.AsRegister<Register>(), |
| 2965 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2966 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2967 | __ AddConstant(out.AsRegister<Register>(), |
| 2968 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2969 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2970 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2971 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2972 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2973 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2974 | if (second.IsConstant()) { |
| 2975 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2976 | GenerateAddLongConst(out, first, value); |
| 2977 | } else { |
| 2978 | DCHECK(second.IsRegisterPair()); |
| 2979 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2980 | first.AsRegisterPairLow<Register>(), |
| 2981 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2982 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2983 | first.AsRegisterPairHigh<Register>(), |
| 2984 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2985 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2986 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2987 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2988 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2989 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2990 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2991 | first.AsFpuRegister<SRegister>(), |
| 2992 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2993 | break; |
| 2994 | |
| 2995 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2996 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2997 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2998 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2999 | break; |
| 3000 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3001 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3002 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3006 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3007 | LocationSummary* locations = |
| 3008 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3009 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3010 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3011 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3012 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3013 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3014 | break; |
| 3015 | } |
| 3016 | |
| 3017 | case Primitive::kPrimLong: { |
| 3018 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3019 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3020 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3021 | break; |
| 3022 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3023 | case Primitive::kPrimFloat: |
| 3024 | case Primitive::kPrimDouble: { |
| 3025 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3026 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3027 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3028 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3029 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3030 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3031 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3032 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3036 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3037 | Location out = locations->Out(); |
| 3038 | Location first = locations->InAt(0); |
| 3039 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3040 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3041 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3042 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3043 | __ sub(out.AsRegister<Register>(), |
| 3044 | first.AsRegister<Register>(), |
| 3045 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3046 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3047 | __ AddConstant(out.AsRegister<Register>(), |
| 3048 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3049 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3050 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3051 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3052 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3053 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3054 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3055 | if (second.IsConstant()) { |
| 3056 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3057 | GenerateAddLongConst(out, first, -value); |
| 3058 | } else { |
| 3059 | DCHECK(second.IsRegisterPair()); |
| 3060 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3061 | first.AsRegisterPairLow<Register>(), |
| 3062 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3063 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3064 | first.AsRegisterPairHigh<Register>(), |
| 3065 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3066 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3067 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3068 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3069 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3070 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3071 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3072 | first.AsFpuRegister<SRegister>(), |
| 3073 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3074 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3078 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3079 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3080 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3081 | break; |
| 3082 | } |
| 3083 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3084 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3085 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3086 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3087 | } |
| 3088 | } |
| 3089 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3090 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3091 | LocationSummary* locations = |
| 3092 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3093 | switch (mul->GetResultType()) { |
| 3094 | case Primitive::kPrimInt: |
| 3095 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3096 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3097 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3098 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3099 | break; |
| 3100 | } |
| 3101 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3102 | case Primitive::kPrimFloat: |
| 3103 | case Primitive::kPrimDouble: { |
| 3104 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3105 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3106 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3107 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3108 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3109 | |
| 3110 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3111 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3116 | LocationSummary* locations = mul->GetLocations(); |
| 3117 | Location out = locations->Out(); |
| 3118 | Location first = locations->InAt(0); |
| 3119 | Location second = locations->InAt(1); |
| 3120 | switch (mul->GetResultType()) { |
| 3121 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3122 | __ mul(out.AsRegister<Register>(), |
| 3123 | first.AsRegister<Register>(), |
| 3124 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | break; |
| 3126 | } |
| 3127 | case Primitive::kPrimLong: { |
| 3128 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3129 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3130 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3131 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3132 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3133 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3134 | |
| 3135 | // Extra checks to protect caused by the existence of R1_R2. |
| 3136 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3137 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3138 | DCHECK_NE(out_hi, in1_lo); |
| 3139 | DCHECK_NE(out_hi, in2_lo); |
| 3140 | |
| 3141 | // input: in1 - 64 bits, in2 - 64 bits |
| 3142 | // output: out |
| 3143 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3144 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3145 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3146 | |
| 3147 | // IP <- in1.lo * in2.hi |
| 3148 | __ mul(IP, in1_lo, in2_hi); |
| 3149 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3150 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3151 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3152 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3153 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3154 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3155 | break; |
| 3156 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3157 | |
| 3158 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3159 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3160 | first.AsFpuRegister<SRegister>(), |
| 3161 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3162 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3166 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3167 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3168 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3169 | break; |
| 3170 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3171 | |
| 3172 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3173 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3174 | } |
| 3175 | } |
| 3176 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3177 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3178 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3179 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3180 | |
| 3181 | LocationSummary* locations = instruction->GetLocations(); |
| 3182 | Location second = locations->InAt(1); |
| 3183 | DCHECK(second.IsConstant()); |
| 3184 | |
| 3185 | Register out = locations->Out().AsRegister<Register>(); |
| 3186 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3187 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3188 | DCHECK(imm == 1 || imm == -1); |
| 3189 | |
| 3190 | if (instruction->IsRem()) { |
| 3191 | __ LoadImmediate(out, 0); |
| 3192 | } else { |
| 3193 | if (imm == 1) { |
| 3194 | __ Mov(out, dividend); |
| 3195 | } else { |
| 3196 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3197 | } |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3202 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3203 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3204 | |
| 3205 | LocationSummary* locations = instruction->GetLocations(); |
| 3206 | Location second = locations->InAt(1); |
| 3207 | DCHECK(second.IsConstant()); |
| 3208 | |
| 3209 | Register out = locations->Out().AsRegister<Register>(); |
| 3210 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3211 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3212 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3213 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3214 | int ctz_imm = CTZ(abs_imm); |
| 3215 | |
| 3216 | if (ctz_imm == 1) { |
| 3217 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3218 | } else { |
| 3219 | __ Asr(temp, dividend, 31); |
| 3220 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3221 | } |
| 3222 | __ add(out, temp, ShifterOperand(dividend)); |
| 3223 | |
| 3224 | if (instruction->IsDiv()) { |
| 3225 | __ Asr(out, out, ctz_imm); |
| 3226 | if (imm < 0) { |
| 3227 | __ rsb(out, out, ShifterOperand(0)); |
| 3228 | } |
| 3229 | } else { |
| 3230 | __ ubfx(out, out, 0, ctz_imm); |
| 3231 | __ sub(out, out, ShifterOperand(temp)); |
| 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3236 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3237 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3238 | |
| 3239 | LocationSummary* locations = instruction->GetLocations(); |
| 3240 | Location second = locations->InAt(1); |
| 3241 | DCHECK(second.IsConstant()); |
| 3242 | |
| 3243 | Register out = locations->Out().AsRegister<Register>(); |
| 3244 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3245 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3246 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3247 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3248 | |
| 3249 | int64_t magic; |
| 3250 | int shift; |
| 3251 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3252 | |
| 3253 | __ LoadImmediate(temp1, magic); |
| 3254 | __ smull(temp2, temp1, dividend, temp1); |
| 3255 | |
| 3256 | if (imm > 0 && magic < 0) { |
| 3257 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3258 | } else if (imm < 0 && magic > 0) { |
| 3259 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3260 | } |
| 3261 | |
| 3262 | if (shift != 0) { |
| 3263 | __ Asr(temp1, temp1, shift); |
| 3264 | } |
| 3265 | |
| 3266 | if (instruction->IsDiv()) { |
| 3267 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3268 | } else { |
| 3269 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3270 | // TODO: Strength reduction for mls. |
| 3271 | __ LoadImmediate(temp2, imm); |
| 3272 | __ mls(out, temp1, temp2, dividend); |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3277 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3278 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3279 | |
| 3280 | LocationSummary* locations = instruction->GetLocations(); |
| 3281 | Location second = locations->InAt(1); |
| 3282 | DCHECK(second.IsConstant()); |
| 3283 | |
| 3284 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3285 | if (imm == 0) { |
| 3286 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3287 | } else if (imm == 1 || imm == -1) { |
| 3288 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3289 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3290 | DivRemByPowerOfTwo(instruction); |
| 3291 | } else { |
| 3292 | DCHECK(imm <= -2 || imm >= 2); |
| 3293 | GenerateDivRemWithAnyConstant(instruction); |
| 3294 | } |
| 3295 | } |
| 3296 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3297 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3298 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3299 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3300 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3301 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3302 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3303 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3304 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3305 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3306 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3307 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3310 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3311 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3312 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3313 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3314 | if (div->InputAt(1)->IsConstant()) { |
| 3315 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3316 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3317 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3318 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3319 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3320 | // No temp register required. |
| 3321 | } else { |
| 3322 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3323 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3324 | locations->AddTemp(Location::RequiresRegister()); |
| 3325 | } |
| 3326 | } |
| 3327 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3328 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3329 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3330 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3331 | } else { |
| 3332 | InvokeRuntimeCallingConvention calling_convention; |
| 3333 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3334 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3335 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3336 | // we only need the former. |
| 3337 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3338 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3339 | break; |
| 3340 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3341 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3342 | InvokeRuntimeCallingConvention calling_convention; |
| 3343 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3344 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3345 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3346 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3347 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3348 | break; |
| 3349 | } |
| 3350 | case Primitive::kPrimFloat: |
| 3351 | case Primitive::kPrimDouble: { |
| 3352 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3353 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3354 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3355 | break; |
| 3356 | } |
| 3357 | |
| 3358 | default: |
| 3359 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3364 | LocationSummary* locations = div->GetLocations(); |
| 3365 | Location out = locations->Out(); |
| 3366 | Location first = locations->InAt(0); |
| 3367 | Location second = locations->InAt(1); |
| 3368 | |
| 3369 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3370 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3371 | if (second.IsConstant()) { |
| 3372 | GenerateDivRemConstantIntegral(div); |
| 3373 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3374 | __ sdiv(out.AsRegister<Register>(), |
| 3375 | first.AsRegister<Register>(), |
| 3376 | second.AsRegister<Register>()); |
| 3377 | } else { |
| 3378 | InvokeRuntimeCallingConvention calling_convention; |
| 3379 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3380 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3381 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3382 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3383 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3384 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3385 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3386 | break; |
| 3387 | } |
| 3388 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3389 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3390 | InvokeRuntimeCallingConvention calling_convention; |
| 3391 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3392 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3393 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3394 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3395 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3396 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3397 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3398 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3399 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3400 | break; |
| 3401 | } |
| 3402 | |
| 3403 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3404 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3405 | first.AsFpuRegister<SRegister>(), |
| 3406 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3407 | break; |
| 3408 | } |
| 3409 | |
| 3410 | case Primitive::kPrimDouble: { |
| 3411 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3412 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3413 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3414 | break; |
| 3415 | } |
| 3416 | |
| 3417 | default: |
| 3418 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3419 | } |
| 3420 | } |
| 3421 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3422 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3423 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3424 | |
| 3425 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3426 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3427 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3428 | // sdiv will be replaced by other instruction sequence. |
| 3429 | call_kind = LocationSummary::kNoCall; |
| 3430 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3431 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3432 | // Have hardware divide instruction for int, do it with three instructions. |
| 3433 | call_kind = LocationSummary::kNoCall; |
| 3434 | } |
| 3435 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3436 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3437 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3438 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3439 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3440 | if (rem->InputAt(1)->IsConstant()) { |
| 3441 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3442 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3443 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3444 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3445 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3446 | // No temp register required. |
| 3447 | } else { |
| 3448 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3449 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3450 | locations->AddTemp(Location::RequiresRegister()); |
| 3451 | } |
| 3452 | } |
| 3453 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3455 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3456 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3457 | locations->AddTemp(Location::RequiresRegister()); |
| 3458 | } else { |
| 3459 | InvokeRuntimeCallingConvention calling_convention; |
| 3460 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3461 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3462 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3463 | // we only need the latter. |
| 3464 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3465 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3466 | break; |
| 3467 | } |
| 3468 | case Primitive::kPrimLong: { |
| 3469 | InvokeRuntimeCallingConvention calling_convention; |
| 3470 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3471 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3472 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3473 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3474 | // The runtime helper puts the output in R2,R3. |
| 3475 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3476 | break; |
| 3477 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3478 | case Primitive::kPrimFloat: { |
| 3479 | InvokeRuntimeCallingConvention calling_convention; |
| 3480 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3481 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3482 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3483 | break; |
| 3484 | } |
| 3485 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3486 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3487 | InvokeRuntimeCallingConvention calling_convention; |
| 3488 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3489 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3490 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3491 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3492 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3493 | break; |
| 3494 | } |
| 3495 | |
| 3496 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3497 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3502 | LocationSummary* locations = rem->GetLocations(); |
| 3503 | Location out = locations->Out(); |
| 3504 | Location first = locations->InAt(0); |
| 3505 | Location second = locations->InAt(1); |
| 3506 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3507 | Primitive::Type type = rem->GetResultType(); |
| 3508 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3509 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3510 | if (second.IsConstant()) { |
| 3511 | GenerateDivRemConstantIntegral(rem); |
| 3512 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3513 | Register reg1 = first.AsRegister<Register>(); |
| 3514 | Register reg2 = second.AsRegister<Register>(); |
| 3515 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3516 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3517 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3518 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3519 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3520 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3521 | } else { |
| 3522 | InvokeRuntimeCallingConvention calling_convention; |
| 3523 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3524 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3525 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3526 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3527 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3528 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3529 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3530 | break; |
| 3531 | } |
| 3532 | |
| 3533 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3534 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3535 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | break; |
| 3537 | } |
| 3538 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3539 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3540 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3541 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3545 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3546 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3547 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3548 | break; |
| 3549 | } |
| 3550 | |
| 3551 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3552 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 | } |
| 3554 | } |
| 3555 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3556 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3557 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3558 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3562 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3563 | codegen_->AddSlowPath(slow_path); |
| 3564 | |
| 3565 | LocationSummary* locations = instruction->GetLocations(); |
| 3566 | Location value = locations->InAt(0); |
| 3567 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3568 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3569 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3570 | case Primitive::kPrimByte: |
| 3571 | case Primitive::kPrimChar: |
| 3572 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3573 | case Primitive::kPrimInt: { |
| 3574 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3575 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3576 | } else { |
| 3577 | DCHECK(value.IsConstant()) << value; |
| 3578 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3579 | __ b(slow_path->GetEntryLabel()); |
| 3580 | } |
| 3581 | } |
| 3582 | break; |
| 3583 | } |
| 3584 | case Primitive::kPrimLong: { |
| 3585 | if (value.IsRegisterPair()) { |
| 3586 | __ orrs(IP, |
| 3587 | value.AsRegisterPairLow<Register>(), |
| 3588 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3589 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3590 | } else { |
| 3591 | DCHECK(value.IsConstant()) << value; |
| 3592 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3593 | __ b(slow_path->GetEntryLabel()); |
| 3594 | } |
| 3595 | } |
| 3596 | break; |
| 3597 | default: |
| 3598 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3599 | } |
| 3600 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3603 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3604 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3605 | Location rhs = locations->InAt(1); |
| 3606 | Register out = locations->Out().AsRegister<Register>(); |
| 3607 | |
| 3608 | if (rhs.IsConstant()) { |
| 3609 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3610 | // so map all rotations to a +ve. equivalent in that range. |
| 3611 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3612 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3613 | if (rot) { |
| 3614 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3615 | // (e.g. left by 2 bits == right by 30.) |
| 3616 | __ Ror(out, in, rot); |
| 3617 | } else if (out != in) { |
| 3618 | __ Mov(out, in); |
| 3619 | } |
| 3620 | } else { |
| 3621 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3626 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3627 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3628 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3629 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3630 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3631 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3632 | Location rhs = locations->InAt(1); |
| 3633 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3634 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3635 | |
| 3636 | if (rhs.IsConstant()) { |
| 3637 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3638 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3639 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3640 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3641 | // logic below to a simple pair of binary orr. |
| 3642 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3643 | if (rot >= kArmBitsPerWord) { |
| 3644 | rot -= kArmBitsPerWord; |
| 3645 | std::swap(in_reg_hi, in_reg_lo); |
| 3646 | } |
| 3647 | // Rotate, or mov to out for zero or word size rotations. |
| 3648 | if (rot != 0u) { |
| 3649 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3650 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3651 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3652 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3653 | } else { |
| 3654 | __ Mov(out_reg_lo, in_reg_lo); |
| 3655 | __ Mov(out_reg_hi, in_reg_hi); |
| 3656 | } |
| 3657 | } else { |
| 3658 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3659 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3660 | Label end; |
| 3661 | Label shift_by_32_plus_shift_right; |
| 3662 | |
| 3663 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3664 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3665 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3666 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3667 | |
| 3668 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3669 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3670 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3671 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3672 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3673 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3674 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3675 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3676 | __ b(&end); |
| 3677 | |
| 3678 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3679 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3680 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3681 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3682 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3683 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3684 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3685 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3686 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3687 | |
| 3688 | __ Bind(&end); |
| 3689 | } |
| 3690 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3691 | |
| 3692 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3693 | LocationSummary* locations = |
| 3694 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3695 | switch (ror->GetResultType()) { |
| 3696 | case Primitive::kPrimInt: { |
| 3697 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3698 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3699 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3700 | break; |
| 3701 | } |
| 3702 | case Primitive::kPrimLong: { |
| 3703 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3704 | if (ror->InputAt(1)->IsConstant()) { |
| 3705 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3706 | } else { |
| 3707 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3708 | locations->AddTemp(Location::RequiresRegister()); |
| 3709 | locations->AddTemp(Location::RequiresRegister()); |
| 3710 | } |
| 3711 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3712 | break; |
| 3713 | } |
| 3714 | default: |
| 3715 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3716 | } |
| 3717 | } |
| 3718 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3719 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3720 | LocationSummary* locations = ror->GetLocations(); |
| 3721 | Primitive::Type type = ror->GetResultType(); |
| 3722 | switch (type) { |
| 3723 | case Primitive::kPrimInt: { |
| 3724 | HandleIntegerRotate(locations); |
| 3725 | break; |
| 3726 | } |
| 3727 | case Primitive::kPrimLong: { |
| 3728 | HandleLongRotate(locations); |
| 3729 | break; |
| 3730 | } |
| 3731 | default: |
| 3732 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3733 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3734 | } |
| 3735 | } |
| 3736 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3737 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3738 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3739 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3740 | LocationSummary* locations = |
| 3741 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3742 | |
| 3743 | switch (op->GetResultType()) { |
| 3744 | case Primitive::kPrimInt: { |
| 3745 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3746 | if (op->InputAt(1)->IsConstant()) { |
| 3747 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3748 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3749 | } else { |
| 3750 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3751 | // Make the output overlap, as it will be used to hold the masked |
| 3752 | // second input. |
| 3753 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3754 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3755 | break; |
| 3756 | } |
| 3757 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3758 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3759 | if (op->InputAt(1)->IsConstant()) { |
| 3760 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3761 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3762 | // don't clash with high registers which the register allocator currently guarantees. |
| 3763 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3764 | } else { |
| 3765 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3766 | locations->AddTemp(Location::RequiresRegister()); |
| 3767 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3768 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3769 | break; |
| 3770 | } |
| 3771 | default: |
| 3772 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3777 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3778 | |
| 3779 | LocationSummary* locations = op->GetLocations(); |
| 3780 | Location out = locations->Out(); |
| 3781 | Location first = locations->InAt(0); |
| 3782 | Location second = locations->InAt(1); |
| 3783 | |
| 3784 | Primitive::Type type = op->GetResultType(); |
| 3785 | switch (type) { |
| 3786 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3787 | Register out_reg = out.AsRegister<Register>(); |
| 3788 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3789 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3790 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3791 | // 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] | 3792 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3793 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3794 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3795 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3796 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3797 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3798 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3799 | } |
| 3800 | } else { |
| 3801 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3802 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3803 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3804 | __ Mov(out_reg, first_reg); |
| 3805 | } else if (op->IsShl()) { |
| 3806 | __ Lsl(out_reg, first_reg, shift_value); |
| 3807 | } else if (op->IsShr()) { |
| 3808 | __ Asr(out_reg, first_reg, shift_value); |
| 3809 | } else { |
| 3810 | __ Lsr(out_reg, first_reg, shift_value); |
| 3811 | } |
| 3812 | } |
| 3813 | break; |
| 3814 | } |
| 3815 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3816 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3817 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3818 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3819 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3820 | Register low = first.AsRegisterPairLow<Register>(); |
| 3821 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3822 | if (second.IsRegister()) { |
| 3823 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3824 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3825 | Register second_reg = second.AsRegister<Register>(); |
| 3826 | |
| 3827 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3828 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3829 | // Shift the high part |
| 3830 | __ Lsl(o_h, high, o_l); |
| 3831 | // Shift the low part and `or` what overflew on the high part |
| 3832 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3833 | __ Lsr(temp, low, temp); |
| 3834 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3835 | // If the shift is > 32 bits, override the high part |
| 3836 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3837 | __ it(PL); |
| 3838 | __ Lsl(o_h, low, temp, PL); |
| 3839 | // Shift the low part |
| 3840 | __ Lsl(o_l, low, o_l); |
| 3841 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3842 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3843 | // Shift the low part |
| 3844 | __ Lsr(o_l, low, o_h); |
| 3845 | // Shift the high part and `or` what underflew on the low part |
| 3846 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3847 | __ Lsl(temp, high, temp); |
| 3848 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3849 | // If the shift is > 32 bits, override the low part |
| 3850 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3851 | __ it(PL); |
| 3852 | __ Asr(o_l, high, temp, PL); |
| 3853 | // Shift the high part |
| 3854 | __ Asr(o_h, high, o_h); |
| 3855 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3856 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3857 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3858 | __ Lsr(o_l, low, o_h); |
| 3859 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3860 | __ Lsl(temp, high, temp); |
| 3861 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3862 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3863 | __ it(PL); |
| 3864 | __ Lsr(o_l, high, temp, PL); |
| 3865 | __ Lsr(o_h, high, o_h); |
| 3866 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3867 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3868 | // Register allocator doesn't create partial overlap. |
| 3869 | DCHECK_NE(o_l, high); |
| 3870 | DCHECK_NE(o_h, low); |
| 3871 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3872 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3873 | if (shift_value > 32) { |
| 3874 | if (op->IsShl()) { |
| 3875 | __ Lsl(o_h, low, shift_value - 32); |
| 3876 | __ LoadImmediate(o_l, 0); |
| 3877 | } else if (op->IsShr()) { |
| 3878 | __ Asr(o_l, high, shift_value - 32); |
| 3879 | __ Asr(o_h, high, 31); |
| 3880 | } else { |
| 3881 | __ Lsr(o_l, high, shift_value - 32); |
| 3882 | __ LoadImmediate(o_h, 0); |
| 3883 | } |
| 3884 | } else if (shift_value == 32) { |
| 3885 | if (op->IsShl()) { |
| 3886 | __ mov(o_h, ShifterOperand(low)); |
| 3887 | __ LoadImmediate(o_l, 0); |
| 3888 | } else if (op->IsShr()) { |
| 3889 | __ mov(o_l, ShifterOperand(high)); |
| 3890 | __ Asr(o_h, high, 31); |
| 3891 | } else { |
| 3892 | __ mov(o_l, ShifterOperand(high)); |
| 3893 | __ LoadImmediate(o_h, 0); |
| 3894 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3895 | } else if (shift_value == 1) { |
| 3896 | if (op->IsShl()) { |
| 3897 | __ Lsls(o_l, low, 1); |
| 3898 | __ adc(o_h, high, ShifterOperand(high)); |
| 3899 | } else if (op->IsShr()) { |
| 3900 | __ Asrs(o_h, high, 1); |
| 3901 | __ Rrx(o_l, low); |
| 3902 | } else { |
| 3903 | __ Lsrs(o_h, high, 1); |
| 3904 | __ Rrx(o_l, low); |
| 3905 | } |
| 3906 | } else { |
| 3907 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3908 | if (op->IsShl()) { |
| 3909 | __ Lsl(o_h, high, shift_value); |
| 3910 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3911 | __ Lsl(o_l, low, shift_value); |
| 3912 | } else if (op->IsShr()) { |
| 3913 | __ Lsr(o_l, low, shift_value); |
| 3914 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3915 | __ Asr(o_h, high, shift_value); |
| 3916 | } else { |
| 3917 | __ Lsr(o_l, low, shift_value); |
| 3918 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3919 | __ Lsr(o_h, high, shift_value); |
| 3920 | } |
| 3921 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3922 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3923 | break; |
| 3924 | } |
| 3925 | default: |
| 3926 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3927 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3932 | HandleShift(shl); |
| 3933 | } |
| 3934 | |
| 3935 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3936 | HandleShift(shl); |
| 3937 | } |
| 3938 | |
| 3939 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3940 | HandleShift(shr); |
| 3941 | } |
| 3942 | |
| 3943 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3944 | HandleShift(shr); |
| 3945 | } |
| 3946 | |
| 3947 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3948 | HandleShift(ushr); |
| 3949 | } |
| 3950 | |
| 3951 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3952 | HandleShift(ushr); |
| 3953 | } |
| 3954 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3955 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3956 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3957 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3958 | if (instruction->IsStringAlloc()) { |
| 3959 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3960 | } else { |
| 3961 | InvokeRuntimeCallingConvention calling_convention; |
| 3962 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3963 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3964 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3968 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3969 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3970 | if (instruction->IsStringAlloc()) { |
| 3971 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3972 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3973 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3974 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3975 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3976 | __ blx(LR); |
| 3977 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3978 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3979 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 3980 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3981 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3982 | } |
| 3983 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3984 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3985 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3986 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3987 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3988 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 3989 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3990 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3994 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3995 | // of poisoning the reference. |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 3996 | codegen_->InvokeRuntime(kQuickAllocArrayResolved, instruction, instruction->GetDexPc()); |
| 3997 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3998 | } |
| 3999 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4000 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4001 | LocationSummary* locations = |
| 4002 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4003 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4004 | if (location.IsStackSlot()) { |
| 4005 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4006 | } else if (location.IsDoubleStackSlot()) { |
| 4007 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4008 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4009 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4010 | } |
| 4011 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4012 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4013 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4014 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4018 | LocationSummary* locations = |
| 4019 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4020 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4021 | } |
| 4022 | |
| 4023 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4024 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4025 | } |
| 4026 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4027 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4028 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4029 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4030 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4032 | } |
| 4033 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4034 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4035 | LocationSummary* locations = not_->GetLocations(); |
| 4036 | Location out = locations->Out(); |
| 4037 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4038 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4039 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4040 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4041 | break; |
| 4042 | |
| 4043 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4044 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4045 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4046 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4047 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4048 | break; |
| 4049 | |
| 4050 | default: |
| 4051 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4052 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4053 | } |
| 4054 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4055 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4056 | LocationSummary* locations = |
| 4057 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4058 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4059 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4060 | } |
| 4061 | |
| 4062 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4063 | LocationSummary* locations = bool_not->GetLocations(); |
| 4064 | Location out = locations->Out(); |
| 4065 | Location in = locations->InAt(0); |
| 4066 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4067 | } |
| 4068 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4069 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4070 | LocationSummary* locations = |
| 4071 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4072 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4073 | case Primitive::kPrimBoolean: |
| 4074 | case Primitive::kPrimByte: |
| 4075 | case Primitive::kPrimShort: |
| 4076 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4077 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4078 | case Primitive::kPrimLong: { |
| 4079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4080 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4081 | // Output overlaps because it is written before doing the low comparison. |
| 4082 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4083 | break; |
| 4084 | } |
| 4085 | case Primitive::kPrimFloat: |
| 4086 | case Primitive::kPrimDouble: { |
| 4087 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4088 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4089 | locations->SetOut(Location::RequiresRegister()); |
| 4090 | break; |
| 4091 | } |
| 4092 | default: |
| 4093 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4094 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4098 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4099 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4100 | Location left = locations->InAt(0); |
| 4101 | Location right = locations->InAt(1); |
| 4102 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4103 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4104 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4105 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4106 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4107 | case Primitive::kPrimBoolean: |
| 4108 | case Primitive::kPrimByte: |
| 4109 | case Primitive::kPrimShort: |
| 4110 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4111 | case Primitive::kPrimInt: { |
| 4112 | __ LoadImmediate(out, 0); |
| 4113 | __ cmp(left.AsRegister<Register>(), |
| 4114 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4115 | less_cond = LT; |
| 4116 | break; |
| 4117 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4118 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4119 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4120 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4121 | __ b(&less, LT); |
| 4122 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4123 | // 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] | 4124 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4125 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4126 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4127 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| 4130 | case Primitive::kPrimFloat: |
| 4131 | case Primitive::kPrimDouble: { |
| 4132 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4133 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4134 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4135 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4136 | break; |
| 4137 | } |
| 4138 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4139 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4140 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4141 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4142 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4143 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4144 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4145 | |
| 4146 | __ Bind(&greater); |
| 4147 | __ LoadImmediate(out, 1); |
| 4148 | __ b(&done); |
| 4149 | |
| 4150 | __ Bind(&less); |
| 4151 | __ LoadImmediate(out, -1); |
| 4152 | |
| 4153 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4156 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4157 | LocationSummary* locations = |
| 4158 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4159 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4160 | locations->SetInAt(i, Location::Any()); |
| 4161 | } |
| 4162 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4163 | } |
| 4164 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4165 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4166 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4169 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4170 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4171 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4172 | switch (kind) { |
| 4173 | case MemBarrierKind::kAnyStore: |
| 4174 | case MemBarrierKind::kLoadAny: |
| 4175 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4176 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | break; |
| 4178 | } |
| 4179 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4180 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4181 | break; |
| 4182 | } |
| 4183 | default: |
| 4184 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4185 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4186 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4190 | uint32_t offset, |
| 4191 | Register out_lo, |
| 4192 | Register out_hi) { |
| 4193 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4194 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4195 | // `offset` into `out_lo` does not clutter `addr`. |
| 4196 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4197 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4198 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4199 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4200 | } |
| 4201 | __ ldrexd(out_lo, out_hi, addr); |
| 4202 | } |
| 4203 | |
| 4204 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4205 | uint32_t offset, |
| 4206 | Register value_lo, |
| 4207 | Register value_hi, |
| 4208 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4209 | Register temp2, |
| 4210 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4211 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4212 | if (offset != 0) { |
| 4213 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4214 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4215 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4216 | } |
| 4217 | __ Bind(&fail); |
| 4218 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4219 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4220 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4221 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4222 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4223 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4227 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4228 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4229 | LocationSummary* locations = |
| 4230 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4231 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4232 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4233 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4234 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4235 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4236 | } else { |
| 4237 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4238 | } |
| 4239 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4240 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4241 | bool generate_volatile = field_info.IsVolatile() |
| 4242 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4243 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4244 | bool needs_write_barrier = |
| 4245 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4246 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4247 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4248 | if (needs_write_barrier) { |
| 4249 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4250 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4251 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4252 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4253 | // - registers need to be consecutive |
| 4254 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4255 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4256 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4257 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4258 | |
| 4259 | locations->AddTemp(Location::RequiresRegister()); |
| 4260 | locations->AddTemp(Location::RequiresRegister()); |
| 4261 | if (field_type == Primitive::kPrimDouble) { |
| 4262 | // For doubles we need two more registers to copy the value. |
| 4263 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4264 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4265 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4266 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4267 | } |
| 4268 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4269 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4270 | const FieldInfo& field_info, |
| 4271 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4272 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4273 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4274 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4275 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4276 | Location value = locations->InAt(1); |
| 4277 | |
| 4278 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4279 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4280 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4281 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4282 | bool needs_write_barrier = |
| 4283 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4284 | |
| 4285 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4286 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4287 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4288 | |
| 4289 | switch (field_type) { |
| 4290 | case Primitive::kPrimBoolean: |
| 4291 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4292 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | case Primitive::kPrimShort: |
| 4297 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4298 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4299 | break; |
| 4300 | } |
| 4301 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4302 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4303 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4304 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4305 | // Note that in the case where `value` is a null reference, |
| 4306 | // we do not enter this block, as a null reference does not |
| 4307 | // need poisoning. |
| 4308 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4309 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4310 | __ Mov(temp, value.AsRegister<Register>()); |
| 4311 | __ PoisonHeapReference(temp); |
| 4312 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4313 | } else { |
| 4314 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4315 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4316 | break; |
| 4317 | } |
| 4318 | |
| 4319 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4320 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4321 | GenerateWideAtomicStore(base, offset, |
| 4322 | value.AsRegisterPairLow<Register>(), |
| 4323 | value.AsRegisterPairHigh<Register>(), |
| 4324 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4325 | locations->GetTemp(1).AsRegister<Register>(), |
| 4326 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4327 | } else { |
| 4328 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4329 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4330 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4331 | break; |
| 4332 | } |
| 4333 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4334 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4335 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4336 | break; |
| 4337 | } |
| 4338 | |
| 4339 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4340 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4341 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4342 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4343 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4344 | |
| 4345 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4346 | |
| 4347 | GenerateWideAtomicStore(base, offset, |
| 4348 | value_reg_lo, |
| 4349 | value_reg_hi, |
| 4350 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4351 | locations->GetTemp(3).AsRegister<Register>(), |
| 4352 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4353 | } else { |
| 4354 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4355 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4356 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4357 | break; |
| 4358 | } |
| 4359 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4360 | case Primitive::kPrimVoid: |
| 4361 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4362 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4363 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4364 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4365 | // Longs and doubles are handled in the switch. |
| 4366 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4367 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4368 | } |
| 4369 | |
| 4370 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4371 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4372 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4373 | codegen_->MarkGCCard( |
| 4374 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4377 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4378 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4379 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4380 | } |
| 4381 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4382 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4383 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4384 | |
| 4385 | bool object_field_get_with_read_barrier = |
| 4386 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4387 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4388 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4389 | object_field_get_with_read_barrier ? |
| 4390 | LocationSummary::kCallOnSlowPath : |
| 4391 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4392 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4393 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4394 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4395 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4396 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4397 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4398 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4399 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4400 | // The output overlaps in case of volatile long: we don't want the |
| 4401 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4402 | // object's location. Likewise, in the case of an object field get |
| 4403 | // with read barriers enabled, we do not want the load to overwrite |
| 4404 | // the object's location, as we need it to emit the read barrier. |
| 4405 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4406 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4407 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4408 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4409 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4410 | } else { |
| 4411 | locations->SetOut(Location::RequiresRegister(), |
| 4412 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4413 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4414 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4415 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4416 | // - registers need to be consecutive |
| 4417 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4418 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4419 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4420 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4421 | locations->AddTemp(Location::RequiresRegister()); |
| 4422 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4423 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4424 | // We need a temporary register for the read barrier marking slow |
| 4425 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4426 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4427 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4428 | } |
| 4429 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4430 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4431 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4432 | << input->GetType(); |
| 4433 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4434 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4435 | return Location::ConstantLocation(input->AsConstant()); |
| 4436 | } else { |
| 4437 | return Location::RequiresFpuRegister(); |
| 4438 | } |
| 4439 | } |
| 4440 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4441 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4442 | Opcode opcode) { |
| 4443 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4444 | if (constant->IsConstant() && |
| 4445 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4446 | return Location::ConstantLocation(constant->AsConstant()); |
| 4447 | } |
| 4448 | return Location::RequiresRegister(); |
| 4449 | } |
| 4450 | |
| 4451 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4452 | Opcode opcode) { |
| 4453 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4454 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4455 | Opcode high_opcode = opcode; |
| 4456 | SetCc low_set_cc = kCcDontCare; |
| 4457 | switch (opcode) { |
| 4458 | case SUB: |
| 4459 | // Flip the operation to an ADD. |
| 4460 | value = -value; |
| 4461 | opcode = ADD; |
| 4462 | FALLTHROUGH_INTENDED; |
| 4463 | case ADD: |
| 4464 | if (Low32Bits(value) == 0u) { |
| 4465 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4466 | } |
| 4467 | high_opcode = ADC; |
| 4468 | low_set_cc = kCcSet; |
| 4469 | break; |
| 4470 | default: |
| 4471 | break; |
| 4472 | } |
| 4473 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4474 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4475 | } else { |
| 4476 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4477 | } |
| 4478 | } |
| 4479 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4480 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4481 | Opcode opcode, |
| 4482 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4483 | ShifterOperand so; |
| 4484 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4485 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4486 | return true; |
| 4487 | } |
| 4488 | Opcode neg_opcode = kNoOperand; |
| 4489 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4490 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4491 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4492 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4493 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4494 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4495 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4496 | default: |
| 4497 | return false; |
| 4498 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4499 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4500 | } |
| 4501 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4502 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4503 | const FieldInfo& field_info) { |
| 4504 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4505 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4506 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4507 | Location base_loc = locations->InAt(0); |
| 4508 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4509 | Location out = locations->Out(); |
| 4510 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4511 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4512 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4513 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4514 | |
| 4515 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4516 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4517 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4518 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4519 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4520 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4521 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4522 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4523 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4524 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4525 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4526 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4527 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4528 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4529 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4530 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4531 | |
| 4532 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4533 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4534 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4535 | |
| 4536 | case Primitive::kPrimNot: { |
| 4537 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4538 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4539 | Location temp_loc = locations->GetTemp(0); |
| 4540 | // Note that a potential implicit null check is handled in this |
| 4541 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4542 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4543 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4544 | if (is_volatile) { |
| 4545 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4546 | } |
| 4547 | } else { |
| 4548 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4549 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4550 | if (is_volatile) { |
| 4551 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4552 | } |
| 4553 | // If read barriers are enabled, emit read barriers other than |
| 4554 | // Baker's using a slow path (and also unpoison the loaded |
| 4555 | // reference, if heap poisoning is enabled). |
| 4556 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4557 | } |
| 4558 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4559 | } |
| 4560 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4561 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4562 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4563 | GenerateWideAtomicLoad(base, offset, |
| 4564 | out.AsRegisterPairLow<Register>(), |
| 4565 | out.AsRegisterPairHigh<Register>()); |
| 4566 | } else { |
| 4567 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4568 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4569 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4570 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4571 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4572 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4573 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4574 | |
| 4575 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4576 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4577 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4579 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4580 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4581 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4582 | __ vmovdrr(out_reg, lo, hi); |
| 4583 | } else { |
| 4584 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4585 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4586 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4587 | break; |
| 4588 | } |
| 4589 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4590 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4591 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4592 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4593 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4594 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4595 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4596 | // Potential implicit null checks, in the case of reference or |
| 4597 | // double fields, are handled in the previous switch statement. |
| 4598 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4599 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4600 | } |
| 4601 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4602 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4603 | if (field_type == Primitive::kPrimNot) { |
| 4604 | // Memory barriers, in the case of references, are also handled |
| 4605 | // in the previous switch statement. |
| 4606 | } else { |
| 4607 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4608 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4609 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4613 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4614 | } |
| 4615 | |
| 4616 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4617 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4621 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4622 | } |
| 4623 | |
| 4624 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4625 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4626 | } |
| 4627 | |
| 4628 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4629 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4630 | } |
| 4631 | |
| 4632 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4633 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4634 | } |
| 4635 | |
| 4636 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4637 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4638 | } |
| 4639 | |
| 4640 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4641 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4644 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4645 | HUnresolvedInstanceFieldGet* instruction) { |
| 4646 | FieldAccessCallingConventionARM calling_convention; |
| 4647 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4648 | instruction, instruction->GetFieldType(), calling_convention); |
| 4649 | } |
| 4650 | |
| 4651 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4652 | HUnresolvedInstanceFieldGet* instruction) { |
| 4653 | FieldAccessCallingConventionARM calling_convention; |
| 4654 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4655 | instruction->GetFieldType(), |
| 4656 | instruction->GetFieldIndex(), |
| 4657 | instruction->GetDexPc(), |
| 4658 | calling_convention); |
| 4659 | } |
| 4660 | |
| 4661 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4662 | HUnresolvedInstanceFieldSet* instruction) { |
| 4663 | FieldAccessCallingConventionARM calling_convention; |
| 4664 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4665 | instruction, instruction->GetFieldType(), calling_convention); |
| 4666 | } |
| 4667 | |
| 4668 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4669 | HUnresolvedInstanceFieldSet* instruction) { |
| 4670 | FieldAccessCallingConventionARM calling_convention; |
| 4671 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4672 | instruction->GetFieldType(), |
| 4673 | instruction->GetFieldIndex(), |
| 4674 | instruction->GetDexPc(), |
| 4675 | calling_convention); |
| 4676 | } |
| 4677 | |
| 4678 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4679 | HUnresolvedStaticFieldGet* instruction) { |
| 4680 | FieldAccessCallingConventionARM calling_convention; |
| 4681 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4682 | instruction, instruction->GetFieldType(), calling_convention); |
| 4683 | } |
| 4684 | |
| 4685 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4686 | HUnresolvedStaticFieldGet* instruction) { |
| 4687 | FieldAccessCallingConventionARM calling_convention; |
| 4688 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4689 | instruction->GetFieldType(), |
| 4690 | instruction->GetFieldIndex(), |
| 4691 | instruction->GetDexPc(), |
| 4692 | calling_convention); |
| 4693 | } |
| 4694 | |
| 4695 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4696 | HUnresolvedStaticFieldSet* instruction) { |
| 4697 | FieldAccessCallingConventionARM calling_convention; |
| 4698 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4699 | instruction, instruction->GetFieldType(), calling_convention); |
| 4700 | } |
| 4701 | |
| 4702 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4703 | HUnresolvedStaticFieldSet* instruction) { |
| 4704 | FieldAccessCallingConventionARM calling_convention; |
| 4705 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4706 | instruction->GetFieldType(), |
| 4707 | instruction->GetFieldIndex(), |
| 4708 | instruction->GetDexPc(), |
| 4709 | calling_convention); |
| 4710 | } |
| 4711 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4712 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4713 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4714 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4715 | } |
| 4716 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4717 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4718 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4719 | return; |
| 4720 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4721 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4722 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4723 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4724 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4727 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4728 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4729 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4730 | |
| 4731 | LocationSummary* locations = instruction->GetLocations(); |
| 4732 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4733 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4734 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4735 | } |
| 4736 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4737 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4738 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4741 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4742 | switch (type) { |
| 4743 | case Primitive::kPrimNot: |
| 4744 | return kLoadWord; |
| 4745 | case Primitive::kPrimBoolean: |
| 4746 | return kLoadUnsignedByte; |
| 4747 | case Primitive::kPrimByte: |
| 4748 | return kLoadSignedByte; |
| 4749 | case Primitive::kPrimChar: |
| 4750 | return kLoadUnsignedHalfword; |
| 4751 | case Primitive::kPrimShort: |
| 4752 | return kLoadSignedHalfword; |
| 4753 | case Primitive::kPrimInt: |
| 4754 | return kLoadWord; |
| 4755 | case Primitive::kPrimLong: |
| 4756 | return kLoadWordPair; |
| 4757 | case Primitive::kPrimFloat: |
| 4758 | return kLoadSWord; |
| 4759 | case Primitive::kPrimDouble: |
| 4760 | return kLoadDWord; |
| 4761 | default: |
| 4762 | LOG(FATAL) << "Unreachable type " << type; |
| 4763 | UNREACHABLE(); |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4768 | switch (type) { |
| 4769 | case Primitive::kPrimNot: |
| 4770 | return kStoreWord; |
| 4771 | case Primitive::kPrimBoolean: |
| 4772 | case Primitive::kPrimByte: |
| 4773 | return kStoreByte; |
| 4774 | case Primitive::kPrimChar: |
| 4775 | case Primitive::kPrimShort: |
| 4776 | return kStoreHalfword; |
| 4777 | case Primitive::kPrimInt: |
| 4778 | return kStoreWord; |
| 4779 | case Primitive::kPrimLong: |
| 4780 | return kStoreWordPair; |
| 4781 | case Primitive::kPrimFloat: |
| 4782 | return kStoreSWord; |
| 4783 | case Primitive::kPrimDouble: |
| 4784 | return kStoreDWord; |
| 4785 | default: |
| 4786 | LOG(FATAL) << "Unreachable type " << type; |
| 4787 | UNREACHABLE(); |
| 4788 | } |
| 4789 | } |
| 4790 | |
| 4791 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4792 | Location out_loc, |
| 4793 | Register base, |
| 4794 | Register reg_offset, |
| 4795 | Condition cond) { |
| 4796 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4797 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4798 | |
| 4799 | switch (type) { |
| 4800 | case Primitive::kPrimByte: |
| 4801 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4802 | break; |
| 4803 | case Primitive::kPrimBoolean: |
| 4804 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4805 | break; |
| 4806 | case Primitive::kPrimShort: |
| 4807 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4808 | break; |
| 4809 | case Primitive::kPrimChar: |
| 4810 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4811 | break; |
| 4812 | case Primitive::kPrimNot: |
| 4813 | case Primitive::kPrimInt: |
| 4814 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4815 | break; |
| 4816 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4817 | case Primitive::kPrimLong: |
| 4818 | case Primitive::kPrimFloat: |
| 4819 | case Primitive::kPrimDouble: |
| 4820 | default: |
| 4821 | LOG(FATAL) << "Unreachable type " << type; |
| 4822 | UNREACHABLE(); |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4827 | Location loc, |
| 4828 | Register base, |
| 4829 | Register reg_offset, |
| 4830 | Condition cond) { |
| 4831 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4832 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4833 | |
| 4834 | switch (type) { |
| 4835 | case Primitive::kPrimByte: |
| 4836 | case Primitive::kPrimBoolean: |
| 4837 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4838 | break; |
| 4839 | case Primitive::kPrimShort: |
| 4840 | case Primitive::kPrimChar: |
| 4841 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4842 | break; |
| 4843 | case Primitive::kPrimNot: |
| 4844 | case Primitive::kPrimInt: |
| 4845 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4846 | break; |
| 4847 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4848 | case Primitive::kPrimLong: |
| 4849 | case Primitive::kPrimFloat: |
| 4850 | case Primitive::kPrimDouble: |
| 4851 | default: |
| 4852 | LOG(FATAL) << "Unreachable type " << type; |
| 4853 | UNREACHABLE(); |
| 4854 | } |
| 4855 | } |
| 4856 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4857 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4858 | bool object_array_get_with_read_barrier = |
| 4859 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4860 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4861 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4862 | object_array_get_with_read_barrier ? |
| 4863 | LocationSummary::kCallOnSlowPath : |
| 4864 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4865 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4866 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4867 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4868 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4869 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4870 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4871 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4872 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4873 | // The output overlaps in the case of an object array get with |
| 4874 | // read barriers enabled: we do not want the move to overwrite the |
| 4875 | // array's location, as we need it to emit the read barrier. |
| 4876 | locations->SetOut( |
| 4877 | Location::RequiresRegister(), |
| 4878 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4879 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4880 | // We need a temporary register for the read barrier marking slow |
| 4881 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4882 | // Also need for String compression feature. |
| 4883 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4884 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4885 | locations->AddTemp(Location::RequiresRegister()); |
| 4886 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4890 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4891 | Location obj_loc = locations->InAt(0); |
| 4892 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4893 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4894 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4895 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4896 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4897 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4898 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4899 | HInstruction* array_instr = instruction->GetArray(); |
| 4900 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4901 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4902 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4903 | case Primitive::kPrimBoolean: |
| 4904 | case Primitive::kPrimByte: |
| 4905 | case Primitive::kPrimShort: |
| 4906 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4907 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4908 | Register length; |
| 4909 | if (maybe_compressed_char_at) { |
| 4910 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 4911 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4912 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4913 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4914 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4915 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4916 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4917 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4918 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4919 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4920 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4921 | "Expecting 0=compressed, 1=uncompressed"); |
| 4922 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4923 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4924 | out_loc.AsRegister<Register>(), |
| 4925 | obj, |
| 4926 | data_offset + const_index); |
| 4927 | __ b(&done); |
| 4928 | __ Bind(&uncompressed_load); |
| 4929 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4930 | out_loc.AsRegister<Register>(), |
| 4931 | obj, |
| 4932 | data_offset + (const_index << 1)); |
| 4933 | __ Bind(&done); |
| 4934 | } else { |
| 4935 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4936 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4937 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4938 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4939 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4940 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4941 | Register temp = IP; |
| 4942 | |
| 4943 | if (has_intermediate_address) { |
| 4944 | // We do not need to compute the intermediate address from the array: the |
| 4945 | // input instruction has done it already. See the comment in |
| 4946 | // `TryExtractArrayAccessAddress()`. |
| 4947 | if (kIsDebugBuild) { |
| 4948 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4949 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4950 | } |
| 4951 | temp = obj; |
| 4952 | } else { |
| 4953 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4954 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4955 | if (maybe_compressed_char_at) { |
| 4956 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4957 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4958 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4959 | "Expecting 0=compressed, 1=uncompressed"); |
| 4960 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4961 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4962 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4963 | __ b(&done); |
| 4964 | __ Bind(&uncompressed_load); |
| 4965 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4966 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4967 | __ Bind(&done); |
| 4968 | } else { |
| 4969 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4970 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4971 | } |
| 4972 | break; |
| 4973 | } |
| 4974 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4975 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 4976 | // The read barrier instrumentation of object ArrayGet |
| 4977 | // instructions does not support the HIntermediateAddress |
| 4978 | // instruction. |
| 4979 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 4980 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4981 | static_assert( |
| 4982 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4983 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4984 | // /* HeapReference<Object> */ out = |
| 4985 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4986 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4987 | Location temp = locations->GetTemp(0); |
| 4988 | // Note that a potential implicit null check is handled in this |
| 4989 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4990 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4991 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4992 | } else { |
| 4993 | Register out = out_loc.AsRegister<Register>(); |
| 4994 | if (index.IsConstant()) { |
| 4995 | size_t offset = |
| 4996 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4997 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4998 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4999 | // If read barriers are enabled, emit read barriers other than |
| 5000 | // Baker's using a slow path (and also unpoison the loaded |
| 5001 | // reference, if heap poisoning is enabled). |
| 5002 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5003 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5004 | Register temp = IP; |
| 5005 | |
| 5006 | if (has_intermediate_address) { |
| 5007 | // We do not need to compute the intermediate address from the array: the |
| 5008 | // input instruction has done it already. See the comment in |
| 5009 | // `TryExtractArrayAccessAddress()`. |
| 5010 | if (kIsDebugBuild) { |
| 5011 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5012 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5013 | } |
| 5014 | temp = obj; |
| 5015 | } else { |
| 5016 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5017 | } |
| 5018 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5019 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5020 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5021 | // If read barriers are enabled, emit read barriers other than |
| 5022 | // Baker's using a slow path (and also unpoison the loaded |
| 5023 | // reference, if heap poisoning is enabled). |
| 5024 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5025 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5026 | } |
| 5027 | } |
| 5028 | break; |
| 5029 | } |
| 5030 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5031 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5032 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5033 | size_t offset = |
| 5034 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5035 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5036 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5037 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5038 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5039 | } |
| 5040 | break; |
| 5041 | } |
| 5042 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5043 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5044 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5045 | if (index.IsConstant()) { |
| 5046 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5047 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5048 | } else { |
| 5049 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5050 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5051 | } |
| 5052 | break; |
| 5053 | } |
| 5054 | |
| 5055 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5056 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5057 | if (index.IsConstant()) { |
| 5058 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5059 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5060 | } else { |
| 5061 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5062 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5063 | } |
| 5064 | break; |
| 5065 | } |
| 5066 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5067 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5068 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5069 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5070 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5071 | |
| 5072 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5073 | // Potential implicit null checks, in the case of reference |
| 5074 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5075 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5077 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5081 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5082 | |
| 5083 | bool needs_write_barrier = |
| 5084 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5085 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5086 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5087 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5088 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5089 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5090 | LocationSummary::kCallOnSlowPath : |
| 5091 | LocationSummary::kNoCall); |
| 5092 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5093 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5094 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5095 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5096 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5097 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5098 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5099 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5100 | if (needs_write_barrier) { |
| 5101 | // Temporary registers for the write barrier. |
| 5102 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5103 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5108 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5109 | Location array_loc = locations->InAt(0); |
| 5110 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5112 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5113 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5114 | bool needs_write_barrier = |
| 5115 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5116 | uint32_t data_offset = |
| 5117 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5118 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5119 | HInstruction* array_instr = instruction->GetArray(); |
| 5120 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5121 | |
| 5122 | switch (value_type) { |
| 5123 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5124 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5125 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5126 | case Primitive::kPrimChar: |
| 5127 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5128 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5129 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5130 | uint32_t full_offset = |
| 5131 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5132 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5133 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5134 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5135 | Register temp = IP; |
| 5136 | |
| 5137 | if (has_intermediate_address) { |
| 5138 | // We do not need to compute the intermediate address from the array: the |
| 5139 | // input instruction has done it already. See the comment in |
| 5140 | // `TryExtractArrayAccessAddress()`. |
| 5141 | if (kIsDebugBuild) { |
| 5142 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5143 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5144 | } |
| 5145 | temp = array; |
| 5146 | } else { |
| 5147 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5148 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5149 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5150 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5151 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5152 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | } |
| 5154 | break; |
| 5155 | } |
| 5156 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5158 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5159 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5160 | // See the comment in instruction_simplifier_shared.cc. |
| 5161 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | |
| 5163 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5164 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5165 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5166 | size_t offset = |
| 5167 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5168 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5169 | } else { |
| 5170 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5171 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5172 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5173 | value_loc, |
| 5174 | IP, |
| 5175 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5176 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5177 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5178 | DCHECK(!needs_write_barrier); |
| 5179 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5180 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5181 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5182 | |
| 5183 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5184 | Location temp1_loc = locations->GetTemp(0); |
| 5185 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5186 | Location temp2_loc = locations->GetTemp(1); |
| 5187 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5188 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5189 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5190 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5191 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5192 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5193 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5194 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5195 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5196 | codegen_->AddSlowPath(slow_path); |
| 5197 | if (instruction->GetValueCanBeNull()) { |
| 5198 | Label non_zero; |
| 5199 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5200 | if (index.IsConstant()) { |
| 5201 | size_t offset = |
| 5202 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5203 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5204 | } else { |
| 5205 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5206 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5207 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5208 | value_loc, |
| 5209 | IP, |
| 5210 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5211 | } |
| 5212 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5213 | __ b(&done); |
| 5214 | __ Bind(&non_zero); |
| 5215 | } |
| 5216 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5217 | // Note that when read barriers are enabled, the type checks |
| 5218 | // are performed without read barriers. This is fine, even in |
| 5219 | // the case where a class object is in the from-space after |
| 5220 | // the flip, as a comparison involving such a type would not |
| 5221 | // produce a false positive; it may of course produce a false |
| 5222 | // negative, in which case we would take the ArraySet slow |
| 5223 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5224 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5225 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5226 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5227 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5228 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5229 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5230 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5231 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5232 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5233 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5234 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5235 | // nor `temp2`, as we are comparing two poisoned references. |
| 5236 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5237 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5238 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5239 | Label do_put; |
| 5240 | __ b(&do_put, EQ); |
| 5241 | // If heap poisoning is enabled, the `temp1` reference has |
| 5242 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5243 | __ MaybeUnpoisonHeapReference(temp1); |
| 5244 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5245 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5246 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5247 | // If heap poisoning is enabled, no need to unpoison |
| 5248 | // `temp1`, as we are comparing against null below. |
| 5249 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5250 | __ Bind(&do_put); |
| 5251 | } else { |
| 5252 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5253 | } |
| 5254 | } |
| 5255 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5256 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5257 | if (kPoisonHeapReferences) { |
| 5258 | // Note that in the case where `value` is a null reference, |
| 5259 | // we do not enter this block, as a null reference does not |
| 5260 | // need poisoning. |
| 5261 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5262 | __ Mov(temp1, value); |
| 5263 | __ PoisonHeapReference(temp1); |
| 5264 | source = temp1; |
| 5265 | } |
| 5266 | |
| 5267 | if (index.IsConstant()) { |
| 5268 | size_t offset = |
| 5269 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5270 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5271 | } else { |
| 5272 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5273 | |
| 5274 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5275 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5276 | Location::RegisterLocation(source), |
| 5277 | IP, |
| 5278 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5279 | } |
| 5280 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5281 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5282 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5283 | } |
| 5284 | |
| 5285 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5286 | |
| 5287 | if (done.IsLinked()) { |
| 5288 | __ Bind(&done); |
| 5289 | } |
| 5290 | |
| 5291 | if (slow_path != nullptr) { |
| 5292 | __ Bind(slow_path->GetExitLabel()); |
| 5293 | } |
| 5294 | |
| 5295 | break; |
| 5296 | } |
| 5297 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5299 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5300 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5301 | size_t offset = |
| 5302 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5303 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5304 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5306 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5307 | } |
| 5308 | break; |
| 5309 | } |
| 5310 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5311 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5312 | Location value = locations->InAt(2); |
| 5313 | DCHECK(value.IsFpuRegister()); |
| 5314 | if (index.IsConstant()) { |
| 5315 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5316 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5317 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5318 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5319 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5320 | } |
| 5321 | break; |
| 5322 | } |
| 5323 | |
| 5324 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5325 | Location value = locations->InAt(2); |
| 5326 | DCHECK(value.IsFpuRegisterPair()); |
| 5327 | if (index.IsConstant()) { |
| 5328 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5329 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5330 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5331 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5332 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5333 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5334 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5335 | break; |
| 5336 | } |
| 5337 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5338 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5339 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5340 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5341 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5342 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5343 | // Objects are handled in the switch. |
| 5344 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5346 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5350 | LocationSummary* locations = |
| 5351 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5352 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5357 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5358 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5359 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5360 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5361 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5363 | // Mask out compression flag from String's array length. |
| 5364 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5365 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5366 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | } |
| 5368 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5369 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5370 | LocationSummary* locations = |
| 5371 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5372 | |
| 5373 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5374 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5375 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5376 | } |
| 5377 | |
| 5378 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5379 | LocationSummary* locations = instruction->GetLocations(); |
| 5380 | Location out = locations->Out(); |
| 5381 | Location first = locations->InAt(0); |
| 5382 | Location second = locations->InAt(1); |
| 5383 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5384 | if (second.IsRegister()) { |
| 5385 | __ add(out.AsRegister<Register>(), |
| 5386 | first.AsRegister<Register>(), |
| 5387 | ShifterOperand(second.AsRegister<Register>())); |
| 5388 | } else { |
| 5389 | __ AddConstant(out.AsRegister<Register>(), |
| 5390 | first.AsRegister<Register>(), |
| 5391 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5392 | } |
| 5393 | } |
| 5394 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5395 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5396 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5397 | InvokeRuntimeCallingConvention calling_convention; |
| 5398 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5399 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5400 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5401 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5402 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5406 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5407 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5408 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5409 | codegen_->AddSlowPath(slow_path); |
| 5410 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5411 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5412 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5413 | |
| 5414 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5415 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5416 | } |
| 5417 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5418 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5419 | Register card, |
| 5420 | Register object, |
| 5421 | Register value, |
| 5422 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5423 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5424 | if (can_be_null) { |
| 5425 | __ CompareAndBranchIfZero(value, &is_null); |
| 5426 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5427 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5428 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5429 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5430 | if (can_be_null) { |
| 5431 | __ Bind(&is_null); |
| 5432 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5433 | } |
| 5434 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5435 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5436 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5440 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5441 | } |
| 5442 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5443 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5444 | LocationSummary* locations = |
| 5445 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5446 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5450 | HBasicBlock* block = instruction->GetBlock(); |
| 5451 | if (block->GetLoopInformation() != nullptr) { |
| 5452 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5453 | // The back edge will generate the suspend check. |
| 5454 | return; |
| 5455 | } |
| 5456 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5457 | // The goto will generate the suspend check. |
| 5458 | return; |
| 5459 | } |
| 5460 | GenerateSuspendCheck(instruction, nullptr); |
| 5461 | } |
| 5462 | |
| 5463 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5464 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5465 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5466 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5467 | if (slow_path == nullptr) { |
| 5468 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5469 | instruction->SetSlowPath(slow_path); |
| 5470 | codegen_->AddSlowPath(slow_path); |
| 5471 | if (successor != nullptr) { |
| 5472 | DCHECK(successor->IsLoopHeader()); |
| 5473 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5474 | } |
| 5475 | } else { |
| 5476 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5477 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5478 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5479 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5480 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5481 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5482 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5483 | __ Bind(slow_path->GetReturnLabel()); |
| 5484 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5485 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5486 | __ b(slow_path->GetEntryLabel()); |
| 5487 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5488 | } |
| 5489 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5490 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5491 | return codegen_->GetAssembler(); |
| 5492 | } |
| 5493 | |
| 5494 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5495 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5496 | Location source = move->GetSource(); |
| 5497 | Location destination = move->GetDestination(); |
| 5498 | |
| 5499 | if (source.IsRegister()) { |
| 5500 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5501 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5502 | } else if (destination.IsFpuRegister()) { |
| 5503 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5504 | } else { |
| 5505 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5506 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5507 | SP, destination.GetStackIndex()); |
| 5508 | } |
| 5509 | } else if (source.IsStackSlot()) { |
| 5510 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5511 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5512 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5513 | } else if (destination.IsFpuRegister()) { |
| 5514 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5515 | } else { |
| 5516 | DCHECK(destination.IsStackSlot()); |
| 5517 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5518 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5519 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5520 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5521 | if (destination.IsRegister()) { |
| 5522 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5523 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5524 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5525 | } else { |
| 5526 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5527 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5528 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5529 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5530 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5531 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5532 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5533 | } else if (destination.IsRegisterPair()) { |
| 5534 | DCHECK(ExpectedPairLayout(destination)); |
| 5535 | __ LoadFromOffset( |
| 5536 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5537 | } else { |
| 5538 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5539 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5540 | SP, |
| 5541 | source.GetStackIndex()); |
| 5542 | } |
| 5543 | } else if (source.IsRegisterPair()) { |
| 5544 | if (destination.IsRegisterPair()) { |
| 5545 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5546 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5547 | } else if (destination.IsFpuRegisterPair()) { |
| 5548 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5549 | source.AsRegisterPairLow<Register>(), |
| 5550 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5551 | } else { |
| 5552 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5553 | DCHECK(ExpectedPairLayout(source)); |
| 5554 | __ StoreToOffset( |
| 5555 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5556 | } |
| 5557 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5558 | if (destination.IsRegisterPair()) { |
| 5559 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5560 | destination.AsRegisterPairHigh<Register>(), |
| 5561 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5562 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5563 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5564 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5565 | } else { |
| 5566 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5567 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5568 | SP, |
| 5569 | destination.GetStackIndex()); |
| 5570 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5571 | } else { |
| 5572 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5573 | HConstant* constant = source.GetConstant(); |
| 5574 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5575 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5576 | if (destination.IsRegister()) { |
| 5577 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5578 | } else { |
| 5579 | DCHECK(destination.IsStackSlot()); |
| 5580 | __ LoadImmediate(IP, value); |
| 5581 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5582 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5583 | } else if (constant->IsLongConstant()) { |
| 5584 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5585 | if (destination.IsRegisterPair()) { |
| 5586 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5587 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5588 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5589 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5590 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5591 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5592 | __ LoadImmediate(IP, High32Bits(value)); |
| 5593 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5594 | } |
| 5595 | } else if (constant->IsDoubleConstant()) { |
| 5596 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5597 | if (destination.IsFpuRegisterPair()) { |
| 5598 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5599 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5600 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5601 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5602 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5603 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5604 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5605 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5606 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5607 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5608 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5609 | float value = constant->AsFloatConstant()->GetValue(); |
| 5610 | if (destination.IsFpuRegister()) { |
| 5611 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5612 | } else { |
| 5613 | DCHECK(destination.IsStackSlot()); |
| 5614 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5615 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5616 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5617 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5618 | } |
| 5619 | } |
| 5620 | |
| 5621 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5622 | __ Mov(IP, reg); |
| 5623 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5624 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5625 | } |
| 5626 | |
| 5627 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5628 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5629 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5630 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5631 | SP, mem1 + stack_offset); |
| 5632 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5633 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5634 | SP, mem2 + stack_offset); |
| 5635 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5636 | } |
| 5637 | |
| 5638 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5639 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5640 | Location source = move->GetSource(); |
| 5641 | Location destination = move->GetDestination(); |
| 5642 | |
| 5643 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5644 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5645 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5646 | __ Mov(IP, source.AsRegister<Register>()); |
| 5647 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5648 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5649 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5650 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5651 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5652 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5653 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5654 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5655 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5656 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5657 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5658 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5659 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5660 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5661 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5662 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5663 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5664 | destination.AsRegisterPairHigh<Register>(), |
| 5665 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5666 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5667 | Register low_reg = source.IsRegisterPair() |
| 5668 | ? source.AsRegisterPairLow<Register>() |
| 5669 | : destination.AsRegisterPairLow<Register>(); |
| 5670 | int mem = source.IsRegisterPair() |
| 5671 | ? destination.GetStackIndex() |
| 5672 | : source.GetStackIndex(); |
| 5673 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5674 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5675 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5676 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5677 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5678 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5679 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5680 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5681 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5682 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5683 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5684 | DRegister reg = source.IsFpuRegisterPair() |
| 5685 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5686 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5687 | int mem = source.IsFpuRegisterPair() |
| 5688 | ? destination.GetStackIndex() |
| 5689 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5690 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5691 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5692 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5693 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5694 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5695 | : destination.AsFpuRegister<SRegister>(); |
| 5696 | int mem = source.IsFpuRegister() |
| 5697 | ? destination.GetStackIndex() |
| 5698 | : source.GetStackIndex(); |
| 5699 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5700 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5701 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5702 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5703 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5704 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5705 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5706 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5707 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5708 | } |
| 5709 | } |
| 5710 | |
| 5711 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5712 | __ Push(static_cast<Register>(reg)); |
| 5713 | } |
| 5714 | |
| 5715 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5716 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5719 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5720 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5721 | switch (desired_class_load_kind) { |
| 5722 | case HLoadClass::LoadKind::kReferrersClass: |
| 5723 | break; |
| 5724 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5725 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5726 | break; |
| 5727 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5728 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5729 | break; |
| 5730 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5731 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5732 | case HLoadClass::LoadKind::kBssEntry: |
| 5733 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5734 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5735 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5736 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5737 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5738 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5739 | break; |
| 5740 | } |
| 5741 | return desired_class_load_kind; |
| 5742 | } |
| 5743 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5744 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5745 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5746 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5747 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5748 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5749 | cls, |
| 5750 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5751 | Location::RegisterLocation(R0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5752 | return; |
| 5753 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5754 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5755 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5756 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5757 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5758 | ? LocationSummary::kCallOnSlowPath |
| 5759 | : LocationSummary::kNoCall; |
| 5760 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5761 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5762 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5763 | } |
| 5764 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5765 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5766 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5767 | } |
| 5768 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5769 | } |
| 5770 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5771 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5772 | // move. |
| 5773 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5774 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5775 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5776 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5777 | return; |
| 5778 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5779 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5780 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5781 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5782 | Location out_loc = locations->Out(); |
| 5783 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5784 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5785 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5786 | ? kWithoutReadBarrier |
| 5787 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5788 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5789 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5790 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5791 | DCHECK(!cls->CanCallRuntime()); |
| 5792 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5793 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5794 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5795 | GenerateGcRootFieldLoad(cls, |
| 5796 | out_loc, |
| 5797 | current_method, |
| 5798 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5799 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5800 | break; |
| 5801 | } |
| 5802 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5803 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5804 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5805 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5806 | cls->GetTypeIndex())); |
| 5807 | break; |
| 5808 | } |
| 5809 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5810 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5811 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5812 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5813 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5814 | __ BindTrackedLabel(&labels->movw_label); |
| 5815 | __ movw(out, /* placeholder */ 0u); |
| 5816 | __ BindTrackedLabel(&labels->movt_label); |
| 5817 | __ movt(out, /* placeholder */ 0u); |
| 5818 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5819 | __ add(out, out, ShifterOperand(PC)); |
| 5820 | break; |
| 5821 | } |
| 5822 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5823 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5824 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5825 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5826 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5827 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5828 | break; |
| 5829 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5830 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5831 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5832 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5833 | __ BindTrackedLabel(&labels->movw_label); |
| 5834 | __ movw(out, /* placeholder */ 0u); |
| 5835 | __ BindTrackedLabel(&labels->movt_label); |
| 5836 | __ movt(out, /* placeholder */ 0u); |
| 5837 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5838 | __ add(out, out, ShifterOperand(PC)); |
| 5839 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, kCompilerReadBarrierOption); |
| 5840 | generate_null_check = true; |
| 5841 | break; |
| 5842 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5843 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5844 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5845 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5846 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5847 | // /* GcRoot<mirror::Class> */ out = *out |
| 5848 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5849 | break; |
| 5850 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5851 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5852 | LOG(FATAL) << "UNREACHABLE"; |
| 5853 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5854 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5855 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5856 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5857 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5858 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5859 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5860 | codegen_->AddSlowPath(slow_path); |
| 5861 | if (generate_null_check) { |
| 5862 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5863 | } |
| 5864 | if (cls->MustGenerateClinitCheck()) { |
| 5865 | GenerateClassInitializationCheck(slow_path, out); |
| 5866 | } else { |
| 5867 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5868 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5869 | } |
| 5870 | } |
| 5871 | |
| 5872 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5873 | LocationSummary* locations = |
| 5874 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5875 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5876 | if (check->HasUses()) { |
| 5877 | locations->SetOut(Location::SameAsFirstInput()); |
| 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5882 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5883 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5884 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5885 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5886 | GenerateClassInitializationCheck(slow_path, |
| 5887 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5888 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5889 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5890 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5891 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5892 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5893 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5894 | __ b(slow_path->GetEntryLabel(), LT); |
| 5895 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5896 | // properly. Therefore, we do a memory fence. |
| 5897 | __ dmb(ISH); |
| 5898 | __ Bind(slow_path->GetExitLabel()); |
| 5899 | } |
| 5900 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5901 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5902 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5903 | switch (desired_string_load_kind) { |
| 5904 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5905 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5906 | break; |
| 5907 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5908 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5909 | break; |
| 5910 | case HLoadString::LoadKind::kBootImageAddress: |
| 5911 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5912 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5913 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5914 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5915 | case HLoadString::LoadKind::kJitTableAddress: |
| 5916 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5917 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5918 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5919 | break; |
| 5920 | } |
| 5921 | return desired_string_load_kind; |
| 5922 | } |
| 5923 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5924 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5925 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5926 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5927 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5928 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5929 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5930 | } else { |
| 5931 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5932 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5933 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5934 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 5935 | // Note that IP may theoretically be clobbered by saving/restoring the live register |
| 5936 | // (only one thanks to the custom calling convention), so we request a different temp. |
| 5937 | locations->AddTemp(Location::RequiresRegister()); |
| 5938 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5939 | InvokeRuntimeCallingConvention calling_convention; |
| 5940 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5941 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5942 | // that the the kPrimNot result register is the same as the first argument register. |
| 5943 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5944 | } else { |
| 5945 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5946 | } |
| 5947 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5948 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5949 | } |
| 5950 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5951 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5952 | // move. |
| 5953 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5954 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5955 | Location out_loc = locations->Out(); |
| 5956 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5957 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5958 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5959 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5960 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5961 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5962 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5963 | load->GetStringIndex())); |
| 5964 | return; // No dex cache slow path. |
| 5965 | } |
| 5966 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5967 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5968 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5969 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5970 | __ BindTrackedLabel(&labels->movw_label); |
| 5971 | __ movw(out, /* placeholder */ 0u); |
| 5972 | __ BindTrackedLabel(&labels->movt_label); |
| 5973 | __ movt(out, /* placeholder */ 0u); |
| 5974 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5975 | __ add(out, out, ShifterOperand(PC)); |
| 5976 | return; // No dex cache slow path. |
| 5977 | } |
| 5978 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5979 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5980 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5981 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5982 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5983 | return; // No dex cache slow path. |
| 5984 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5985 | case HLoadString::LoadKind::kBssEntry: { |
| 5986 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5987 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5988 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5989 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5990 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5991 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5992 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5993 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5994 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5995 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5996 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5997 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5998 | codegen_->AddSlowPath(slow_path); |
| 5999 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6000 | __ Bind(slow_path->GetExitLabel()); |
| 6001 | return; |
| 6002 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6003 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6004 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6005 | load->GetStringIndex(), |
| 6006 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6007 | // /* GcRoot<mirror::String> */ out = *out |
| 6008 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6009 | return; |
| 6010 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6011 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6012 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6013 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6014 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6015 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6016 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6017 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6018 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6019 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6020 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6021 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6024 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6025 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6026 | } |
| 6027 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6028 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6029 | LocationSummary* locations = |
| 6030 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6031 | locations->SetOut(Location::RequiresRegister()); |
| 6032 | } |
| 6033 | |
| 6034 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6035 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6036 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6037 | } |
| 6038 | |
| 6039 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6040 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6041 | } |
| 6042 | |
| 6043 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6044 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6045 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6049 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6050 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6051 | InvokeRuntimeCallingConvention calling_convention; |
| 6052 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6053 | } |
| 6054 | |
| 6055 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6056 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6057 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6058 | } |
| 6059 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6060 | // Temp is used for read barrier. |
| 6061 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6062 | if (kEmitCompilerReadBarrier && |
| 6063 | (kUseBakerReadBarrier || |
| 6064 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6065 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6066 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6067 | return 1; |
| 6068 | } |
| 6069 | return 0; |
| 6070 | } |
| 6071 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6072 | // 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] | 6073 | // interface pointer, one for loading the current interface. |
| 6074 | // The other checks have one temp for loading the object's class. |
| 6075 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6076 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6077 | return 3; |
| 6078 | } |
| 6079 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6082 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6083 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6084 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6085 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6086 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6087 | case TypeCheckKind::kExactCheck: |
| 6088 | case TypeCheckKind::kAbstractClassCheck: |
| 6089 | case TypeCheckKind::kClassHierarchyCheck: |
| 6090 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6091 | call_kind = |
| 6092 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6093 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6094 | break; |
| 6095 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6096 | case TypeCheckKind::kUnresolvedCheck: |
| 6097 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6098 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6099 | break; |
| 6100 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6101 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6102 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6103 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6104 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6105 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6106 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6107 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6108 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6109 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6110 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6111 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6112 | } |
| 6113 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6114 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6115 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6116 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6117 | Location obj_loc = locations->InAt(0); |
| 6118 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6119 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6120 | Location out_loc = locations->Out(); |
| 6121 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6122 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6123 | DCHECK_LE(num_temps, 1u); |
| 6124 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6125 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6126 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6127 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6128 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6129 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6130 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6131 | |
| 6132 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6133 | // avoid null check if we know obj is not null. |
| 6134 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6135 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6136 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6137 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6138 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6139 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6140 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6141 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6142 | out_loc, |
| 6143 | obj_loc, |
| 6144 | class_offset, |
| 6145 | maybe_temp_loc, |
| 6146 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6147 | __ cmp(out, ShifterOperand(cls)); |
| 6148 | // Classes must be equal for the instanceof to succeed. |
| 6149 | __ b(&zero, NE); |
| 6150 | __ LoadImmediate(out, 1); |
| 6151 | __ b(&done); |
| 6152 | break; |
| 6153 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6154 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6155 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6156 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6157 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6158 | out_loc, |
| 6159 | obj_loc, |
| 6160 | class_offset, |
| 6161 | maybe_temp_loc, |
| 6162 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6163 | // If the class is abstract, we eagerly fetch the super class of the |
| 6164 | // object to avoid doing a comparison we know will fail. |
| 6165 | Label loop; |
| 6166 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6167 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6168 | GenerateReferenceLoadOneRegister(instruction, |
| 6169 | out_loc, |
| 6170 | super_offset, |
| 6171 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6172 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6173 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6174 | __ CompareAndBranchIfZero(out, &done); |
| 6175 | __ cmp(out, ShifterOperand(cls)); |
| 6176 | __ b(&loop, NE); |
| 6177 | __ LoadImmediate(out, 1); |
| 6178 | if (zero.IsLinked()) { |
| 6179 | __ b(&done); |
| 6180 | } |
| 6181 | break; |
| 6182 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6183 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6185 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6186 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6187 | out_loc, |
| 6188 | obj_loc, |
| 6189 | class_offset, |
| 6190 | maybe_temp_loc, |
| 6191 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6192 | // Walk over the class hierarchy to find a match. |
| 6193 | Label loop, success; |
| 6194 | __ Bind(&loop); |
| 6195 | __ cmp(out, ShifterOperand(cls)); |
| 6196 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6197 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6198 | GenerateReferenceLoadOneRegister(instruction, |
| 6199 | out_loc, |
| 6200 | super_offset, |
| 6201 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6202 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6204 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6205 | __ b(&done); |
| 6206 | __ Bind(&success); |
| 6207 | __ LoadImmediate(out, 1); |
| 6208 | if (zero.IsLinked()) { |
| 6209 | __ b(&done); |
| 6210 | } |
| 6211 | break; |
| 6212 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6213 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6214 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6215 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6216 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6217 | out_loc, |
| 6218 | obj_loc, |
| 6219 | class_offset, |
| 6220 | maybe_temp_loc, |
| 6221 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6222 | // Do an exact check. |
| 6223 | Label exact_check; |
| 6224 | __ cmp(out, ShifterOperand(cls)); |
| 6225 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6226 | // 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] | 6227 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6228 | GenerateReferenceLoadOneRegister(instruction, |
| 6229 | out_loc, |
| 6230 | component_offset, |
| 6231 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6232 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6233 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6234 | __ CompareAndBranchIfZero(out, &done); |
| 6235 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6236 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6237 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6238 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | __ LoadImmediate(out, 1); |
| 6240 | __ b(&done); |
| 6241 | break; |
| 6242 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6243 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6244 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6245 | // No read barrier since the slow path will retry upon failure. |
| 6246 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6247 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6248 | out_loc, |
| 6249 | obj_loc, |
| 6250 | class_offset, |
| 6251 | maybe_temp_loc, |
| 6252 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6253 | __ cmp(out, ShifterOperand(cls)); |
| 6254 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6255 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6256 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6257 | codegen_->AddSlowPath(slow_path); |
| 6258 | __ b(slow_path->GetEntryLabel(), NE); |
| 6259 | __ LoadImmediate(out, 1); |
| 6260 | if (zero.IsLinked()) { |
| 6261 | __ b(&done); |
| 6262 | } |
| 6263 | break; |
| 6264 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6265 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6266 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6267 | case TypeCheckKind::kInterfaceCheck: { |
| 6268 | // 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] | 6269 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6270 | // cases. |
| 6271 | // |
| 6272 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6273 | // entry point without resorting to a type checking slow path |
| 6274 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6275 | // require to assign fixed registers for the inputs of this |
| 6276 | // HInstanceOf instruction (following the runtime calling |
| 6277 | // convention), which might be cluttered by the potential first |
| 6278 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6279 | // |
| 6280 | // TODO: Introduce a new runtime entry point taking the object |
| 6281 | // to test (instead of its class) as argument, and let it deal |
| 6282 | // with the read barrier issues. This will let us refactor this |
| 6283 | // case of the `switch` code as it was previously (with a direct |
| 6284 | // call to the runtime not using a type checking slow path). |
| 6285 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6286 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6287 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6288 | /* is_fatal */ false); |
| 6289 | codegen_->AddSlowPath(slow_path); |
| 6290 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6291 | if (zero.IsLinked()) { |
| 6292 | __ b(&done); |
| 6293 | } |
| 6294 | break; |
| 6295 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6296 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6297 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6298 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6299 | __ Bind(&zero); |
| 6300 | __ LoadImmediate(out, 0); |
| 6301 | } |
| 6302 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6303 | if (done.IsLinked()) { |
| 6304 | __ Bind(&done); |
| 6305 | } |
| 6306 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6307 | if (slow_path != nullptr) { |
| 6308 | __ Bind(slow_path->GetExitLabel()); |
| 6309 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6310 | } |
| 6311 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6312 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6313 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6314 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6315 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6316 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6317 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6318 | case TypeCheckKind::kExactCheck: |
| 6319 | case TypeCheckKind::kAbstractClassCheck: |
| 6320 | case TypeCheckKind::kClassHierarchyCheck: |
| 6321 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6322 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6323 | LocationSummary::kCallOnSlowPath : |
| 6324 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6325 | break; |
| 6326 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6327 | case TypeCheckKind::kUnresolvedCheck: |
| 6328 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6329 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6330 | break; |
| 6331 | } |
| 6332 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6333 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6335 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6336 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6337 | } |
| 6338 | |
| 6339 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6340 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6341 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6342 | Location obj_loc = locations->InAt(0); |
| 6343 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6344 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6345 | Location temp_loc = locations->GetTemp(0); |
| 6346 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6347 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6348 | DCHECK_LE(num_temps, 3u); |
| 6349 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6350 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6351 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6352 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6353 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6354 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6355 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6356 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6357 | const uint32_t object_array_data_offset = |
| 6358 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6359 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6360 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6361 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6362 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6363 | bool is_type_check_slow_path_fatal = false; |
| 6364 | if (!kEmitCompilerReadBarrier) { |
| 6365 | is_type_check_slow_path_fatal = |
| 6366 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6367 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6368 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6369 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6370 | !instruction->CanThrowIntoCatchBlock(); |
| 6371 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6372 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6373 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6374 | is_type_check_slow_path_fatal); |
| 6375 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6376 | |
| 6377 | Label done; |
| 6378 | // Avoid null check if we know obj is not null. |
| 6379 | if (instruction->MustDoNullCheck()) { |
| 6380 | __ CompareAndBranchIfZero(obj, &done); |
| 6381 | } |
| 6382 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6383 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6384 | case TypeCheckKind::kExactCheck: |
| 6385 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6386 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6387 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6388 | temp_loc, |
| 6389 | obj_loc, |
| 6390 | class_offset, |
| 6391 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6392 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6393 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6394 | __ cmp(temp, ShifterOperand(cls)); |
| 6395 | // Jump to slow path for throwing the exception or doing a |
| 6396 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6397 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6398 | break; |
| 6399 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6400 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6401 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6402 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6403 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6404 | temp_loc, |
| 6405 | obj_loc, |
| 6406 | class_offset, |
| 6407 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6408 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6409 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6410 | // If the class is abstract, we eagerly fetch the super class of the |
| 6411 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6412 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6413 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6414 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6415 | GenerateReferenceLoadOneRegister(instruction, |
| 6416 | temp_loc, |
| 6417 | super_offset, |
| 6418 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6419 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6420 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6421 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6422 | // exception. |
| 6423 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6424 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6425 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6426 | __ cmp(temp, ShifterOperand(cls)); |
| 6427 | __ b(&loop, NE); |
| 6428 | break; |
| 6429 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6430 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6432 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6433 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6434 | temp_loc, |
| 6435 | obj_loc, |
| 6436 | class_offset, |
| 6437 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6438 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6439 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6440 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6441 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6442 | __ Bind(&loop); |
| 6443 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6444 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6445 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6446 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6447 | GenerateReferenceLoadOneRegister(instruction, |
| 6448 | temp_loc, |
| 6449 | super_offset, |
| 6450 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6451 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6452 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6453 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6454 | // exception. |
| 6455 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6456 | // Otherwise, jump to the beginning of the loop. |
| 6457 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6458 | break; |
| 6459 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6460 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6461 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6462 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6463 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6464 | temp_loc, |
| 6465 | obj_loc, |
| 6466 | class_offset, |
| 6467 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6468 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6469 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6470 | // Do an exact check. |
| 6471 | __ cmp(temp, ShifterOperand(cls)); |
| 6472 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6473 | |
| 6474 | // 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] | 6475 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6476 | GenerateReferenceLoadOneRegister(instruction, |
| 6477 | temp_loc, |
| 6478 | component_offset, |
| 6479 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6480 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6481 | // If the component type is null, jump to the slow path to throw the exception. |
| 6482 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6483 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6484 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6485 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6486 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6487 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6488 | break; |
| 6489 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6490 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6491 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6492 | // 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] | 6493 | // We cannot directly call the CheckCast runtime entry point |
| 6494 | // without resorting to a type checking slow path here (i.e. by |
| 6495 | // calling InvokeRuntime directly), as it would require to |
| 6496 | // assign fixed registers for the inputs of this HInstanceOf |
| 6497 | // instruction (following the runtime calling convention), which |
| 6498 | // might be cluttered by the potential first read barrier |
| 6499 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6500 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6501 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6502 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6503 | |
| 6504 | case TypeCheckKind::kInterfaceCheck: { |
| 6505 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6506 | // positives by doing this. |
| 6507 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6508 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6509 | temp_loc, |
| 6510 | obj_loc, |
| 6511 | class_offset, |
| 6512 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6513 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6514 | |
| 6515 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6516 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6517 | temp_loc, |
| 6518 | temp_loc, |
| 6519 | iftable_offset, |
| 6520 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6521 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6522 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6523 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6524 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6525 | Label start_loop; |
| 6526 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6527 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 6528 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6529 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6530 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6531 | // Go to next interface. |
| 6532 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 6533 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 6534 | maybe_temp2_loc.AsRegister<Register>(), |
| 6535 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6536 | // Compare the classes and continue the loop if they do not match. |
| 6537 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 6538 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6539 | break; |
| 6540 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6541 | } |
| 6542 | __ Bind(&done); |
| 6543 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6544 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6547 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6548 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6549 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6550 | InvokeRuntimeCallingConvention calling_convention; |
| 6551 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6552 | } |
| 6553 | |
| 6554 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6555 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6556 | instruction, |
| 6557 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6558 | if (instruction->IsEnter()) { |
| 6559 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6560 | } else { |
| 6561 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6562 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6563 | } |
| 6564 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6565 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6566 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6567 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6568 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6569 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6570 | LocationSummary* locations = |
| 6571 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6572 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6573 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6574 | // 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] | 6575 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6576 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6577 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6578 | } |
| 6579 | |
| 6580 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6581 | HandleBitwiseOperation(instruction); |
| 6582 | } |
| 6583 | |
| 6584 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6585 | HandleBitwiseOperation(instruction); |
| 6586 | } |
| 6587 | |
| 6588 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6589 | HandleBitwiseOperation(instruction); |
| 6590 | } |
| 6591 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6592 | |
| 6593 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6594 | LocationSummary* locations = |
| 6595 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6596 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6597 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6598 | |
| 6599 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6600 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6601 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6602 | } |
| 6603 | |
| 6604 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6605 | LocationSummary* locations = instruction->GetLocations(); |
| 6606 | Location first = locations->InAt(0); |
| 6607 | Location second = locations->InAt(1); |
| 6608 | Location out = locations->Out(); |
| 6609 | |
| 6610 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6611 | Register first_reg = first.AsRegister<Register>(); |
| 6612 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6613 | Register out_reg = out.AsRegister<Register>(); |
| 6614 | |
| 6615 | switch (instruction->GetOpKind()) { |
| 6616 | case HInstruction::kAnd: |
| 6617 | __ bic(out_reg, first_reg, second_reg); |
| 6618 | break; |
| 6619 | case HInstruction::kOr: |
| 6620 | __ orn(out_reg, first_reg, second_reg); |
| 6621 | break; |
| 6622 | // There is no EON on arm. |
| 6623 | case HInstruction::kXor: |
| 6624 | default: |
| 6625 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6626 | UNREACHABLE(); |
| 6627 | } |
| 6628 | return; |
| 6629 | |
| 6630 | } else { |
| 6631 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6632 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6633 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6634 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6635 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6636 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6637 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6638 | |
| 6639 | switch (instruction->GetOpKind()) { |
| 6640 | case HInstruction::kAnd: |
| 6641 | __ bic(out_low, first_low, second_low); |
| 6642 | __ bic(out_high, first_high, second_high); |
| 6643 | break; |
| 6644 | case HInstruction::kOr: |
| 6645 | __ orn(out_low, first_low, second_low); |
| 6646 | __ orn(out_high, first_high, second_high); |
| 6647 | break; |
| 6648 | // There is no EON on arm. |
| 6649 | case HInstruction::kXor: |
| 6650 | default: |
| 6651 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6652 | UNREACHABLE(); |
| 6653 | } |
| 6654 | } |
| 6655 | } |
| 6656 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6657 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6658 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6659 | if (value == 0xffffffffu) { |
| 6660 | if (out != first) { |
| 6661 | __ mov(out, ShifterOperand(first)); |
| 6662 | } |
| 6663 | return; |
| 6664 | } |
| 6665 | if (value == 0u) { |
| 6666 | __ mov(out, ShifterOperand(0)); |
| 6667 | return; |
| 6668 | } |
| 6669 | ShifterOperand so; |
| 6670 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6671 | __ and_(out, first, so); |
| 6672 | } else { |
| 6673 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6674 | __ bic(out, first, ShifterOperand(~value)); |
| 6675 | } |
| 6676 | } |
| 6677 | |
| 6678 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6679 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6680 | if (value == 0u) { |
| 6681 | if (out != first) { |
| 6682 | __ mov(out, ShifterOperand(first)); |
| 6683 | } |
| 6684 | return; |
| 6685 | } |
| 6686 | if (value == 0xffffffffu) { |
| 6687 | __ mvn(out, ShifterOperand(0)); |
| 6688 | return; |
| 6689 | } |
| 6690 | ShifterOperand so; |
| 6691 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6692 | __ orr(out, first, so); |
| 6693 | } else { |
| 6694 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6695 | __ orn(out, first, ShifterOperand(~value)); |
| 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6700 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6701 | if (value == 0u) { |
| 6702 | if (out != first) { |
| 6703 | __ mov(out, ShifterOperand(first)); |
| 6704 | } |
| 6705 | return; |
| 6706 | } |
| 6707 | __ eor(out, first, ShifterOperand(value)); |
| 6708 | } |
| 6709 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6710 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6711 | Location first, |
| 6712 | uint64_t value) { |
| 6713 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6714 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6715 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6716 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6717 | uint32_t value_low = Low32Bits(value); |
| 6718 | uint32_t value_high = High32Bits(value); |
| 6719 | if (value_low == 0u) { |
| 6720 | if (out_low != first_low) { |
| 6721 | __ mov(out_low, ShifterOperand(first_low)); |
| 6722 | } |
| 6723 | __ AddConstant(out_high, first_high, value_high); |
| 6724 | return; |
| 6725 | } |
| 6726 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6727 | ShifterOperand so; |
| 6728 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6729 | __ adc(out_high, first_high, so); |
| 6730 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6731 | __ sbc(out_high, first_high, so); |
| 6732 | } else { |
| 6733 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6734 | UNREACHABLE(); |
| 6735 | } |
| 6736 | } |
| 6737 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6738 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6739 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6740 | Location first = locations->InAt(0); |
| 6741 | Location second = locations->InAt(1); |
| 6742 | Location out = locations->Out(); |
| 6743 | |
| 6744 | if (second.IsConstant()) { |
| 6745 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6746 | uint32_t value_low = Low32Bits(value); |
| 6747 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6748 | Register first_reg = first.AsRegister<Register>(); |
| 6749 | Register out_reg = out.AsRegister<Register>(); |
| 6750 | if (instruction->IsAnd()) { |
| 6751 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6752 | } else if (instruction->IsOr()) { |
| 6753 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6754 | } else { |
| 6755 | DCHECK(instruction->IsXor()); |
| 6756 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6757 | } |
| 6758 | } else { |
| 6759 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6760 | uint32_t value_high = High32Bits(value); |
| 6761 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6762 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6763 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6764 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6765 | if (instruction->IsAnd()) { |
| 6766 | GenerateAndConst(out_low, first_low, value_low); |
| 6767 | GenerateAndConst(out_high, first_high, value_high); |
| 6768 | } else if (instruction->IsOr()) { |
| 6769 | GenerateOrrConst(out_low, first_low, value_low); |
| 6770 | GenerateOrrConst(out_high, first_high, value_high); |
| 6771 | } else { |
| 6772 | DCHECK(instruction->IsXor()); |
| 6773 | GenerateEorConst(out_low, first_low, value_low); |
| 6774 | GenerateEorConst(out_high, first_high, value_high); |
| 6775 | } |
| 6776 | } |
| 6777 | return; |
| 6778 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6779 | |
| 6780 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6781 | Register first_reg = first.AsRegister<Register>(); |
| 6782 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6783 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6784 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6785 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6786 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6787 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6788 | } else { |
| 6789 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6790 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6791 | } |
| 6792 | } else { |
| 6793 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6794 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6795 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6796 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6797 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6798 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6799 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6800 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6801 | __ and_(out_low, first_low, second_low); |
| 6802 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6803 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6804 | __ orr(out_low, first_low, second_low); |
| 6805 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6806 | } else { |
| 6807 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6808 | __ eor(out_low, first_low, second_low); |
| 6809 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6810 | } |
| 6811 | } |
| 6812 | } |
| 6813 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6814 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 6815 | HInstruction* instruction, |
| 6816 | Location out, |
| 6817 | uint32_t offset, |
| 6818 | Location maybe_temp, |
| 6819 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6820 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6821 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6822 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6823 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6824 | if (kUseBakerReadBarrier) { |
| 6825 | // Load with fast path based Baker's read barrier. |
| 6826 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6827 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6828 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6829 | } else { |
| 6830 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6831 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6832 | // in the following move operation, as we will need it for the |
| 6833 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6834 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6835 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6836 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6837 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6838 | } |
| 6839 | } else { |
| 6840 | // Plain load with no read barrier. |
| 6841 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6842 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6843 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6844 | } |
| 6845 | } |
| 6846 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6847 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 6848 | HInstruction* instruction, |
| 6849 | Location out, |
| 6850 | Location obj, |
| 6851 | uint32_t offset, |
| 6852 | Location maybe_temp, |
| 6853 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6854 | Register out_reg = out.AsRegister<Register>(); |
| 6855 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6856 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6857 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6858 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6859 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6860 | // Load with fast path based Baker's read barrier. |
| 6861 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6862 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6863 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6864 | } else { |
| 6865 | // Load with slow path based read barrier. |
| 6866 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6867 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6868 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6869 | } |
| 6870 | } else { |
| 6871 | // Plain load with no read barrier. |
| 6872 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6873 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6874 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6879 | Location root, |
| 6880 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6881 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6882 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6883 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6884 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6885 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6886 | if (kUseBakerReadBarrier) { |
| 6887 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6888 | // Baker's read barrier are used: |
| 6889 | // |
| 6890 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6891 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6892 | // if (temp != null) { |
| 6893 | // root = temp(root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6894 | // } |
| 6895 | |
| 6896 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6897 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6898 | static_assert( |
| 6899 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6900 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6901 | "have different sizes."); |
| 6902 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6903 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6904 | "have different sizes."); |
| 6905 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6906 | // Slow path marking the GC root `root`. |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6907 | Location temp = Location::RegisterLocation(LR); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6908 | SlowPathCodeARM* slow_path = |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6909 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 6910 | instruction, |
| 6911 | root, |
| 6912 | /*entrypoint*/ temp); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6913 | codegen_->AddSlowPath(slow_path); |
| 6914 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6915 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6916 | const int32_t entry_point_offset = |
| 6917 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 6918 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6919 | // threads are suspended or running a checkpoint. |
| 6920 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6921 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6922 | // checking GetIsGcMarking. |
| 6923 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6924 | __ Bind(slow_path->GetExitLabel()); |
| 6925 | } else { |
| 6926 | // GC root loaded through a slow path for read barriers other |
| 6927 | // than Baker's. |
| 6928 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6929 | __ AddConstant(root_reg, obj, offset); |
| 6930 | // /* mirror::Object* */ root = root->Read() |
| 6931 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6932 | } |
| 6933 | } else { |
| 6934 | // Plain GC root load with no read barrier. |
| 6935 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6936 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6937 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6938 | // do not have to unpoison `root_reg` here. |
| 6939 | } |
| 6940 | } |
| 6941 | |
| 6942 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6943 | Location ref, |
| 6944 | Register obj, |
| 6945 | uint32_t offset, |
| 6946 | Location temp, |
| 6947 | bool needs_null_check) { |
| 6948 | DCHECK(kEmitCompilerReadBarrier); |
| 6949 | DCHECK(kUseBakerReadBarrier); |
| 6950 | |
| 6951 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6952 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6953 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6954 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6955 | 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] | 6956 | } |
| 6957 | |
| 6958 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6959 | Location ref, |
| 6960 | Register obj, |
| 6961 | uint32_t data_offset, |
| 6962 | Location index, |
| 6963 | Location temp, |
| 6964 | bool needs_null_check) { |
| 6965 | DCHECK(kEmitCompilerReadBarrier); |
| 6966 | DCHECK(kUseBakerReadBarrier); |
| 6967 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6968 | static_assert( |
| 6969 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6970 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6971 | // /* HeapReference<Object> */ ref = |
| 6972 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6973 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6974 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6975 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6976 | } |
| 6977 | |
| 6978 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6979 | Location ref, |
| 6980 | Register obj, |
| 6981 | uint32_t offset, |
| 6982 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6983 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6984 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6985 | bool needs_null_check, |
| 6986 | bool always_update_field, |
| 6987 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6988 | DCHECK(kEmitCompilerReadBarrier); |
| 6989 | DCHECK(kUseBakerReadBarrier); |
| 6990 | |
| 6991 | // In slow path based read barriers, the read barrier call is |
| 6992 | // inserted after the original load. However, in fast path based |
| 6993 | // Baker's read barriers, we need to perform the load of |
| 6994 | // mirror::Object::monitor_ *before* the original reference load. |
| 6995 | // This load-load ordering is required by the read barrier. |
| 6996 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6997 | // |
| 6998 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6999 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7000 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7001 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7002 | // if (is_gray) { |
| 7003 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7004 | // } |
| 7005 | // |
| 7006 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7007 | // slightly more complex as it performs additional checks that we do |
| 7008 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7009 | |
| 7010 | Register ref_reg = ref.AsRegister<Register>(); |
| 7011 | Register temp_reg = temp.AsRegister<Register>(); |
| 7012 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7013 | |
| 7014 | // /* int32_t */ monitor = obj->monitor_ |
| 7015 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7016 | if (needs_null_check) { |
| 7017 | MaybeRecordImplicitNullCheck(instruction); |
| 7018 | } |
| 7019 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7020 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7021 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7022 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7023 | // Introduce a dependency on the lock_word including the rb_state, |
| 7024 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7025 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 7026 | // `obj` is unchanged by this operation, but its value now depends |
| 7027 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7028 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7029 | |
| 7030 | // The actual reference load. |
| 7031 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7032 | // Load types involving an "index": ArrayGet, |
| 7033 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7034 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7035 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7036 | if (index.IsConstant()) { |
| 7037 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7038 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7039 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7040 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7041 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7042 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7043 | // intrinsics, which use a register pair as index ("long |
| 7044 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7045 | Register index_reg = index.IsRegisterPair() |
| 7046 | ? index.AsRegisterPairLow<Register>() |
| 7047 | : index.AsRegister<Register>(); |
| 7048 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7049 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7050 | } |
| 7051 | } else { |
| 7052 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7053 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7054 | } |
| 7055 | |
| 7056 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7057 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7058 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7059 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7060 | SlowPathCodeARM* slow_path; |
| 7061 | if (always_update_field) { |
| 7062 | DCHECK(temp2 != nullptr); |
| 7063 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 7064 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7065 | // `field_offset` is a register pair (of which only the lower half |
| 7066 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7067 | // to be null in this code path. |
| 7068 | DCHECK_EQ(offset, 0u); |
| 7069 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7070 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 7071 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7072 | } else { |
| 7073 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 7074 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7075 | AddSlowPath(slow_path); |
| 7076 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7077 | // if (rb_state == ReadBarrier::GrayState()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7078 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7079 | // Given the numeric representation, it's enough to check the low bit of the |
| 7080 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7081 | // which can be a 16-bit instruction unlike the TST immediate. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7082 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7083 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7084 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7085 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7086 | __ Bind(slow_path->GetExitLabel()); |
| 7087 | } |
| 7088 | |
| 7089 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7090 | Location out, |
| 7091 | Location ref, |
| 7092 | Location obj, |
| 7093 | uint32_t offset, |
| 7094 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7095 | DCHECK(kEmitCompilerReadBarrier); |
| 7096 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7097 | // Insert a slow path based read barrier *after* the reference load. |
| 7098 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7099 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7100 | // reference will be carried out by the runtime within the slow |
| 7101 | // path. |
| 7102 | // |
| 7103 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7104 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7105 | // not used by the artReadBarrierSlow entry point. |
| 7106 | // |
| 7107 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7108 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7109 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7110 | AddSlowPath(slow_path); |
| 7111 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7112 | __ b(slow_path->GetEntryLabel()); |
| 7113 | __ Bind(slow_path->GetExitLabel()); |
| 7114 | } |
| 7115 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7116 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7117 | Location out, |
| 7118 | Location ref, |
| 7119 | Location obj, |
| 7120 | uint32_t offset, |
| 7121 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7122 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7123 | // Baker's read barriers shall be handled by the fast path |
| 7124 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7125 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7126 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7127 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7128 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7129 | } else if (kPoisonHeapReferences) { |
| 7130 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7131 | } |
| 7132 | } |
| 7133 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7134 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7135 | Location out, |
| 7136 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7137 | DCHECK(kEmitCompilerReadBarrier); |
| 7138 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7139 | // Insert a slow path based read barrier *after* the GC root load. |
| 7140 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7141 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7142 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7143 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7144 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7145 | AddSlowPath(slow_path); |
| 7146 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7147 | __ b(slow_path->GetEntryLabel()); |
| 7148 | __ Bind(slow_path->GetExitLabel()); |
| 7149 | } |
| 7150 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7151 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7152 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7153 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame^] | 7154 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7155 | } |
| 7156 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7157 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7158 | Register temp) { |
| 7159 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7160 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7161 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7162 | return location.AsRegister<Register>(); |
| 7163 | } |
| 7164 | // For intrinsics we allow any location, so it may be on the stack. |
| 7165 | if (!location.IsRegister()) { |
| 7166 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7167 | return temp; |
| 7168 | } |
| 7169 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7170 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7171 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7172 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7173 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7174 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7175 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7176 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7177 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7178 | return temp; |
| 7179 | } |
| 7180 | return location.AsRegister<Register>(); |
| 7181 | } |
| 7182 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 7183 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7184 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7185 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7186 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7187 | uint32_t offset = |
| 7188 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7189 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7190 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7191 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7192 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7193 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7194 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7195 | break; |
| 7196 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7197 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7198 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7199 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7200 | HArmDexCacheArraysBase* base = |
| 7201 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7202 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7203 | temp.AsRegister<Register>()); |
| 7204 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7205 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7206 | break; |
| 7207 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7208 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7209 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7210 | Register method_reg; |
| 7211 | Register reg = temp.AsRegister<Register>(); |
| 7212 | if (current_method.IsRegister()) { |
| 7213 | method_reg = current_method.AsRegister<Register>(); |
| 7214 | } else { |
| 7215 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7216 | DCHECK(!current_method.IsValid()); |
| 7217 | method_reg = reg; |
| 7218 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7219 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7220 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7221 | __ LoadFromOffset(kLoadWord, |
| 7222 | reg, |
| 7223 | method_reg, |
| 7224 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7225 | // temp = temp[index_in_cache]; |
| 7226 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7227 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7228 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7229 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7230 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7231 | } |
| 7232 | |
| 7233 | switch (invoke->GetCodePtrLocation()) { |
| 7234 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7235 | __ bl(GetFrameEntryLabel()); |
| 7236 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7237 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7238 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7239 | __ LoadFromOffset( |
| 7240 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7241 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7242 | // LR() |
| 7243 | __ blx(LR); |
| 7244 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7245 | } |
| 7246 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7247 | DCHECK(!IsLeafMethod()); |
| 7248 | } |
| 7249 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7250 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7251 | Register temp = temp_location.AsRegister<Register>(); |
| 7252 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7253 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7254 | |
| 7255 | // Use the calling convention instead of the location of the receiver, as |
| 7256 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7257 | // slow path, the arguments have been moved to the right place, so here we are |
| 7258 | // guaranteed that the receiver is the first register of the calling convention. |
| 7259 | InvokeDexCallingConvention calling_convention; |
| 7260 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7261 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7262 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7263 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7264 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7265 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7266 | // emit a read barrier for the previous class reference load. |
| 7267 | // However this is not required in practice, as this is an |
| 7268 | // intermediate/temporary reference and because the current |
| 7269 | // concurrent copying collector keeps the from-space memory |
| 7270 | // intact/accessible until the end of the marking phase (the |
| 7271 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7272 | __ MaybeUnpoisonHeapReference(temp); |
| 7273 | // temp = temp->GetMethodAt(method_offset); |
| 7274 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7275 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7276 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7277 | // LR = temp->GetEntryPoint(); |
| 7278 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7279 | // LR(); |
| 7280 | __ blx(LR); |
| 7281 | } |
| 7282 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7283 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7284 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7285 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7288 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7289 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7290 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7291 | } |
| 7292 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7293 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 7294 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7295 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7296 | } |
| 7297 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7298 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7299 | const DexFile& dex_file, uint32_t element_offset) { |
| 7300 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7301 | } |
| 7302 | |
| 7303 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7304 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7305 | patches->emplace_back(dex_file, offset_or_index); |
| 7306 | return &patches->back(); |
| 7307 | } |
| 7308 | |
| 7309 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7310 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7311 | return boot_image_string_patches_.GetOrCreate( |
| 7312 | StringReference(&dex_file, string_index), |
| 7313 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7314 | } |
| 7315 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7316 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7317 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7318 | return boot_image_type_patches_.GetOrCreate( |
| 7319 | TypeReference(&dex_file, type_index), |
| 7320 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7321 | } |
| 7322 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7323 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7324 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7325 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7326 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7327 | } |
| 7328 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7329 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7330 | dex::StringIndex string_index, |
| 7331 | Handle<mirror::String> handle) { |
| 7332 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7333 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7334 | return jit_string_patches_.GetOrCreate( |
| 7335 | StringReference(&dex_file, string_index), |
| 7336 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7337 | } |
| 7338 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7339 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7340 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7341 | Handle<mirror::Class> handle) { |
| 7342 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 7343 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7344 | return jit_class_patches_.GetOrCreate( |
| 7345 | TypeReference(&dex_file, type_index), |
| 7346 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7347 | } |
| 7348 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7349 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7350 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7351 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7352 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7353 | for (const PcRelativePatchInfo& info : infos) { |
| 7354 | const DexFile& dex_file = info.target_dex_file; |
| 7355 | size_t offset_or_index = info.offset_or_index; |
| 7356 | DCHECK(info.add_pc_label.IsBound()); |
| 7357 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7358 | // Add MOVW patch. |
| 7359 | DCHECK(info.movw_label.IsBound()); |
| 7360 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7361 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7362 | // Add MOVT patch. |
| 7363 | DCHECK(info.movt_label.IsBound()); |
| 7364 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7365 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7366 | } |
| 7367 | } |
| 7368 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7369 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7370 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7371 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7372 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7373 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7374 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7375 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7376 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7377 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7378 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7379 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7380 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7381 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7382 | for (const auto& entry : boot_image_string_patches_) { |
| 7383 | const StringReference& target_string = entry.first; |
| 7384 | Literal* literal = entry.second; |
| 7385 | DCHECK(literal->GetLabel()->IsBound()); |
| 7386 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7387 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7388 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7389 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7390 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7391 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7392 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7393 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7394 | linker_patches); |
| 7395 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7396 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7397 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7398 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7399 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7400 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7401 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7402 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7403 | for (const auto& entry : boot_image_type_patches_) { |
| 7404 | const TypeReference& target_type = entry.first; |
| 7405 | Literal* literal = entry.second; |
| 7406 | DCHECK(literal->GetLabel()->IsBound()); |
| 7407 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7408 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7409 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7410 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7411 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7412 | for (const auto& entry : boot_image_address_patches_) { |
| 7413 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7414 | Literal* literal = entry.second; |
| 7415 | DCHECK(literal->GetLabel()->IsBound()); |
| 7416 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7417 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7418 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7419 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
| 7422 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7423 | return map->GetOrCreate( |
| 7424 | value, |
| 7425 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7426 | } |
| 7427 | |
| 7428 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7429 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7430 | return map->GetOrCreate( |
| 7431 | target_method, |
| 7432 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7433 | } |
| 7434 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7435 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7436 | LocationSummary* locations = |
| 7437 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7438 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7439 | Location::RequiresRegister()); |
| 7440 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7441 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7442 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7443 | } |
| 7444 | |
| 7445 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7446 | LocationSummary* locations = instr->GetLocations(); |
| 7447 | Register res = locations->Out().AsRegister<Register>(); |
| 7448 | Register accumulator = |
| 7449 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7450 | Register mul_left = |
| 7451 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7452 | Register mul_right = |
| 7453 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7454 | |
| 7455 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7456 | __ mla(res, mul_left, mul_right, accumulator); |
| 7457 | } else { |
| 7458 | __ mls(res, mul_left, mul_right, accumulator); |
| 7459 | } |
| 7460 | } |
| 7461 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7462 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7463 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7464 | LOG(FATAL) << "Unreachable"; |
| 7465 | } |
| 7466 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7467 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7468 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7469 | LOG(FATAL) << "Unreachable"; |
| 7470 | } |
| 7471 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7472 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7473 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7474 | LocationSummary* locations = |
| 7475 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7476 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7477 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7478 | codegen_->GetAssembler()->IsThumb()) { |
| 7479 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7480 | if (switch_instr->GetStartValue() != 0) { |
| 7481 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7482 | } |
| 7483 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7487 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7488 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7489 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7490 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7491 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7492 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7493 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7494 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7495 | Register temp_reg = IP; |
| 7496 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7497 | // the immediate, because IP is used as the destination register. For the other |
| 7498 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7499 | // and they can be encoded in the instruction without making use of IP register. |
| 7500 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7501 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7502 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7503 | // Jump to successors[0] if value == lower_bound. |
| 7504 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7505 | int32_t last_index = 0; |
| 7506 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7507 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7508 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7509 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7510 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7511 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7512 | } |
| 7513 | if (num_entries - last_index == 2) { |
| 7514 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7515 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7516 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7517 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7518 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7519 | // And the default for any other value. |
| 7520 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7521 | __ b(codegen_->GetLabelOf(default_block)); |
| 7522 | } |
| 7523 | } else { |
| 7524 | // Create a table lookup. |
| 7525 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7526 | |
| 7527 | // Materialize a pointer to the switch table |
| 7528 | std::vector<Label*> labels(num_entries); |
| 7529 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7530 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7531 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7532 | } |
| 7533 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7534 | |
| 7535 | // Remove the bias. |
| 7536 | Register key_reg; |
| 7537 | if (lower_bound != 0) { |
| 7538 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7539 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7540 | } else { |
| 7541 | key_reg = value_reg; |
| 7542 | } |
| 7543 | |
| 7544 | // Check whether the value is in the table, jump to default block if not. |
| 7545 | __ CmpConstant(key_reg, num_entries - 1); |
| 7546 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7547 | |
| 7548 | // Load the displacement from the table. |
| 7549 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7550 | |
| 7551 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7552 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7553 | } |
| 7554 | } |
| 7555 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7556 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7557 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7558 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7559 | } |
| 7560 | |
| 7561 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7562 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7563 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7564 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7565 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7566 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7567 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7568 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7569 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7570 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7571 | } |
| 7572 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7573 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7574 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7575 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7576 | return; |
| 7577 | } |
| 7578 | |
| 7579 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7580 | |
| 7581 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7582 | if (return_loc.Equals(trg)) { |
| 7583 | return; |
| 7584 | } |
| 7585 | |
| 7586 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7587 | // with the last branch. |
| 7588 | if (type == Primitive::kPrimLong) { |
| 7589 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7590 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7591 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7592 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7593 | } else if (type == Primitive::kPrimDouble) { |
| 7594 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7595 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7596 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7597 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7598 | } else { |
| 7599 | // Let the parallel move resolver take care of all of this. |
| 7600 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7601 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7602 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7603 | } |
| 7604 | } |
| 7605 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7606 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7607 | LocationSummary* locations = |
| 7608 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7610 | locations->SetOut(Location::RequiresRegister()); |
| 7611 | } |
| 7612 | |
| 7613 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7614 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7615 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7616 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7617 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7618 | __ LoadFromOffset(kLoadWord, |
| 7619 | locations->Out().AsRegister<Register>(), |
| 7620 | locations->InAt(0).AsRegister<Register>(), |
| 7621 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7622 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7623 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7624 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7625 | __ LoadFromOffset(kLoadWord, |
| 7626 | locations->Out().AsRegister<Register>(), |
| 7627 | locations->InAt(0).AsRegister<Register>(), |
| 7628 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7629 | __ LoadFromOffset(kLoadWord, |
| 7630 | locations->Out().AsRegister<Register>(), |
| 7631 | locations->Out().AsRegister<Register>(), |
| 7632 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7633 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7634 | } |
| 7635 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7636 | static void PatchJitRootUse(uint8_t* code, |
| 7637 | const uint8_t* roots_data, |
| 7638 | Literal* literal, |
| 7639 | uint64_t index_in_table) { |
| 7640 | DCHECK(literal->GetLabel()->IsBound()); |
| 7641 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7642 | uintptr_t address = |
| 7643 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7644 | uint8_t* data = code + literal_offset; |
| 7645 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 7646 | } |
| 7647 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7648 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7649 | for (const auto& entry : jit_string_patches_) { |
| 7650 | const auto& it = jit_string_roots_.find(entry.first); |
| 7651 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7652 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 7653 | } |
| 7654 | for (const auto& entry : jit_class_patches_) { |
| 7655 | const auto& it = jit_class_roots_.find(entry.first); |
| 7656 | DCHECK(it != jit_class_roots_.end()); |
| 7657 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7658 | } |
| 7659 | } |
| 7660 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7661 | #undef __ |
| 7662 | #undef QUICK_ENTRY_POINT |
| 7663 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7664 | } // namespace arm |
| 7665 | } // namespace art |