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) { |
| 1242 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 1243 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1244 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1245 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1246 | // Adjust pc offsets for the disassembly information. |
| 1247 | if (disasm_info_ != nullptr) { |
| 1248 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1249 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1250 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1251 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1252 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1253 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1254 | } |
| 1255 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1256 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1257 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1258 | } |
| 1259 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1260 | |
| 1261 | CodeGenerator::Finalize(allocator); |
| 1262 | } |
| 1263 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1264 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1265 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1266 | blocked_core_registers_[SP] = true; |
| 1267 | blocked_core_registers_[LR] = true; |
| 1268 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1269 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1270 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1271 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1272 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1273 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1274 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1275 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1276 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1277 | // Stubs do not save callee-save floating point registers. If the graph |
| 1278 | // is debuggable, we need to deal with these registers differently. For |
| 1279 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1280 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1281 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1282 | } |
| 1283 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1286 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1287 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1288 | assembler_(codegen->GetAssembler()), |
| 1289 | codegen_(codegen) {} |
| 1290 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1291 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1292 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1293 | 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] | 1294 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1295 | // restore another arbitrary register. |
| 1296 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1297 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1298 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1299 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1300 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1301 | // but in the range. |
| 1302 | if (fpu_spill_mask_ != 0) { |
| 1303 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1304 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1305 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1306 | fpu_spill_mask_ |= (1 << i); |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1311 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1312 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1316 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1317 | } |
| 1318 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1319 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1320 | bool skip_overflow_check = |
| 1321 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1322 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1323 | __ Bind(&frame_entry_label_); |
| 1324 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1325 | if (HasEmptyFrame()) { |
| 1326 | return; |
| 1327 | } |
| 1328 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1329 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1330 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1331 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1332 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1335 | __ PushList(core_spill_mask_); |
| 1336 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1337 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1338 | if (fpu_spill_mask_ != 0) { |
| 1339 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1340 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1341 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1342 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1343 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1344 | |
| 1345 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1346 | // Initialize should_deoptimize flag to 0. |
| 1347 | __ mov(IP, ShifterOperand(0)); |
| 1348 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1349 | } |
| 1350 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1351 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1352 | __ AddConstant(SP, -adjust); |
| 1353 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1354 | |
| 1355 | // Save the current method if we need it. Note that we do not |
| 1356 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1357 | // in the SSA graph. |
| 1358 | if (RequiresCurrentMethod()) { |
| 1359 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1360 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1364 | if (HasEmptyFrame()) { |
| 1365 | __ bx(LR); |
| 1366 | return; |
| 1367 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1368 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1369 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1370 | __ AddConstant(SP, adjust); |
| 1371 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1372 | if (fpu_spill_mask_ != 0) { |
| 1373 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1374 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1375 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1376 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1377 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1378 | // Pop LR into PC to return. |
| 1379 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1380 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1381 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1382 | __ cfi().RestoreState(); |
| 1383 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1386 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1387 | Label* label = GetLabelOf(block); |
| 1388 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1391 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1392 | switch (type) { |
| 1393 | case Primitive::kPrimBoolean: |
| 1394 | case Primitive::kPrimByte: |
| 1395 | case Primitive::kPrimChar: |
| 1396 | case Primitive::kPrimShort: |
| 1397 | case Primitive::kPrimInt: |
| 1398 | case Primitive::kPrimNot: { |
| 1399 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1400 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1401 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1402 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1403 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1404 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1405 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1406 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1407 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1408 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1409 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1410 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1411 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1412 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1413 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1414 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1415 | // Skip R1, and use R2_R3 instead. |
| 1416 | gp_index_++; |
| 1417 | index++; |
| 1418 | } |
| 1419 | } |
| 1420 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1421 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1422 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1423 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1424 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1425 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1426 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1427 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | case Primitive::kPrimFloat: { |
| 1432 | uint32_t stack_index = stack_index_++; |
| 1433 | if (float_index_ % 2 == 0) { |
| 1434 | float_index_ = std::max(double_index_, float_index_); |
| 1435 | } |
| 1436 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1437 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1438 | } else { |
| 1439 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | case Primitive::kPrimDouble: { |
| 1444 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1445 | uint32_t stack_index = stack_index_; |
| 1446 | stack_index_ += 2; |
| 1447 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1448 | uint32_t index = double_index_; |
| 1449 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1450 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1451 | calling_convention.GetFpuRegisterAt(index), |
| 1452 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1453 | DCHECK(ExpectedPairLayout(result)); |
| 1454 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1455 | } else { |
| 1456 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1460 | case Primitive::kPrimVoid: |
| 1461 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1462 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1463 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1464 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1465 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1466 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1467 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1468 | switch (type) { |
| 1469 | case Primitive::kPrimBoolean: |
| 1470 | case Primitive::kPrimByte: |
| 1471 | case Primitive::kPrimChar: |
| 1472 | case Primitive::kPrimShort: |
| 1473 | case Primitive::kPrimInt: |
| 1474 | case Primitive::kPrimNot: { |
| 1475 | return Location::RegisterLocation(R0); |
| 1476 | } |
| 1477 | |
| 1478 | case Primitive::kPrimFloat: { |
| 1479 | return Location::FpuRegisterLocation(S0); |
| 1480 | } |
| 1481 | |
| 1482 | case Primitive::kPrimLong: { |
| 1483 | return Location::RegisterPairLocation(R0, R1); |
| 1484 | } |
| 1485 | |
| 1486 | case Primitive::kPrimDouble: { |
| 1487 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1488 | } |
| 1489 | |
| 1490 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1491 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1492 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1493 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1494 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1497 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1498 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1499 | } |
| 1500 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1501 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1502 | if (source.Equals(destination)) { |
| 1503 | return; |
| 1504 | } |
| 1505 | if (destination.IsRegister()) { |
| 1506 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1507 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1508 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1509 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1510 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1511 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1512 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1513 | } else if (destination.IsFpuRegister()) { |
| 1514 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1515 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1516 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1517 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1518 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1519 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1520 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1521 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1522 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1523 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1524 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1525 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1526 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1527 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1528 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1529 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1530 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1536 | if (source.Equals(destination)) { |
| 1537 | return; |
| 1538 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1539 | if (destination.IsRegisterPair()) { |
| 1540 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1541 | EmitParallelMoves( |
| 1542 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1543 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1544 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1545 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1546 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1547 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1548 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1549 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1550 | } else if (source.IsFpuRegisterPair()) { |
| 1551 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1552 | destination.AsRegisterPairHigh<Register>(), |
| 1553 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1554 | } else { |
| 1555 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1556 | DCHECK(ExpectedPairLayout(destination)); |
| 1557 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1558 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1559 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1560 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1561 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1562 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1563 | SP, |
| 1564 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1565 | } else if (source.IsRegisterPair()) { |
| 1566 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1567 | source.AsRegisterPairLow<Register>(), |
| 1568 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1569 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1570 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1571 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1572 | } else { |
| 1573 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1574 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1575 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1576 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1577 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1578 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1579 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1580 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1581 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1582 | SP, destination.GetStackIndex()); |
| 1583 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1584 | } else if (source.IsFpuRegisterPair()) { |
| 1585 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1586 | SP, |
| 1587 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1588 | } else { |
| 1589 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1590 | EmitParallelMoves( |
| 1591 | Location::StackSlot(source.GetStackIndex()), |
| 1592 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1593 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1594 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1595 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1596 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1601 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1602 | DCHECK(location.IsRegister()); |
| 1603 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1604 | } |
| 1605 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1606 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1607 | HParallelMove move(GetGraph()->GetArena()); |
| 1608 | move.AddMove(src, dst, dst_type, nullptr); |
| 1609 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1613 | if (location.IsRegister()) { |
| 1614 | locations->AddTemp(location); |
| 1615 | } else if (location.IsRegisterPair()) { |
| 1616 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1617 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1618 | } else { |
| 1619 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1620 | } |
| 1621 | } |
| 1622 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1623 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1624 | HInstruction* instruction, |
| 1625 | uint32_t dex_pc, |
| 1626 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1627 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1628 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1629 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1630 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1631 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1632 | } |
| 1633 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1634 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1635 | HInstruction* instruction, |
| 1636 | SlowPathCode* slow_path) { |
| 1637 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1638 | GenerateInvokeRuntime(entry_point_offset); |
| 1639 | } |
| 1640 | |
| 1641 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1642 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1643 | __ blx(LR); |
| 1644 | } |
| 1645 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1646 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1647 | DCHECK(!successor->IsExitBlock()); |
| 1648 | |
| 1649 | HBasicBlock* block = got->GetBlock(); |
| 1650 | HInstruction* previous = got->GetPrevious(); |
| 1651 | |
| 1652 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1653 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1654 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1655 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1656 | return; |
| 1657 | } |
| 1658 | |
| 1659 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1660 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1661 | } |
| 1662 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1663 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1664 | } |
| 1665 | } |
| 1666 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1667 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1668 | got->SetLocations(nullptr); |
| 1669 | } |
| 1670 | |
| 1671 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1672 | HandleGoto(got, got->GetSuccessor()); |
| 1673 | } |
| 1674 | |
| 1675 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1676 | try_boundary->SetLocations(nullptr); |
| 1677 | } |
| 1678 | |
| 1679 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1680 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1681 | if (!successor->IsExitBlock()) { |
| 1682 | HandleGoto(try_boundary, successor); |
| 1683 | } |
| 1684 | } |
| 1685 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1686 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1687 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1690 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1693 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1694 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1695 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1696 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1697 | if (rhs_loc.IsConstant()) { |
| 1698 | // 0.0 is the only immediate that can be encoded directly in |
| 1699 | // a VCMP instruction. |
| 1700 | // |
| 1701 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1702 | // specify that in a floating-point comparison, positive zero |
| 1703 | // and negative zero are considered equal, so we can use the |
| 1704 | // literal 0.0 for both cases here. |
| 1705 | // |
| 1706 | // Note however that some methods (Float.equal, Float.compare, |
| 1707 | // Float.compareTo, Double.equal, Double.compare, |
| 1708 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1709 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1710 | // -0.0. So if we ever translate calls to these methods into a |
| 1711 | // HCompare instruction, we must handle the -0.0 case with |
| 1712 | // care here. |
| 1713 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1714 | if (type == Primitive::kPrimFloat) { |
| 1715 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1716 | } else { |
| 1717 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1718 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1719 | } |
| 1720 | } else { |
| 1721 | if (type == Primitive::kPrimFloat) { |
| 1722 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1723 | } else { |
| 1724 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1725 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1726 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1731 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1732 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1733 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1734 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1735 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1739 | Label* true_label, |
| 1740 | Label* false_label) { |
| 1741 | LocationSummary* locations = cond->GetLocations(); |
| 1742 | Location left = locations->InAt(0); |
| 1743 | Location right = locations->InAt(1); |
| 1744 | IfCondition if_cond = cond->GetCondition(); |
| 1745 | |
| 1746 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1747 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1748 | IfCondition true_high_cond = if_cond; |
| 1749 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1750 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1751 | |
| 1752 | // Set the conditions for the test, remembering that == needs to be |
| 1753 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1754 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1755 | switch (if_cond) { |
| 1756 | case kCondEQ: |
| 1757 | case kCondNE: |
| 1758 | // Nothing to do. |
| 1759 | break; |
| 1760 | case kCondLT: |
| 1761 | false_high_cond = kCondGT; |
| 1762 | break; |
| 1763 | case kCondLE: |
| 1764 | true_high_cond = kCondLT; |
| 1765 | break; |
| 1766 | case kCondGT: |
| 1767 | false_high_cond = kCondLT; |
| 1768 | break; |
| 1769 | case kCondGE: |
| 1770 | true_high_cond = kCondGT; |
| 1771 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1772 | case kCondB: |
| 1773 | false_high_cond = kCondA; |
| 1774 | break; |
| 1775 | case kCondBE: |
| 1776 | true_high_cond = kCondB; |
| 1777 | break; |
| 1778 | case kCondA: |
| 1779 | false_high_cond = kCondB; |
| 1780 | break; |
| 1781 | case kCondAE: |
| 1782 | true_high_cond = kCondA; |
| 1783 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1784 | } |
| 1785 | if (right.IsConstant()) { |
| 1786 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1787 | int32_t val_low = Low32Bits(value); |
| 1788 | int32_t val_high = High32Bits(value); |
| 1789 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1790 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1791 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1792 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1793 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1794 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1795 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1796 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1797 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1798 | } |
| 1799 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1800 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1801 | } else { |
| 1802 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1803 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1804 | |
| 1805 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1806 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1807 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1808 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1809 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1810 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1811 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1812 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1813 | } |
| 1814 | // Must be equal high, so compare the lows. |
| 1815 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1816 | } |
| 1817 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1818 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1819 | __ b(true_label, final_condition); |
| 1820 | } |
| 1821 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1822 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1823 | Label* true_target_in, |
| 1824 | Label* false_target_in) { |
| 1825 | // Generated branching requires both targets to be explicit. If either of the |
| 1826 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1827 | Label fallthrough_target; |
| 1828 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1829 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1830 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1831 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1832 | switch (type) { |
| 1833 | case Primitive::kPrimLong: |
| 1834 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1835 | break; |
| 1836 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1837 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1838 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1839 | GenerateFPJumps(condition, true_target, false_target); |
| 1840 | break; |
| 1841 | default: |
| 1842 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1843 | } |
| 1844 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1845 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1846 | __ b(false_target); |
| 1847 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1848 | |
| 1849 | if (fallthrough_target.IsLinked()) { |
| 1850 | __ Bind(&fallthrough_target); |
| 1851 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1852 | } |
| 1853 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1854 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1855 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1856 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1857 | Label* false_target) { |
| 1858 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1859 | |
| 1860 | if (true_target == nullptr && false_target == nullptr) { |
| 1861 | // Nothing to do. The code always falls through. |
| 1862 | return; |
| 1863 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1864 | // Constant condition, statically compared against "true" (integer value 1). |
| 1865 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1866 | if (true_target != nullptr) { |
| 1867 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1868 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1869 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1870 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1871 | if (false_target != nullptr) { |
| 1872 | __ b(false_target); |
| 1873 | } |
| 1874 | } |
| 1875 | return; |
| 1876 | } |
| 1877 | |
| 1878 | // The following code generates these patterns: |
| 1879 | // (1) true_target == nullptr && false_target != nullptr |
| 1880 | // - opposite condition true => branch to false_target |
| 1881 | // (2) true_target != nullptr && false_target == nullptr |
| 1882 | // - condition true => branch to true_target |
| 1883 | // (3) true_target != nullptr && false_target != nullptr |
| 1884 | // - condition true => branch to true_target |
| 1885 | // - branch to false_target |
| 1886 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1887 | // Condition has been materialized, compare the output to 0. |
| 1888 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1889 | DCHECK(cond_val.IsRegister()); |
| 1890 | if (true_target == nullptr) { |
| 1891 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1892 | } else { |
| 1893 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1894 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1895 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1896 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1897 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1898 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1899 | |
| 1900 | // If this is a long or FP comparison that has been folded into |
| 1901 | // the HCondition, generate the comparison directly. |
| 1902 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1903 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1904 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1905 | return; |
| 1906 | } |
| 1907 | |
| 1908 | LocationSummary* locations = cond->GetLocations(); |
| 1909 | DCHECK(locations->InAt(0).IsRegister()); |
| 1910 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1911 | Location right = locations->InAt(1); |
| 1912 | if (right.IsRegister()) { |
| 1913 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1914 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1915 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1916 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1917 | } |
| 1918 | if (true_target == nullptr) { |
| 1919 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1920 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1921 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1922 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1923 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1924 | |
| 1925 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1926 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1927 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1928 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1932 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1933 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1934 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1935 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1940 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1941 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1942 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1943 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1944 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1945 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1946 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1950 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1951 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1952 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1953 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1954 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1959 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1960 | GenerateTestAndBranch(deoptimize, |
| 1961 | /* condition_input_index */ 0, |
| 1962 | slow_path->GetEntryLabel(), |
| 1963 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1964 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1965 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1966 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1967 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1968 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1969 | locations->SetOut(Location::RequiresRegister()); |
| 1970 | } |
| 1971 | |
| 1972 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1973 | __ LoadFromOffset(kLoadWord, |
| 1974 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 1975 | SP, |
| 1976 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1977 | } |
| 1978 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1979 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1980 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1981 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1982 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1983 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1984 | } else { |
| 1985 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1986 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1987 | } |
| 1988 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1989 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1990 | } |
| 1991 | locations->SetOut(Location::SameAsFirstInput()); |
| 1992 | } |
| 1993 | |
| 1994 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1995 | LocationSummary* locations = select->GetLocations(); |
| 1996 | Label false_target; |
| 1997 | GenerateTestAndBranch(select, |
| 1998 | /* condition_input_index */ 2, |
| 1999 | /* true_target */ nullptr, |
| 2000 | &false_target); |
| 2001 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2002 | __ Bind(&false_target); |
| 2003 | } |
| 2004 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2005 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2006 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2007 | } |
| 2008 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2009 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2010 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | void CodeGeneratorARM::GenerateNop() { |
| 2014 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2017 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2018 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2019 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2020 | // Handle the long/FP comparisons made in instruction simplification. |
| 2021 | switch (cond->InputAt(0)->GetType()) { |
| 2022 | case Primitive::kPrimLong: |
| 2023 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2024 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2025 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2026 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2027 | } |
| 2028 | break; |
| 2029 | |
| 2030 | case Primitive::kPrimFloat: |
| 2031 | case Primitive::kPrimDouble: |
| 2032 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2033 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2034 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2035 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2036 | } |
| 2037 | break; |
| 2038 | |
| 2039 | default: |
| 2040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2041 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2042 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2043 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2044 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2045 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2048 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2049 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2050 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2051 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2052 | |
| 2053 | LocationSummary* locations = cond->GetLocations(); |
| 2054 | Location left = locations->InAt(0); |
| 2055 | Location right = locations->InAt(1); |
| 2056 | Register out = locations->Out().AsRegister<Register>(); |
| 2057 | Label true_label, false_label; |
| 2058 | |
| 2059 | switch (cond->InputAt(0)->GetType()) { |
| 2060 | default: { |
| 2061 | // Integer case. |
| 2062 | if (right.IsRegister()) { |
| 2063 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2064 | } else { |
| 2065 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2066 | __ CmpConstant(left.AsRegister<Register>(), |
| 2067 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2068 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2069 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2070 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2071 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2072 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2073 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2074 | return; |
| 2075 | } |
| 2076 | case Primitive::kPrimLong: |
| 2077 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2078 | break; |
| 2079 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2080 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2081 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2082 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2083 | break; |
| 2084 | } |
| 2085 | |
| 2086 | // Convert the jumps into the result. |
| 2087 | Label done_label; |
| 2088 | |
| 2089 | // False case: result = 0. |
| 2090 | __ Bind(&false_label); |
| 2091 | __ LoadImmediate(out, 0); |
| 2092 | __ b(&done_label); |
| 2093 | |
| 2094 | // True case: result = 1. |
| 2095 | __ Bind(&true_label); |
| 2096 | __ LoadImmediate(out, 1); |
| 2097 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2101 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2105 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2109 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2113 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2117 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2121 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2125 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2129 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2133 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2137 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2141 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2145 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2148 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2149 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2153 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2157 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2161 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2165 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2169 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2173 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2177 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2180 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2181 | LocationSummary* locations = |
| 2182 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2183 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2186 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2187 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2190 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2191 | LocationSummary* locations = |
| 2192 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2193 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2194 | } |
| 2195 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2196 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2197 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2200 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2201 | LocationSummary* locations = |
| 2202 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2203 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2204 | } |
| 2205 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2206 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2207 | // Will be generated at use site. |
| 2208 | } |
| 2209 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2210 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2211 | LocationSummary* locations = |
| 2212 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2213 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2214 | } |
| 2215 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2216 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2217 | // Will be generated at use site. |
| 2218 | } |
| 2219 | |
| 2220 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2221 | LocationSummary* locations = |
| 2222 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2223 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2224 | } |
| 2225 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2226 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2227 | // Will be generated at use site. |
| 2228 | } |
| 2229 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2230 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2231 | memory_barrier->SetLocations(nullptr); |
| 2232 | } |
| 2233 | |
| 2234 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2235 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2238 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2239 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2242 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2243 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2246 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2247 | LocationSummary* locations = |
| 2248 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2249 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2252 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2253 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2256 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2257 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2258 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2259 | // the method_idx. |
| 2260 | HandleInvoke(invoke); |
| 2261 | } |
| 2262 | |
| 2263 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2264 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2265 | } |
| 2266 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2267 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2268 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2269 | // art::PrepareForRegisterAllocation. |
| 2270 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2271 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2272 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2273 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2274 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2275 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2276 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2277 | return; |
| 2278 | } |
| 2279 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2280 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2281 | |
| 2282 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2283 | if (invoke->HasPcRelativeDexCache()) { |
| 2284 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2285 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2286 | } |
| 2287 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2288 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2289 | if (invoke->GetLocations()->Intrinsified()) { |
| 2290 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2291 | intrinsic.Dispatch(invoke); |
| 2292 | return true; |
| 2293 | } |
| 2294 | return false; |
| 2295 | } |
| 2296 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2297 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2298 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2299 | // art::PrepareForRegisterAllocation. |
| 2300 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2301 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2302 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2303 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2304 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2305 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2306 | LocationSummary* locations = invoke->GetLocations(); |
| 2307 | codegen_->GenerateStaticOrDirectCall( |
| 2308 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2309 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2312 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2313 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2314 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2317 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2318 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2319 | if (intrinsic.TryDispatch(invoke)) { |
| 2320 | return; |
| 2321 | } |
| 2322 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2323 | HandleInvoke(invoke); |
| 2324 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2325 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2326 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2327 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2328 | return; |
| 2329 | } |
| 2330 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2331 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2332 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2333 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2336 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2337 | HandleInvoke(invoke); |
| 2338 | // Add the hidden argument. |
| 2339 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2340 | } |
| 2341 | |
| 2342 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2343 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2344 | LocationSummary* locations = invoke->GetLocations(); |
| 2345 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2346 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2347 | Location receiver = locations->InAt(0); |
| 2348 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2349 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2350 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2351 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2352 | DCHECK_EQ(R12, hidden_reg); |
| 2353 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2354 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2355 | if (receiver.IsStackSlot()) { |
| 2356 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2357 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2358 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2359 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2360 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2361 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2362 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2363 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2364 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2365 | // emit a read barrier for the previous class reference load. |
| 2366 | // However this is not required in practice, as this is an |
| 2367 | // intermediate/temporary reference and because the current |
| 2368 | // concurrent copying collector keeps the from-space memory |
| 2369 | // intact/accessible until the end of the marking phase (the |
| 2370 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2371 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2372 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2373 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2374 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2375 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2376 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2377 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2378 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2379 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2380 | // LR = temp->GetEntryPoint(); |
| 2381 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2382 | // LR(); |
| 2383 | __ blx(LR); |
| 2384 | DCHECK(!codegen_->IsLeafMethod()); |
| 2385 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2386 | } |
| 2387 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2388 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2389 | HandleInvoke(invoke); |
| 2390 | } |
| 2391 | |
| 2392 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2393 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2394 | } |
| 2395 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2396 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2397 | LocationSummary* locations = |
| 2398 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2399 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2400 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2401 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2402 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2403 | break; |
| 2404 | } |
| 2405 | case Primitive::kPrimLong: { |
| 2406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2407 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2408 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2409 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2410 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2411 | case Primitive::kPrimFloat: |
| 2412 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2413 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2414 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2415 | break; |
| 2416 | |
| 2417 | default: |
| 2418 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2423 | LocationSummary* locations = neg->GetLocations(); |
| 2424 | Location out = locations->Out(); |
| 2425 | Location in = locations->InAt(0); |
| 2426 | switch (neg->GetResultType()) { |
| 2427 | case Primitive::kPrimInt: |
| 2428 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2429 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2430 | break; |
| 2431 | |
| 2432 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2433 | DCHECK(in.IsRegisterPair()); |
| 2434 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2435 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2436 | in.AsRegisterPairLow<Register>(), |
| 2437 | ShifterOperand(0)); |
| 2438 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2439 | // instruction here, as it does not exist in the Thumb-2 |
| 2440 | // instruction set. We use the following approach |
| 2441 | // using SBC and SUB instead. |
| 2442 | // |
| 2443 | // out.hi = -C |
| 2444 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2445 | out.AsRegisterPairHigh<Register>(), |
| 2446 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2447 | // out.hi = out.hi - in.hi |
| 2448 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2449 | out.AsRegisterPairHigh<Register>(), |
| 2450 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2451 | break; |
| 2452 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2453 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2454 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2455 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2458 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2459 | DCHECK(in.IsFpuRegisterPair()); |
| 2460 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2461 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2462 | break; |
| 2463 | |
| 2464 | default: |
| 2465 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2466 | } |
| 2467 | } |
| 2468 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2469 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | Primitive::Type result_type = conversion->GetResultType(); |
| 2471 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2472 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2473 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2474 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2475 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2476 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2477 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2478 | && result_type == Primitive::kPrimLong) |
| 2479 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2480 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2481 | : LocationSummary::kNoCall; |
| 2482 | LocationSummary* locations = |
| 2483 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2484 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2485 | // The Java language does not allow treating boolean as an integral type but |
| 2486 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2487 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2488 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2489 | case Primitive::kPrimByte: |
| 2490 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimLong: |
| 2492 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimBoolean: |
| 2494 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimShort: |
| 2496 | case Primitive::kPrimInt: |
| 2497 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2498 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2499 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2500 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2501 | break; |
| 2502 | |
| 2503 | default: |
| 2504 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2505 | << " to " << result_type; |
| 2506 | } |
| 2507 | break; |
| 2508 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2509 | case Primitive::kPrimShort: |
| 2510 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2511 | case Primitive::kPrimLong: |
| 2512 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2513 | case Primitive::kPrimBoolean: |
| 2514 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2515 | case Primitive::kPrimByte: |
| 2516 | case Primitive::kPrimInt: |
| 2517 | case Primitive::kPrimChar: |
| 2518 | // Processing a Dex `int-to-short' instruction. |
| 2519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2520 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2521 | break; |
| 2522 | |
| 2523 | default: |
| 2524 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2525 | << " to " << result_type; |
| 2526 | } |
| 2527 | break; |
| 2528 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2529 | case Primitive::kPrimInt: |
| 2530 | switch (input_type) { |
| 2531 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2532 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2533 | locations->SetInAt(0, Location::Any()); |
| 2534 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2535 | break; |
| 2536 | |
| 2537 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2538 | // Processing a Dex `float-to-int' instruction. |
| 2539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2540 | locations->SetOut(Location::RequiresRegister()); |
| 2541 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2542 | break; |
| 2543 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2545 | // Processing a Dex `double-to-int' instruction. |
| 2546 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2547 | locations->SetOut(Location::RequiresRegister()); |
| 2548 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | |
| 2551 | default: |
| 2552 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2553 | << " to " << result_type; |
| 2554 | } |
| 2555 | break; |
| 2556 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimLong: |
| 2558 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimBoolean: |
| 2560 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimByte: |
| 2562 | case Primitive::kPrimShort: |
| 2563 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2565 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2566 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2567 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2568 | break; |
| 2569 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2570 | case Primitive::kPrimFloat: { |
| 2571 | // Processing a Dex `float-to-long' instruction. |
| 2572 | InvokeRuntimeCallingConvention calling_convention; |
| 2573 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2574 | calling_convention.GetFpuRegisterAt(0))); |
| 2575 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2576 | break; |
| 2577 | } |
| 2578 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2579 | case Primitive::kPrimDouble: { |
| 2580 | // Processing a Dex `double-to-long' instruction. |
| 2581 | InvokeRuntimeCallingConvention calling_convention; |
| 2582 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2583 | calling_convention.GetFpuRegisterAt(0), |
| 2584 | calling_convention.GetFpuRegisterAt(1))); |
| 2585 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2586 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2587 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | |
| 2589 | default: |
| 2590 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2591 | << " to " << result_type; |
| 2592 | } |
| 2593 | break; |
| 2594 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2595 | case Primitive::kPrimChar: |
| 2596 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimLong: |
| 2598 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2599 | case Primitive::kPrimBoolean: |
| 2600 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimByte: |
| 2602 | case Primitive::kPrimShort: |
| 2603 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2604 | // Processing a Dex `int-to-char' instruction. |
| 2605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2606 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2607 | break; |
| 2608 | |
| 2609 | default: |
| 2610 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2611 | << " to " << result_type; |
| 2612 | } |
| 2613 | break; |
| 2614 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2615 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2616 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2617 | case Primitive::kPrimBoolean: |
| 2618 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2619 | case Primitive::kPrimByte: |
| 2620 | case Primitive::kPrimShort: |
| 2621 | case Primitive::kPrimInt: |
| 2622 | case Primitive::kPrimChar: |
| 2623 | // Processing a Dex `int-to-float' instruction. |
| 2624 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2625 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2626 | break; |
| 2627 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2628 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2629 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2630 | InvokeRuntimeCallingConvention calling_convention; |
| 2631 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2632 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2633 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2634 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2635 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2636 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2638 | // Processing a Dex `double-to-float' instruction. |
| 2639 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2640 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2641 | break; |
| 2642 | |
| 2643 | default: |
| 2644 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2645 | << " to " << result_type; |
| 2646 | }; |
| 2647 | break; |
| 2648 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2649 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2650 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2651 | case Primitive::kPrimBoolean: |
| 2652 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2653 | case Primitive::kPrimByte: |
| 2654 | case Primitive::kPrimShort: |
| 2655 | case Primitive::kPrimInt: |
| 2656 | case Primitive::kPrimChar: |
| 2657 | // Processing a Dex `int-to-double' instruction. |
| 2658 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2659 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2660 | break; |
| 2661 | |
| 2662 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2663 | // Processing a Dex `long-to-double' instruction. |
| 2664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2665 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2666 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2667 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2668 | break; |
| 2669 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2670 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2671 | // Processing a Dex `float-to-double' instruction. |
| 2672 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2673 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2674 | break; |
| 2675 | |
| 2676 | default: |
| 2677 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2678 | << " to " << result_type; |
| 2679 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2680 | break; |
| 2681 | |
| 2682 | default: |
| 2683 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2684 | << " to " << result_type; |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2689 | LocationSummary* locations = conversion->GetLocations(); |
| 2690 | Location out = locations->Out(); |
| 2691 | Location in = locations->InAt(0); |
| 2692 | Primitive::Type result_type = conversion->GetResultType(); |
| 2693 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2694 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2695 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2696 | case Primitive::kPrimByte: |
| 2697 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2698 | case Primitive::kPrimLong: |
| 2699 | // Type conversion from long to byte is a result of code transformations. |
| 2700 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2701 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2702 | case Primitive::kPrimBoolean: |
| 2703 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2704 | case Primitive::kPrimShort: |
| 2705 | case Primitive::kPrimInt: |
| 2706 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2707 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2708 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2709 | break; |
| 2710 | |
| 2711 | default: |
| 2712 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2713 | << " to " << result_type; |
| 2714 | } |
| 2715 | break; |
| 2716 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimShort: |
| 2718 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2719 | case Primitive::kPrimLong: |
| 2720 | // Type conversion from long to short is a result of code transformations. |
| 2721 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2722 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2723 | case Primitive::kPrimBoolean: |
| 2724 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2725 | case Primitive::kPrimByte: |
| 2726 | case Primitive::kPrimInt: |
| 2727 | case Primitive::kPrimChar: |
| 2728 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2729 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2730 | break; |
| 2731 | |
| 2732 | default: |
| 2733 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2734 | << " to " << result_type; |
| 2735 | } |
| 2736 | break; |
| 2737 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2738 | case Primitive::kPrimInt: |
| 2739 | switch (input_type) { |
| 2740 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2741 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2742 | DCHECK(out.IsRegister()); |
| 2743 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2744 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2745 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2746 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2747 | } else { |
| 2748 | DCHECK(in.IsConstant()); |
| 2749 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2750 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2751 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2752 | } |
| 2753 | break; |
| 2754 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2755 | case Primitive::kPrimFloat: { |
| 2756 | // Processing a Dex `float-to-int' instruction. |
| 2757 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2758 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2759 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2760 | break; |
| 2761 | } |
| 2762 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2763 | case Primitive::kPrimDouble: { |
| 2764 | // Processing a Dex `double-to-int' instruction. |
| 2765 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2766 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2767 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2768 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2769 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2770 | |
| 2771 | default: |
| 2772 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2773 | << " to " << result_type; |
| 2774 | } |
| 2775 | break; |
| 2776 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2777 | case Primitive::kPrimLong: |
| 2778 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2779 | case Primitive::kPrimBoolean: |
| 2780 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2781 | case Primitive::kPrimByte: |
| 2782 | case Primitive::kPrimShort: |
| 2783 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2784 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2785 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2786 | DCHECK(out.IsRegisterPair()); |
| 2787 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2788 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2789 | // Sign extension. |
| 2790 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2791 | out.AsRegisterPairLow<Register>(), |
| 2792 | 31); |
| 2793 | break; |
| 2794 | |
| 2795 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2796 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2797 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2798 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2799 | break; |
| 2800 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2801 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2802 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2803 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2804 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2805 | break; |
| 2806 | |
| 2807 | default: |
| 2808 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2809 | << " to " << result_type; |
| 2810 | } |
| 2811 | break; |
| 2812 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2813 | case Primitive::kPrimChar: |
| 2814 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2815 | case Primitive::kPrimLong: |
| 2816 | // Type conversion from long to char is a result of code transformations. |
| 2817 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2818 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2819 | case Primitive::kPrimBoolean: |
| 2820 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2821 | case Primitive::kPrimByte: |
| 2822 | case Primitive::kPrimShort: |
| 2823 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2824 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2825 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | |
| 2828 | default: |
| 2829 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2830 | << " to " << result_type; |
| 2831 | } |
| 2832 | break; |
| 2833 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2834 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2835 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2836 | case Primitive::kPrimBoolean: |
| 2837 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2838 | case Primitive::kPrimByte: |
| 2839 | case Primitive::kPrimShort: |
| 2840 | case Primitive::kPrimInt: |
| 2841 | case Primitive::kPrimChar: { |
| 2842 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2843 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2844 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | } |
| 2847 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2848 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2849 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2850 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2851 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2852 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2853 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2854 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2855 | // Processing a Dex `double-to-float' instruction. |
| 2856 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2857 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2858 | break; |
| 2859 | |
| 2860 | default: |
| 2861 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2862 | << " to " << result_type; |
| 2863 | }; |
| 2864 | break; |
| 2865 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2866 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2867 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2868 | case Primitive::kPrimBoolean: |
| 2869 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2870 | case Primitive::kPrimByte: |
| 2871 | case Primitive::kPrimShort: |
| 2872 | case Primitive::kPrimInt: |
| 2873 | case Primitive::kPrimChar: { |
| 2874 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2875 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2876 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2877 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2878 | break; |
| 2879 | } |
| 2880 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2881 | case Primitive::kPrimLong: { |
| 2882 | // Processing a Dex `long-to-double' instruction. |
| 2883 | Register low = in.AsRegisterPairLow<Register>(); |
| 2884 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2885 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2886 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2887 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2888 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2889 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2890 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2891 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2892 | // temp_d = int-to-double(high) |
| 2893 | __ vmovsr(temp_s, high); |
| 2894 | __ vcvtdi(temp_d, temp_s); |
| 2895 | // constant_d = k2Pow32EncodingForDouble |
| 2896 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2897 | // out_d = unsigned-to-double(low) |
| 2898 | __ vmovsr(out_s, low); |
| 2899 | __ vcvtdu(out_d, out_s); |
| 2900 | // out_d += temp_d * constant_d |
| 2901 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
| 2904 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2905 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2906 | // Processing a Dex `float-to-double' instruction. |
| 2907 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2908 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2909 | break; |
| 2910 | |
| 2911 | default: |
| 2912 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2913 | << " to " << result_type; |
| 2914 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2915 | break; |
| 2916 | |
| 2917 | default: |
| 2918 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2919 | << " to " << result_type; |
| 2920 | } |
| 2921 | } |
| 2922 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2923 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2924 | LocationSummary* locations = |
| 2925 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2926 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2927 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2929 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2930 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2931 | break; |
| 2932 | } |
| 2933 | |
| 2934 | case Primitive::kPrimLong: { |
| 2935 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2936 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2937 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2938 | break; |
| 2939 | } |
| 2940 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2941 | case Primitive::kPrimFloat: |
| 2942 | case Primitive::kPrimDouble: { |
| 2943 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2944 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2945 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2946 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2947 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2948 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2949 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2950 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2951 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2955 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2956 | Location out = locations->Out(); |
| 2957 | Location first = locations->InAt(0); |
| 2958 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2959 | switch (add->GetResultType()) { |
| 2960 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2961 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2962 | __ add(out.AsRegister<Register>(), |
| 2963 | first.AsRegister<Register>(), |
| 2964 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2965 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2966 | __ AddConstant(out.AsRegister<Register>(), |
| 2967 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2968 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2969 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2970 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2971 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2972 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2973 | if (second.IsConstant()) { |
| 2974 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2975 | GenerateAddLongConst(out, first, value); |
| 2976 | } else { |
| 2977 | DCHECK(second.IsRegisterPair()); |
| 2978 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2979 | first.AsRegisterPairLow<Register>(), |
| 2980 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2981 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2982 | first.AsRegisterPairHigh<Register>(), |
| 2983 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2984 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2985 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2986 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2987 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2989 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2990 | first.AsFpuRegister<SRegister>(), |
| 2991 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2992 | break; |
| 2993 | |
| 2994 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2995 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2996 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2997 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2998 | break; |
| 2999 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3000 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3001 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3002 | } |
| 3003 | } |
| 3004 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3005 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3006 | LocationSummary* locations = |
| 3007 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3008 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3009 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3010 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3011 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3012 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3013 | break; |
| 3014 | } |
| 3015 | |
| 3016 | case Primitive::kPrimLong: { |
| 3017 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3018 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3019 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3020 | break; |
| 3021 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3022 | case Primitive::kPrimFloat: |
| 3023 | case Primitive::kPrimDouble: { |
| 3024 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3025 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3026 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3027 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3028 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3029 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3030 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3031 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3035 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3036 | Location out = locations->Out(); |
| 3037 | Location first = locations->InAt(0); |
| 3038 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3039 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3040 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3041 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3042 | __ sub(out.AsRegister<Register>(), |
| 3043 | first.AsRegister<Register>(), |
| 3044 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3045 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3046 | __ AddConstant(out.AsRegister<Register>(), |
| 3047 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3048 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3049 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3050 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3051 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3052 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3053 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3054 | if (second.IsConstant()) { |
| 3055 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3056 | GenerateAddLongConst(out, first, -value); |
| 3057 | } else { |
| 3058 | DCHECK(second.IsRegisterPair()); |
| 3059 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3060 | first.AsRegisterPairLow<Register>(), |
| 3061 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3062 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3063 | first.AsRegisterPairHigh<Register>(), |
| 3064 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3065 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3066 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3067 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3068 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3069 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3070 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3071 | first.AsFpuRegister<SRegister>(), |
| 3072 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3073 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3077 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3078 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3079 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3080 | break; |
| 3081 | } |
| 3082 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3083 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3084 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3085 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3086 | } |
| 3087 | } |
| 3088 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3089 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3090 | LocationSummary* locations = |
| 3091 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3092 | switch (mul->GetResultType()) { |
| 3093 | case Primitive::kPrimInt: |
| 3094 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3096 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3098 | break; |
| 3099 | } |
| 3100 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3101 | case Primitive::kPrimFloat: |
| 3102 | case Primitive::kPrimDouble: { |
| 3103 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3104 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3105 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3106 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3107 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3108 | |
| 3109 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3115 | LocationSummary* locations = mul->GetLocations(); |
| 3116 | Location out = locations->Out(); |
| 3117 | Location first = locations->InAt(0); |
| 3118 | Location second = locations->InAt(1); |
| 3119 | switch (mul->GetResultType()) { |
| 3120 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3121 | __ mul(out.AsRegister<Register>(), |
| 3122 | first.AsRegister<Register>(), |
| 3123 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3124 | break; |
| 3125 | } |
| 3126 | case Primitive::kPrimLong: { |
| 3127 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3128 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3129 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3130 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3131 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3132 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3133 | |
| 3134 | // Extra checks to protect caused by the existence of R1_R2. |
| 3135 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3136 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3137 | DCHECK_NE(out_hi, in1_lo); |
| 3138 | DCHECK_NE(out_hi, in2_lo); |
| 3139 | |
| 3140 | // input: in1 - 64 bits, in2 - 64 bits |
| 3141 | // output: out |
| 3142 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3143 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3144 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3145 | |
| 3146 | // IP <- in1.lo * in2.hi |
| 3147 | __ mul(IP, in1_lo, in2_hi); |
| 3148 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3149 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3150 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3151 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3152 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3153 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3154 | break; |
| 3155 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3156 | |
| 3157 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3158 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3159 | first.AsFpuRegister<SRegister>(), |
| 3160 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3161 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3165 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3166 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3167 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3168 | break; |
| 3169 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3170 | |
| 3171 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3172 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3173 | } |
| 3174 | } |
| 3175 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3176 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3177 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3178 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3179 | |
| 3180 | LocationSummary* locations = instruction->GetLocations(); |
| 3181 | Location second = locations->InAt(1); |
| 3182 | DCHECK(second.IsConstant()); |
| 3183 | |
| 3184 | Register out = locations->Out().AsRegister<Register>(); |
| 3185 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3186 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3187 | DCHECK(imm == 1 || imm == -1); |
| 3188 | |
| 3189 | if (instruction->IsRem()) { |
| 3190 | __ LoadImmediate(out, 0); |
| 3191 | } else { |
| 3192 | if (imm == 1) { |
| 3193 | __ Mov(out, dividend); |
| 3194 | } else { |
| 3195 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3196 | } |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3201 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3202 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3203 | |
| 3204 | LocationSummary* locations = instruction->GetLocations(); |
| 3205 | Location second = locations->InAt(1); |
| 3206 | DCHECK(second.IsConstant()); |
| 3207 | |
| 3208 | Register out = locations->Out().AsRegister<Register>(); |
| 3209 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3210 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3211 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3212 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3213 | int ctz_imm = CTZ(abs_imm); |
| 3214 | |
| 3215 | if (ctz_imm == 1) { |
| 3216 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3217 | } else { |
| 3218 | __ Asr(temp, dividend, 31); |
| 3219 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3220 | } |
| 3221 | __ add(out, temp, ShifterOperand(dividend)); |
| 3222 | |
| 3223 | if (instruction->IsDiv()) { |
| 3224 | __ Asr(out, out, ctz_imm); |
| 3225 | if (imm < 0) { |
| 3226 | __ rsb(out, out, ShifterOperand(0)); |
| 3227 | } |
| 3228 | } else { |
| 3229 | __ ubfx(out, out, 0, ctz_imm); |
| 3230 | __ sub(out, out, ShifterOperand(temp)); |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3235 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3236 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3237 | |
| 3238 | LocationSummary* locations = instruction->GetLocations(); |
| 3239 | Location second = locations->InAt(1); |
| 3240 | DCHECK(second.IsConstant()); |
| 3241 | |
| 3242 | Register out = locations->Out().AsRegister<Register>(); |
| 3243 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3244 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3245 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3246 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3247 | |
| 3248 | int64_t magic; |
| 3249 | int shift; |
| 3250 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3251 | |
| 3252 | __ LoadImmediate(temp1, magic); |
| 3253 | __ smull(temp2, temp1, dividend, temp1); |
| 3254 | |
| 3255 | if (imm > 0 && magic < 0) { |
| 3256 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3257 | } else if (imm < 0 && magic > 0) { |
| 3258 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3259 | } |
| 3260 | |
| 3261 | if (shift != 0) { |
| 3262 | __ Asr(temp1, temp1, shift); |
| 3263 | } |
| 3264 | |
| 3265 | if (instruction->IsDiv()) { |
| 3266 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3267 | } else { |
| 3268 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3269 | // TODO: Strength reduction for mls. |
| 3270 | __ LoadImmediate(temp2, imm); |
| 3271 | __ mls(out, temp1, temp2, dividend); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3276 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3277 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3278 | |
| 3279 | LocationSummary* locations = instruction->GetLocations(); |
| 3280 | Location second = locations->InAt(1); |
| 3281 | DCHECK(second.IsConstant()); |
| 3282 | |
| 3283 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3284 | if (imm == 0) { |
| 3285 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3286 | } else if (imm == 1 || imm == -1) { |
| 3287 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3288 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3289 | DivRemByPowerOfTwo(instruction); |
| 3290 | } else { |
| 3291 | DCHECK(imm <= -2 || imm >= 2); |
| 3292 | GenerateDivRemWithAnyConstant(instruction); |
| 3293 | } |
| 3294 | } |
| 3295 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3296 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3297 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3298 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3299 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3300 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3301 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3302 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3303 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3304 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3305 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3306 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3309 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3310 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3311 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3312 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3313 | if (div->InputAt(1)->IsConstant()) { |
| 3314 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3315 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3316 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3317 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3318 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3319 | // No temp register required. |
| 3320 | } else { |
| 3321 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3322 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3323 | locations->AddTemp(Location::RequiresRegister()); |
| 3324 | } |
| 3325 | } |
| 3326 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3328 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3329 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3330 | } else { |
| 3331 | InvokeRuntimeCallingConvention calling_convention; |
| 3332 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3333 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3334 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3335 | // we only need the former. |
| 3336 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3337 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3340 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3341 | InvokeRuntimeCallingConvention calling_convention; |
| 3342 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3343 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3344 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3345 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3346 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3347 | break; |
| 3348 | } |
| 3349 | case Primitive::kPrimFloat: |
| 3350 | case Primitive::kPrimDouble: { |
| 3351 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3352 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3353 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3354 | break; |
| 3355 | } |
| 3356 | |
| 3357 | default: |
| 3358 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3363 | LocationSummary* locations = div->GetLocations(); |
| 3364 | Location out = locations->Out(); |
| 3365 | Location first = locations->InAt(0); |
| 3366 | Location second = locations->InAt(1); |
| 3367 | |
| 3368 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3369 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3370 | if (second.IsConstant()) { |
| 3371 | GenerateDivRemConstantIntegral(div); |
| 3372 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3373 | __ sdiv(out.AsRegister<Register>(), |
| 3374 | first.AsRegister<Register>(), |
| 3375 | second.AsRegister<Register>()); |
| 3376 | } else { |
| 3377 | InvokeRuntimeCallingConvention calling_convention; |
| 3378 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3379 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3380 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3381 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3382 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3383 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3384 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3385 | break; |
| 3386 | } |
| 3387 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3388 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3389 | InvokeRuntimeCallingConvention calling_convention; |
| 3390 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3391 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3392 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3393 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3394 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3395 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3396 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3397 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3398 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3399 | break; |
| 3400 | } |
| 3401 | |
| 3402 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3403 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3404 | first.AsFpuRegister<SRegister>(), |
| 3405 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3406 | break; |
| 3407 | } |
| 3408 | |
| 3409 | case Primitive::kPrimDouble: { |
| 3410 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3411 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3412 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3413 | break; |
| 3414 | } |
| 3415 | |
| 3416 | default: |
| 3417 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3418 | } |
| 3419 | } |
| 3420 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3421 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3422 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3423 | |
| 3424 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3425 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3426 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3427 | // sdiv will be replaced by other instruction sequence. |
| 3428 | call_kind = LocationSummary::kNoCall; |
| 3429 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3430 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3431 | // Have hardware divide instruction for int, do it with three instructions. |
| 3432 | call_kind = LocationSummary::kNoCall; |
| 3433 | } |
| 3434 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3435 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3436 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3437 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3438 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3439 | if (rem->InputAt(1)->IsConstant()) { |
| 3440 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3441 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3442 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3443 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3444 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3445 | // No temp register required. |
| 3446 | } else { |
| 3447 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3448 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3449 | locations->AddTemp(Location::RequiresRegister()); |
| 3450 | } |
| 3451 | } |
| 3452 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3453 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3454 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3456 | locations->AddTemp(Location::RequiresRegister()); |
| 3457 | } else { |
| 3458 | InvokeRuntimeCallingConvention calling_convention; |
| 3459 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3460 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3461 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3462 | // we only need the latter. |
| 3463 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3464 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3465 | break; |
| 3466 | } |
| 3467 | case Primitive::kPrimLong: { |
| 3468 | InvokeRuntimeCallingConvention calling_convention; |
| 3469 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3470 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3471 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3472 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3473 | // The runtime helper puts the output in R2,R3. |
| 3474 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3475 | break; |
| 3476 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3477 | case Primitive::kPrimFloat: { |
| 3478 | InvokeRuntimeCallingConvention calling_convention; |
| 3479 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3480 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3481 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3482 | break; |
| 3483 | } |
| 3484 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3485 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3486 | InvokeRuntimeCallingConvention calling_convention; |
| 3487 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3488 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3489 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3490 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3491 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3492 | break; |
| 3493 | } |
| 3494 | |
| 3495 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3496 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3501 | LocationSummary* locations = rem->GetLocations(); |
| 3502 | Location out = locations->Out(); |
| 3503 | Location first = locations->InAt(0); |
| 3504 | Location second = locations->InAt(1); |
| 3505 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3506 | Primitive::Type type = rem->GetResultType(); |
| 3507 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3508 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3509 | if (second.IsConstant()) { |
| 3510 | GenerateDivRemConstantIntegral(rem); |
| 3511 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3512 | Register reg1 = first.AsRegister<Register>(); |
| 3513 | Register reg2 = second.AsRegister<Register>(); |
| 3514 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3515 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3516 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3517 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3518 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3519 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3520 | } else { |
| 3521 | InvokeRuntimeCallingConvention calling_convention; |
| 3522 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3523 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3524 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3525 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3526 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3527 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3528 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3529 | break; |
| 3530 | } |
| 3531 | |
| 3532 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3533 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3534 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3535 | break; |
| 3536 | } |
| 3537 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3538 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3539 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3540 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3541 | break; |
| 3542 | } |
| 3543 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3544 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3545 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3546 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3547 | break; |
| 3548 | } |
| 3549 | |
| 3550 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3551 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3552 | } |
| 3553 | } |
| 3554 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3555 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3556 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3557 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3561 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3562 | codegen_->AddSlowPath(slow_path); |
| 3563 | |
| 3564 | LocationSummary* locations = instruction->GetLocations(); |
| 3565 | Location value = locations->InAt(0); |
| 3566 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3567 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3568 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3569 | case Primitive::kPrimByte: |
| 3570 | case Primitive::kPrimChar: |
| 3571 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3572 | case Primitive::kPrimInt: { |
| 3573 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3574 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3575 | } else { |
| 3576 | DCHECK(value.IsConstant()) << value; |
| 3577 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3578 | __ b(slow_path->GetEntryLabel()); |
| 3579 | } |
| 3580 | } |
| 3581 | break; |
| 3582 | } |
| 3583 | case Primitive::kPrimLong: { |
| 3584 | if (value.IsRegisterPair()) { |
| 3585 | __ orrs(IP, |
| 3586 | value.AsRegisterPairLow<Register>(), |
| 3587 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3588 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3589 | } else { |
| 3590 | DCHECK(value.IsConstant()) << value; |
| 3591 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3592 | __ b(slow_path->GetEntryLabel()); |
| 3593 | } |
| 3594 | } |
| 3595 | break; |
| 3596 | default: |
| 3597 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3598 | } |
| 3599 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3602 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3603 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3604 | Location rhs = locations->InAt(1); |
| 3605 | Register out = locations->Out().AsRegister<Register>(); |
| 3606 | |
| 3607 | if (rhs.IsConstant()) { |
| 3608 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3609 | // so map all rotations to a +ve. equivalent in that range. |
| 3610 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3611 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3612 | if (rot) { |
| 3613 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3614 | // (e.g. left by 2 bits == right by 30.) |
| 3615 | __ Ror(out, in, rot); |
| 3616 | } else if (out != in) { |
| 3617 | __ Mov(out, in); |
| 3618 | } |
| 3619 | } else { |
| 3620 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3625 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3626 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3627 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3628 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3629 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3630 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3631 | Location rhs = locations->InAt(1); |
| 3632 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3633 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3634 | |
| 3635 | if (rhs.IsConstant()) { |
| 3636 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3637 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3638 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3639 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3640 | // logic below to a simple pair of binary orr. |
| 3641 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3642 | if (rot >= kArmBitsPerWord) { |
| 3643 | rot -= kArmBitsPerWord; |
| 3644 | std::swap(in_reg_hi, in_reg_lo); |
| 3645 | } |
| 3646 | // Rotate, or mov to out for zero or word size rotations. |
| 3647 | if (rot != 0u) { |
| 3648 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3649 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3650 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3651 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3652 | } else { |
| 3653 | __ Mov(out_reg_lo, in_reg_lo); |
| 3654 | __ Mov(out_reg_hi, in_reg_hi); |
| 3655 | } |
| 3656 | } else { |
| 3657 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3658 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3659 | Label end; |
| 3660 | Label shift_by_32_plus_shift_right; |
| 3661 | |
| 3662 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3663 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3664 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3665 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3666 | |
| 3667 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3668 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3669 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3670 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3671 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3672 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3673 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3674 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3675 | __ b(&end); |
| 3676 | |
| 3677 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3678 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3679 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3680 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3681 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3682 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3683 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3684 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3685 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3686 | |
| 3687 | __ Bind(&end); |
| 3688 | } |
| 3689 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3690 | |
| 3691 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3692 | LocationSummary* locations = |
| 3693 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3694 | switch (ror->GetResultType()) { |
| 3695 | case Primitive::kPrimInt: { |
| 3696 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3697 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3698 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3699 | break; |
| 3700 | } |
| 3701 | case Primitive::kPrimLong: { |
| 3702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3703 | if (ror->InputAt(1)->IsConstant()) { |
| 3704 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3705 | } else { |
| 3706 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3707 | locations->AddTemp(Location::RequiresRegister()); |
| 3708 | locations->AddTemp(Location::RequiresRegister()); |
| 3709 | } |
| 3710 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3711 | break; |
| 3712 | } |
| 3713 | default: |
| 3714 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3715 | } |
| 3716 | } |
| 3717 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3718 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3719 | LocationSummary* locations = ror->GetLocations(); |
| 3720 | Primitive::Type type = ror->GetResultType(); |
| 3721 | switch (type) { |
| 3722 | case Primitive::kPrimInt: { |
| 3723 | HandleIntegerRotate(locations); |
| 3724 | break; |
| 3725 | } |
| 3726 | case Primitive::kPrimLong: { |
| 3727 | HandleLongRotate(locations); |
| 3728 | break; |
| 3729 | } |
| 3730 | default: |
| 3731 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3732 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3736 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3737 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3738 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3739 | LocationSummary* locations = |
| 3740 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3741 | |
| 3742 | switch (op->GetResultType()) { |
| 3743 | case Primitive::kPrimInt: { |
| 3744 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3745 | if (op->InputAt(1)->IsConstant()) { |
| 3746 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3747 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3748 | } else { |
| 3749 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3750 | // Make the output overlap, as it will be used to hold the masked |
| 3751 | // second input. |
| 3752 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3753 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3757 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3758 | if (op->InputAt(1)->IsConstant()) { |
| 3759 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3760 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3761 | // don't clash with high registers which the register allocator currently guarantees. |
| 3762 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3763 | } else { |
| 3764 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3765 | locations->AddTemp(Location::RequiresRegister()); |
| 3766 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3767 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3768 | break; |
| 3769 | } |
| 3770 | default: |
| 3771 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3776 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3777 | |
| 3778 | LocationSummary* locations = op->GetLocations(); |
| 3779 | Location out = locations->Out(); |
| 3780 | Location first = locations->InAt(0); |
| 3781 | Location second = locations->InAt(1); |
| 3782 | |
| 3783 | Primitive::Type type = op->GetResultType(); |
| 3784 | switch (type) { |
| 3785 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3786 | Register out_reg = out.AsRegister<Register>(); |
| 3787 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3788 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3789 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3790 | // 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] | 3791 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3792 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3793 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3794 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3795 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3796 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3797 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3798 | } |
| 3799 | } else { |
| 3800 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3801 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3802 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3803 | __ Mov(out_reg, first_reg); |
| 3804 | } else if (op->IsShl()) { |
| 3805 | __ Lsl(out_reg, first_reg, shift_value); |
| 3806 | } else if (op->IsShr()) { |
| 3807 | __ Asr(out_reg, first_reg, shift_value); |
| 3808 | } else { |
| 3809 | __ Lsr(out_reg, first_reg, shift_value); |
| 3810 | } |
| 3811 | } |
| 3812 | break; |
| 3813 | } |
| 3814 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3815 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3816 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3817 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3818 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3819 | Register low = first.AsRegisterPairLow<Register>(); |
| 3820 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3821 | if (second.IsRegister()) { |
| 3822 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3823 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3824 | Register second_reg = second.AsRegister<Register>(); |
| 3825 | |
| 3826 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3827 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3828 | // Shift the high part |
| 3829 | __ Lsl(o_h, high, o_l); |
| 3830 | // Shift the low part and `or` what overflew on the high part |
| 3831 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3832 | __ Lsr(temp, low, temp); |
| 3833 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3834 | // If the shift is > 32 bits, override the high part |
| 3835 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3836 | __ it(PL); |
| 3837 | __ Lsl(o_h, low, temp, PL); |
| 3838 | // Shift the low part |
| 3839 | __ Lsl(o_l, low, o_l); |
| 3840 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3841 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3842 | // Shift the low part |
| 3843 | __ Lsr(o_l, low, o_h); |
| 3844 | // Shift the high part and `or` what underflew on the low part |
| 3845 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3846 | __ Lsl(temp, high, temp); |
| 3847 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3848 | // If the shift is > 32 bits, override the low part |
| 3849 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3850 | __ it(PL); |
| 3851 | __ Asr(o_l, high, temp, PL); |
| 3852 | // Shift the high part |
| 3853 | __ Asr(o_h, high, o_h); |
| 3854 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3855 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3856 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3857 | __ Lsr(o_l, low, o_h); |
| 3858 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3859 | __ Lsl(temp, high, temp); |
| 3860 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3861 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3862 | __ it(PL); |
| 3863 | __ Lsr(o_l, high, temp, PL); |
| 3864 | __ Lsr(o_h, high, o_h); |
| 3865 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3867 | // Register allocator doesn't create partial overlap. |
| 3868 | DCHECK_NE(o_l, high); |
| 3869 | DCHECK_NE(o_h, low); |
| 3870 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3871 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3872 | if (shift_value > 32) { |
| 3873 | if (op->IsShl()) { |
| 3874 | __ Lsl(o_h, low, shift_value - 32); |
| 3875 | __ LoadImmediate(o_l, 0); |
| 3876 | } else if (op->IsShr()) { |
| 3877 | __ Asr(o_l, high, shift_value - 32); |
| 3878 | __ Asr(o_h, high, 31); |
| 3879 | } else { |
| 3880 | __ Lsr(o_l, high, shift_value - 32); |
| 3881 | __ LoadImmediate(o_h, 0); |
| 3882 | } |
| 3883 | } else if (shift_value == 32) { |
| 3884 | if (op->IsShl()) { |
| 3885 | __ mov(o_h, ShifterOperand(low)); |
| 3886 | __ LoadImmediate(o_l, 0); |
| 3887 | } else if (op->IsShr()) { |
| 3888 | __ mov(o_l, ShifterOperand(high)); |
| 3889 | __ Asr(o_h, high, 31); |
| 3890 | } else { |
| 3891 | __ mov(o_l, ShifterOperand(high)); |
| 3892 | __ LoadImmediate(o_h, 0); |
| 3893 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3894 | } else if (shift_value == 1) { |
| 3895 | if (op->IsShl()) { |
| 3896 | __ Lsls(o_l, low, 1); |
| 3897 | __ adc(o_h, high, ShifterOperand(high)); |
| 3898 | } else if (op->IsShr()) { |
| 3899 | __ Asrs(o_h, high, 1); |
| 3900 | __ Rrx(o_l, low); |
| 3901 | } else { |
| 3902 | __ Lsrs(o_h, high, 1); |
| 3903 | __ Rrx(o_l, low); |
| 3904 | } |
| 3905 | } else { |
| 3906 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3907 | if (op->IsShl()) { |
| 3908 | __ Lsl(o_h, high, shift_value); |
| 3909 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3910 | __ Lsl(o_l, low, shift_value); |
| 3911 | } else if (op->IsShr()) { |
| 3912 | __ Lsr(o_l, low, shift_value); |
| 3913 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3914 | __ Asr(o_h, high, shift_value); |
| 3915 | } else { |
| 3916 | __ Lsr(o_l, low, shift_value); |
| 3917 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3918 | __ Lsr(o_h, high, shift_value); |
| 3919 | } |
| 3920 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3921 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3922 | break; |
| 3923 | } |
| 3924 | default: |
| 3925 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3926 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3931 | HandleShift(shl); |
| 3932 | } |
| 3933 | |
| 3934 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3935 | HandleShift(shl); |
| 3936 | } |
| 3937 | |
| 3938 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3939 | HandleShift(shr); |
| 3940 | } |
| 3941 | |
| 3942 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3943 | HandleShift(shr); |
| 3944 | } |
| 3945 | |
| 3946 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3947 | HandleShift(ushr); |
| 3948 | } |
| 3949 | |
| 3950 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3951 | HandleShift(ushr); |
| 3952 | } |
| 3953 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3954 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3955 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3956 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3957 | if (instruction->IsStringAlloc()) { |
| 3958 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3959 | } else { |
| 3960 | InvokeRuntimeCallingConvention calling_convention; |
| 3961 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3962 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3963 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3967 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3968 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3969 | if (instruction->IsStringAlloc()) { |
| 3970 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3971 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3972 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3973 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3974 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3975 | __ blx(LR); |
| 3976 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3977 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3978 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 3979 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3980 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3981 | } |
| 3982 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3983 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3984 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3985 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3986 | InvokeRuntimeCallingConvention calling_convention; |
| 3987 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3988 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3989 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3990 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3994 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3995 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex().index_); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3996 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3997 | // of poisoning the reference. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3998 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3999 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4000 | } |
| 4001 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4002 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4003 | LocationSummary* locations = |
| 4004 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4005 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4006 | if (location.IsStackSlot()) { |
| 4007 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4008 | } else if (location.IsDoubleStackSlot()) { |
| 4009 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4010 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4011 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4012 | } |
| 4013 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4014 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4015 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4016 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4020 | LocationSummary* locations = |
| 4021 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4022 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4023 | } |
| 4024 | |
| 4025 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4026 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4029 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4030 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4031 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4033 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4036 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4037 | LocationSummary* locations = not_->GetLocations(); |
| 4038 | Location out = locations->Out(); |
| 4039 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4040 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4041 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4042 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4043 | break; |
| 4044 | |
| 4045 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4046 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4047 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4048 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4049 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4050 | break; |
| 4051 | |
| 4052 | default: |
| 4053 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4054 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4055 | } |
| 4056 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4057 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4058 | LocationSummary* locations = |
| 4059 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4060 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4061 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4062 | } |
| 4063 | |
| 4064 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4065 | LocationSummary* locations = bool_not->GetLocations(); |
| 4066 | Location out = locations->Out(); |
| 4067 | Location in = locations->InAt(0); |
| 4068 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4069 | } |
| 4070 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4071 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4072 | LocationSummary* locations = |
| 4073 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4074 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4075 | case Primitive::kPrimBoolean: |
| 4076 | case Primitive::kPrimByte: |
| 4077 | case Primitive::kPrimShort: |
| 4078 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4079 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4080 | case Primitive::kPrimLong: { |
| 4081 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4082 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4083 | // Output overlaps because it is written before doing the low comparison. |
| 4084 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4085 | break; |
| 4086 | } |
| 4087 | case Primitive::kPrimFloat: |
| 4088 | case Primitive::kPrimDouble: { |
| 4089 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4090 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4091 | locations->SetOut(Location::RequiresRegister()); |
| 4092 | break; |
| 4093 | } |
| 4094 | default: |
| 4095 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4096 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4100 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4101 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4102 | Location left = locations->InAt(0); |
| 4103 | Location right = locations->InAt(1); |
| 4104 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4105 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4106 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4107 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4108 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4109 | case Primitive::kPrimBoolean: |
| 4110 | case Primitive::kPrimByte: |
| 4111 | case Primitive::kPrimShort: |
| 4112 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4113 | case Primitive::kPrimInt: { |
| 4114 | __ LoadImmediate(out, 0); |
| 4115 | __ cmp(left.AsRegister<Register>(), |
| 4116 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4117 | less_cond = LT; |
| 4118 | break; |
| 4119 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4120 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4121 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4122 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4123 | __ b(&less, LT); |
| 4124 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4125 | // 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] | 4126 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4127 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4128 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4129 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4130 | break; |
| 4131 | } |
| 4132 | case Primitive::kPrimFloat: |
| 4133 | case Primitive::kPrimDouble: { |
| 4134 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4135 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4136 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4137 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4138 | break; |
| 4139 | } |
| 4140 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4141 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4142 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4143 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4144 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4145 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4146 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4147 | |
| 4148 | __ Bind(&greater); |
| 4149 | __ LoadImmediate(out, 1); |
| 4150 | __ b(&done); |
| 4151 | |
| 4152 | __ Bind(&less); |
| 4153 | __ LoadImmediate(out, -1); |
| 4154 | |
| 4155 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4156 | } |
| 4157 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4158 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4159 | LocationSummary* locations = |
| 4160 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4161 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4162 | locations->SetInAt(i, Location::Any()); |
| 4163 | } |
| 4164 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4165 | } |
| 4166 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4167 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4168 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4169 | } |
| 4170 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4171 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4172 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4173 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4174 | switch (kind) { |
| 4175 | case MemBarrierKind::kAnyStore: |
| 4176 | case MemBarrierKind::kLoadAny: |
| 4177 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4178 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4179 | break; |
| 4180 | } |
| 4181 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4182 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4183 | break; |
| 4184 | } |
| 4185 | default: |
| 4186 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4187 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4188 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4192 | uint32_t offset, |
| 4193 | Register out_lo, |
| 4194 | Register out_hi) { |
| 4195 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4196 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4197 | // `offset` into `out_lo` does not clutter `addr`. |
| 4198 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4199 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4200 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4201 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4202 | } |
| 4203 | __ ldrexd(out_lo, out_hi, addr); |
| 4204 | } |
| 4205 | |
| 4206 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4207 | uint32_t offset, |
| 4208 | Register value_lo, |
| 4209 | Register value_hi, |
| 4210 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4211 | Register temp2, |
| 4212 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4213 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4214 | if (offset != 0) { |
| 4215 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4216 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4217 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4218 | } |
| 4219 | __ Bind(&fail); |
| 4220 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4221 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4222 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4223 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4224 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4225 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4229 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4230 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4231 | LocationSummary* locations = |
| 4232 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4233 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4234 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4235 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4236 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4237 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4238 | } else { |
| 4239 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4240 | } |
| 4241 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4242 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4243 | bool generate_volatile = field_info.IsVolatile() |
| 4244 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4245 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4246 | bool needs_write_barrier = |
| 4247 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4248 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4249 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4250 | if (needs_write_barrier) { |
| 4251 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4252 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4253 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4254 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4255 | // - registers need to be consecutive |
| 4256 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4257 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4258 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4259 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4260 | |
| 4261 | locations->AddTemp(Location::RequiresRegister()); |
| 4262 | locations->AddTemp(Location::RequiresRegister()); |
| 4263 | if (field_type == Primitive::kPrimDouble) { |
| 4264 | // For doubles we need two more registers to copy the value. |
| 4265 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4266 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4267 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4268 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4269 | } |
| 4270 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4271 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4272 | const FieldInfo& field_info, |
| 4273 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4274 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4275 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4276 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4277 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4278 | Location value = locations->InAt(1); |
| 4279 | |
| 4280 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4281 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4283 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4284 | bool needs_write_barrier = |
| 4285 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4286 | |
| 4287 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4288 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4289 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4290 | |
| 4291 | switch (field_type) { |
| 4292 | case Primitive::kPrimBoolean: |
| 4293 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4294 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4295 | break; |
| 4296 | } |
| 4297 | |
| 4298 | case Primitive::kPrimShort: |
| 4299 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4300 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4301 | break; |
| 4302 | } |
| 4303 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4304 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4305 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4306 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4307 | // Note that in the case where `value` is a null reference, |
| 4308 | // we do not enter this block, as a null reference does not |
| 4309 | // need poisoning. |
| 4310 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4311 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4312 | __ Mov(temp, value.AsRegister<Register>()); |
| 4313 | __ PoisonHeapReference(temp); |
| 4314 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4315 | } else { |
| 4316 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4317 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4318 | break; |
| 4319 | } |
| 4320 | |
| 4321 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4322 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4323 | GenerateWideAtomicStore(base, offset, |
| 4324 | value.AsRegisterPairLow<Register>(), |
| 4325 | value.AsRegisterPairHigh<Register>(), |
| 4326 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4327 | locations->GetTemp(1).AsRegister<Register>(), |
| 4328 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4329 | } else { |
| 4330 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4331 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4332 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4333 | break; |
| 4334 | } |
| 4335 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4336 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4337 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4338 | break; |
| 4339 | } |
| 4340 | |
| 4341 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4342 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4343 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4344 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4345 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4346 | |
| 4347 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4348 | |
| 4349 | GenerateWideAtomicStore(base, offset, |
| 4350 | value_reg_lo, |
| 4351 | value_reg_hi, |
| 4352 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4353 | locations->GetTemp(3).AsRegister<Register>(), |
| 4354 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4355 | } else { |
| 4356 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4358 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4359 | break; |
| 4360 | } |
| 4361 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4362 | case Primitive::kPrimVoid: |
| 4363 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4364 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4365 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4366 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4367 | // Longs and doubles are handled in the switch. |
| 4368 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4369 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4370 | } |
| 4371 | |
| 4372 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4373 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4374 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4375 | codegen_->MarkGCCard( |
| 4376 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4379 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4380 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4381 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4384 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4385 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4386 | |
| 4387 | bool object_field_get_with_read_barrier = |
| 4388 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4389 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4390 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4391 | object_field_get_with_read_barrier ? |
| 4392 | LocationSummary::kCallOnSlowPath : |
| 4393 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4394 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4395 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4396 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4397 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4398 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4399 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4400 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4401 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4402 | // The output overlaps in case of volatile long: we don't want the |
| 4403 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4404 | // object's location. Likewise, in the case of an object field get |
| 4405 | // with read barriers enabled, we do not want the load to overwrite |
| 4406 | // the object's location, as we need it to emit the read barrier. |
| 4407 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4408 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4409 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4410 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4411 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4412 | } else { |
| 4413 | locations->SetOut(Location::RequiresRegister(), |
| 4414 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4415 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4416 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4417 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4418 | // - registers need to be consecutive |
| 4419 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4420 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4421 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4422 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4423 | locations->AddTemp(Location::RequiresRegister()); |
| 4424 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4425 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4426 | // We need a temporary register for the read barrier marking slow |
| 4427 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4428 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4429 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4430 | } |
| 4431 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4432 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4433 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4434 | << input->GetType(); |
| 4435 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4436 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4437 | return Location::ConstantLocation(input->AsConstant()); |
| 4438 | } else { |
| 4439 | return Location::RequiresFpuRegister(); |
| 4440 | } |
| 4441 | } |
| 4442 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4443 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4444 | Opcode opcode) { |
| 4445 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4446 | if (constant->IsConstant() && |
| 4447 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4448 | return Location::ConstantLocation(constant->AsConstant()); |
| 4449 | } |
| 4450 | return Location::RequiresRegister(); |
| 4451 | } |
| 4452 | |
| 4453 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4454 | Opcode opcode) { |
| 4455 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4456 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4457 | Opcode high_opcode = opcode; |
| 4458 | SetCc low_set_cc = kCcDontCare; |
| 4459 | switch (opcode) { |
| 4460 | case SUB: |
| 4461 | // Flip the operation to an ADD. |
| 4462 | value = -value; |
| 4463 | opcode = ADD; |
| 4464 | FALLTHROUGH_INTENDED; |
| 4465 | case ADD: |
| 4466 | if (Low32Bits(value) == 0u) { |
| 4467 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4468 | } |
| 4469 | high_opcode = ADC; |
| 4470 | low_set_cc = kCcSet; |
| 4471 | break; |
| 4472 | default: |
| 4473 | break; |
| 4474 | } |
| 4475 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4476 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4477 | } else { |
| 4478 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4479 | } |
| 4480 | } |
| 4481 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4482 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4483 | Opcode opcode, |
| 4484 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4485 | ShifterOperand so; |
| 4486 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4487 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4488 | return true; |
| 4489 | } |
| 4490 | Opcode neg_opcode = kNoOperand; |
| 4491 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4492 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4493 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4494 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4495 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4496 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4497 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4498 | default: |
| 4499 | return false; |
| 4500 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4501 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4502 | } |
| 4503 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4504 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4505 | const FieldInfo& field_info) { |
| 4506 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4507 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4508 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4509 | Location base_loc = locations->InAt(0); |
| 4510 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4511 | Location out = locations->Out(); |
| 4512 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4513 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4514 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4515 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4516 | |
| 4517 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4518 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4519 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4520 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4521 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4522 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4523 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4524 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4525 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4526 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4527 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4528 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4529 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4530 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4531 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4532 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4533 | |
| 4534 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4536 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4537 | |
| 4538 | case Primitive::kPrimNot: { |
| 4539 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4540 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4541 | Location temp_loc = locations->GetTemp(0); |
| 4542 | // Note that a potential implicit null check is handled in this |
| 4543 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4544 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4545 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4546 | if (is_volatile) { |
| 4547 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4548 | } |
| 4549 | } else { |
| 4550 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4551 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4552 | if (is_volatile) { |
| 4553 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4554 | } |
| 4555 | // If read barriers are enabled, emit read barriers other than |
| 4556 | // Baker's using a slow path (and also unpoison the loaded |
| 4557 | // reference, if heap poisoning is enabled). |
| 4558 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4559 | } |
| 4560 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4561 | } |
| 4562 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4563 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4564 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | GenerateWideAtomicLoad(base, offset, |
| 4566 | out.AsRegisterPairLow<Register>(), |
| 4567 | out.AsRegisterPairHigh<Register>()); |
| 4568 | } else { |
| 4569 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4570 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4571 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4572 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4573 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4574 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4575 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4576 | |
| 4577 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4579 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4580 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4581 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4582 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4583 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4584 | __ vmovdrr(out_reg, lo, hi); |
| 4585 | } else { |
| 4586 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4587 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4589 | break; |
| 4590 | } |
| 4591 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4592 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4593 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4594 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4595 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4596 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4597 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4598 | // Potential implicit null checks, in the case of reference or |
| 4599 | // double fields, are handled in the previous switch statement. |
| 4600 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4601 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4602 | } |
| 4603 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4604 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4605 | if (field_type == Primitive::kPrimNot) { |
| 4606 | // Memory barriers, in the case of references, are also handled |
| 4607 | // in the previous switch statement. |
| 4608 | } else { |
| 4609 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4610 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4611 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4615 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4616 | } |
| 4617 | |
| 4618 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4619 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4623 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4624 | } |
| 4625 | |
| 4626 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4627 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4628 | } |
| 4629 | |
| 4630 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4631 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4632 | } |
| 4633 | |
| 4634 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4635 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4636 | } |
| 4637 | |
| 4638 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4639 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4640 | } |
| 4641 | |
| 4642 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4643 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4644 | } |
| 4645 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4646 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4647 | HUnresolvedInstanceFieldGet* instruction) { |
| 4648 | FieldAccessCallingConventionARM calling_convention; |
| 4649 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4650 | instruction, instruction->GetFieldType(), calling_convention); |
| 4651 | } |
| 4652 | |
| 4653 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4654 | HUnresolvedInstanceFieldGet* instruction) { |
| 4655 | FieldAccessCallingConventionARM calling_convention; |
| 4656 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4657 | instruction->GetFieldType(), |
| 4658 | instruction->GetFieldIndex(), |
| 4659 | instruction->GetDexPc(), |
| 4660 | calling_convention); |
| 4661 | } |
| 4662 | |
| 4663 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4664 | HUnresolvedInstanceFieldSet* instruction) { |
| 4665 | FieldAccessCallingConventionARM calling_convention; |
| 4666 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4667 | instruction, instruction->GetFieldType(), calling_convention); |
| 4668 | } |
| 4669 | |
| 4670 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4671 | HUnresolvedInstanceFieldSet* instruction) { |
| 4672 | FieldAccessCallingConventionARM calling_convention; |
| 4673 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4674 | instruction->GetFieldType(), |
| 4675 | instruction->GetFieldIndex(), |
| 4676 | instruction->GetDexPc(), |
| 4677 | calling_convention); |
| 4678 | } |
| 4679 | |
| 4680 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4681 | HUnresolvedStaticFieldGet* instruction) { |
| 4682 | FieldAccessCallingConventionARM calling_convention; |
| 4683 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4684 | instruction, instruction->GetFieldType(), calling_convention); |
| 4685 | } |
| 4686 | |
| 4687 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4688 | HUnresolvedStaticFieldGet* instruction) { |
| 4689 | FieldAccessCallingConventionARM calling_convention; |
| 4690 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4691 | instruction->GetFieldType(), |
| 4692 | instruction->GetFieldIndex(), |
| 4693 | instruction->GetDexPc(), |
| 4694 | calling_convention); |
| 4695 | } |
| 4696 | |
| 4697 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4698 | HUnresolvedStaticFieldSet* instruction) { |
| 4699 | FieldAccessCallingConventionARM calling_convention; |
| 4700 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4701 | instruction, instruction->GetFieldType(), calling_convention); |
| 4702 | } |
| 4703 | |
| 4704 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4705 | HUnresolvedStaticFieldSet* instruction) { |
| 4706 | FieldAccessCallingConventionARM calling_convention; |
| 4707 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4708 | instruction->GetFieldType(), |
| 4709 | instruction->GetFieldIndex(), |
| 4710 | instruction->GetDexPc(), |
| 4711 | calling_convention); |
| 4712 | } |
| 4713 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4714 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4715 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4716 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4717 | } |
| 4718 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4719 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4720 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4721 | return; |
| 4722 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4723 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4724 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4725 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4726 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4727 | } |
| 4728 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4729 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4730 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4731 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4732 | |
| 4733 | LocationSummary* locations = instruction->GetLocations(); |
| 4734 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4735 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4736 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4737 | } |
| 4738 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4739 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4740 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4743 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4744 | switch (type) { |
| 4745 | case Primitive::kPrimNot: |
| 4746 | return kLoadWord; |
| 4747 | case Primitive::kPrimBoolean: |
| 4748 | return kLoadUnsignedByte; |
| 4749 | case Primitive::kPrimByte: |
| 4750 | return kLoadSignedByte; |
| 4751 | case Primitive::kPrimChar: |
| 4752 | return kLoadUnsignedHalfword; |
| 4753 | case Primitive::kPrimShort: |
| 4754 | return kLoadSignedHalfword; |
| 4755 | case Primitive::kPrimInt: |
| 4756 | return kLoadWord; |
| 4757 | case Primitive::kPrimLong: |
| 4758 | return kLoadWordPair; |
| 4759 | case Primitive::kPrimFloat: |
| 4760 | return kLoadSWord; |
| 4761 | case Primitive::kPrimDouble: |
| 4762 | return kLoadDWord; |
| 4763 | default: |
| 4764 | LOG(FATAL) << "Unreachable type " << type; |
| 4765 | UNREACHABLE(); |
| 4766 | } |
| 4767 | } |
| 4768 | |
| 4769 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4770 | switch (type) { |
| 4771 | case Primitive::kPrimNot: |
| 4772 | return kStoreWord; |
| 4773 | case Primitive::kPrimBoolean: |
| 4774 | case Primitive::kPrimByte: |
| 4775 | return kStoreByte; |
| 4776 | case Primitive::kPrimChar: |
| 4777 | case Primitive::kPrimShort: |
| 4778 | return kStoreHalfword; |
| 4779 | case Primitive::kPrimInt: |
| 4780 | return kStoreWord; |
| 4781 | case Primitive::kPrimLong: |
| 4782 | return kStoreWordPair; |
| 4783 | case Primitive::kPrimFloat: |
| 4784 | return kStoreSWord; |
| 4785 | case Primitive::kPrimDouble: |
| 4786 | return kStoreDWord; |
| 4787 | default: |
| 4788 | LOG(FATAL) << "Unreachable type " << type; |
| 4789 | UNREACHABLE(); |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4794 | Location out_loc, |
| 4795 | Register base, |
| 4796 | Register reg_offset, |
| 4797 | Condition cond) { |
| 4798 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4799 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4800 | |
| 4801 | switch (type) { |
| 4802 | case Primitive::kPrimByte: |
| 4803 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4804 | break; |
| 4805 | case Primitive::kPrimBoolean: |
| 4806 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4807 | break; |
| 4808 | case Primitive::kPrimShort: |
| 4809 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4810 | break; |
| 4811 | case Primitive::kPrimChar: |
| 4812 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4813 | break; |
| 4814 | case Primitive::kPrimNot: |
| 4815 | case Primitive::kPrimInt: |
| 4816 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4817 | break; |
| 4818 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4819 | case Primitive::kPrimLong: |
| 4820 | case Primitive::kPrimFloat: |
| 4821 | case Primitive::kPrimDouble: |
| 4822 | default: |
| 4823 | LOG(FATAL) << "Unreachable type " << type; |
| 4824 | UNREACHABLE(); |
| 4825 | } |
| 4826 | } |
| 4827 | |
| 4828 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4829 | Location loc, |
| 4830 | Register base, |
| 4831 | Register reg_offset, |
| 4832 | Condition cond) { |
| 4833 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4834 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4835 | |
| 4836 | switch (type) { |
| 4837 | case Primitive::kPrimByte: |
| 4838 | case Primitive::kPrimBoolean: |
| 4839 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4840 | break; |
| 4841 | case Primitive::kPrimShort: |
| 4842 | case Primitive::kPrimChar: |
| 4843 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4844 | break; |
| 4845 | case Primitive::kPrimNot: |
| 4846 | case Primitive::kPrimInt: |
| 4847 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4848 | break; |
| 4849 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4850 | case Primitive::kPrimLong: |
| 4851 | case Primitive::kPrimFloat: |
| 4852 | case Primitive::kPrimDouble: |
| 4853 | default: |
| 4854 | LOG(FATAL) << "Unreachable type " << type; |
| 4855 | UNREACHABLE(); |
| 4856 | } |
| 4857 | } |
| 4858 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4859 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4860 | bool object_array_get_with_read_barrier = |
| 4861 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4862 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4863 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4864 | object_array_get_with_read_barrier ? |
| 4865 | LocationSummary::kCallOnSlowPath : |
| 4866 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4867 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4868 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4869 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4871 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4872 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4873 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4874 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4875 | // The output overlaps in the case of an object array get with |
| 4876 | // read barriers enabled: we do not want the move to overwrite the |
| 4877 | // array's location, as we need it to emit the read barrier. |
| 4878 | locations->SetOut( |
| 4879 | Location::RequiresRegister(), |
| 4880 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4881 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4882 | // We need a temporary register for the read barrier marking slow |
| 4883 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4884 | // Also need for String compression feature. |
| 4885 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4886 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4887 | locations->AddTemp(Location::RequiresRegister()); |
| 4888 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4892 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4893 | Location obj_loc = locations->InAt(0); |
| 4894 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4895 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4896 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4897 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4898 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4899 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4900 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4901 | HInstruction* array_instr = instruction->GetArray(); |
| 4902 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4903 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4904 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4905 | case Primitive::kPrimBoolean: |
| 4906 | case Primitive::kPrimByte: |
| 4907 | case Primitive::kPrimShort: |
| 4908 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4909 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4910 | Register length; |
| 4911 | if (maybe_compressed_char_at) { |
| 4912 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 4913 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4914 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4915 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4916 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4917 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4918 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4919 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4920 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4921 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4922 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4923 | "Expecting 0=compressed, 1=uncompressed"); |
| 4924 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4925 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4926 | out_loc.AsRegister<Register>(), |
| 4927 | obj, |
| 4928 | data_offset + const_index); |
| 4929 | __ b(&done); |
| 4930 | __ Bind(&uncompressed_load); |
| 4931 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4932 | out_loc.AsRegister<Register>(), |
| 4933 | obj, |
| 4934 | data_offset + (const_index << 1)); |
| 4935 | __ Bind(&done); |
| 4936 | } else { |
| 4937 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4938 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4939 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4940 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4941 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4942 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4943 | Register temp = IP; |
| 4944 | |
| 4945 | if (has_intermediate_address) { |
| 4946 | // We do not need to compute the intermediate address from the array: the |
| 4947 | // input instruction has done it already. See the comment in |
| 4948 | // `TryExtractArrayAccessAddress()`. |
| 4949 | if (kIsDebugBuild) { |
| 4950 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4951 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4952 | } |
| 4953 | temp = obj; |
| 4954 | } else { |
| 4955 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4956 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4957 | if (maybe_compressed_char_at) { |
| 4958 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4959 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4960 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4961 | "Expecting 0=compressed, 1=uncompressed"); |
| 4962 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4963 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4964 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4965 | __ b(&done); |
| 4966 | __ Bind(&uncompressed_load); |
| 4967 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4968 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4969 | __ Bind(&done); |
| 4970 | } else { |
| 4971 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4972 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4973 | } |
| 4974 | break; |
| 4975 | } |
| 4976 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4977 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 4978 | // The read barrier instrumentation of object ArrayGet |
| 4979 | // instructions does not support the HIntermediateAddress |
| 4980 | // instruction. |
| 4981 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 4982 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4983 | static_assert( |
| 4984 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4985 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4986 | // /* HeapReference<Object> */ out = |
| 4987 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4988 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4989 | Location temp = locations->GetTemp(0); |
| 4990 | // Note that a potential implicit null check is handled in this |
| 4991 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4992 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4993 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4994 | } else { |
| 4995 | Register out = out_loc.AsRegister<Register>(); |
| 4996 | if (index.IsConstant()) { |
| 4997 | size_t offset = |
| 4998 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4999 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5000 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5001 | // If read barriers are enabled, emit read barriers other than |
| 5002 | // Baker's using a slow path (and also unpoison the loaded |
| 5003 | // reference, if heap poisoning is enabled). |
| 5004 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5005 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5006 | Register temp = IP; |
| 5007 | |
| 5008 | if (has_intermediate_address) { |
| 5009 | // We do not need to compute the intermediate address from the array: the |
| 5010 | // input instruction has done it already. See the comment in |
| 5011 | // `TryExtractArrayAccessAddress()`. |
| 5012 | if (kIsDebugBuild) { |
| 5013 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5014 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5015 | } |
| 5016 | temp = obj; |
| 5017 | } else { |
| 5018 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5019 | } |
| 5020 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5021 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5022 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5023 | // If read barriers are enabled, emit read barriers other than |
| 5024 | // Baker's using a slow path (and also unpoison the loaded |
| 5025 | // reference, if heap poisoning is enabled). |
| 5026 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5027 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5028 | } |
| 5029 | } |
| 5030 | break; |
| 5031 | } |
| 5032 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5033 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5034 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5035 | size_t offset = |
| 5036 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5037 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5039 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5040 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5041 | } |
| 5042 | break; |
| 5043 | } |
| 5044 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5045 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5046 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5047 | if (index.IsConstant()) { |
| 5048 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5049 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5050 | } else { |
| 5051 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5052 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5053 | } |
| 5054 | break; |
| 5055 | } |
| 5056 | |
| 5057 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5058 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5059 | if (index.IsConstant()) { |
| 5060 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5061 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5062 | } else { |
| 5063 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5064 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5065 | } |
| 5066 | break; |
| 5067 | } |
| 5068 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5070 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5071 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5072 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5073 | |
| 5074 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5075 | // Potential implicit null checks, in the case of reference |
| 5076 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5077 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5078 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5079 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5083 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5084 | |
| 5085 | bool needs_write_barrier = |
| 5086 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5087 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5088 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5089 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5090 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5091 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5092 | LocationSummary::kCallOnSlowPath : |
| 5093 | LocationSummary::kNoCall); |
| 5094 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5096 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5097 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5098 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5099 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5100 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5101 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5102 | if (needs_write_barrier) { |
| 5103 | // Temporary registers for the write barrier. |
| 5104 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5105 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5106 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5110 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5111 | Location array_loc = locations->InAt(0); |
| 5112 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5113 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5114 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5115 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5116 | bool needs_write_barrier = |
| 5117 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5118 | uint32_t data_offset = |
| 5119 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5120 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5121 | HInstruction* array_instr = instruction->GetArray(); |
| 5122 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5123 | |
| 5124 | switch (value_type) { |
| 5125 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5126 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5128 | case Primitive::kPrimChar: |
| 5129 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5130 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5131 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5132 | uint32_t full_offset = |
| 5133 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5134 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5135 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5136 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5137 | Register temp = IP; |
| 5138 | |
| 5139 | if (has_intermediate_address) { |
| 5140 | // We do not need to compute the intermediate address from the array: the |
| 5141 | // input instruction has done it already. See the comment in |
| 5142 | // `TryExtractArrayAccessAddress()`. |
| 5143 | if (kIsDebugBuild) { |
| 5144 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5145 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5146 | } |
| 5147 | temp = array; |
| 5148 | } else { |
| 5149 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5150 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5151 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5152 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5153 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5154 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5155 | } |
| 5156 | break; |
| 5157 | } |
| 5158 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5160 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5161 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5162 | // See the comment in instruction_simplifier_shared.cc. |
| 5163 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5164 | |
| 5165 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5166 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5167 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5168 | size_t offset = |
| 5169 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5170 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5171 | } else { |
| 5172 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5173 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5174 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5175 | value_loc, |
| 5176 | IP, |
| 5177 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5178 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5179 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5180 | DCHECK(!needs_write_barrier); |
| 5181 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5182 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5183 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5184 | |
| 5185 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5186 | Location temp1_loc = locations->GetTemp(0); |
| 5187 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5188 | Location temp2_loc = locations->GetTemp(1); |
| 5189 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5190 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5191 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5192 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5193 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5194 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5195 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5196 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5197 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5198 | codegen_->AddSlowPath(slow_path); |
| 5199 | if (instruction->GetValueCanBeNull()) { |
| 5200 | Label non_zero; |
| 5201 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5202 | if (index.IsConstant()) { |
| 5203 | size_t offset = |
| 5204 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5205 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5206 | } else { |
| 5207 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5208 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5209 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5210 | value_loc, |
| 5211 | IP, |
| 5212 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5213 | } |
| 5214 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5215 | __ b(&done); |
| 5216 | __ Bind(&non_zero); |
| 5217 | } |
| 5218 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5219 | // Note that when read barriers are enabled, the type checks |
| 5220 | // are performed without read barriers. This is fine, even in |
| 5221 | // the case where a class object is in the from-space after |
| 5222 | // the flip, as a comparison involving such a type would not |
| 5223 | // produce a false positive; it may of course produce a false |
| 5224 | // negative, in which case we would take the ArraySet slow |
| 5225 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5226 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5227 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5228 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5229 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5230 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5231 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5232 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5233 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5234 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5235 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5236 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5237 | // nor `temp2`, as we are comparing two poisoned references. |
| 5238 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5239 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5240 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5241 | Label do_put; |
| 5242 | __ b(&do_put, EQ); |
| 5243 | // If heap poisoning is enabled, the `temp1` reference has |
| 5244 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5245 | __ MaybeUnpoisonHeapReference(temp1); |
| 5246 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5247 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5248 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5249 | // If heap poisoning is enabled, no need to unpoison |
| 5250 | // `temp1`, as we are comparing against null below. |
| 5251 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5252 | __ Bind(&do_put); |
| 5253 | } else { |
| 5254 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5255 | } |
| 5256 | } |
| 5257 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5258 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5259 | if (kPoisonHeapReferences) { |
| 5260 | // Note that in the case where `value` is a null reference, |
| 5261 | // we do not enter this block, as a null reference does not |
| 5262 | // need poisoning. |
| 5263 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5264 | __ Mov(temp1, value); |
| 5265 | __ PoisonHeapReference(temp1); |
| 5266 | source = temp1; |
| 5267 | } |
| 5268 | |
| 5269 | if (index.IsConstant()) { |
| 5270 | size_t offset = |
| 5271 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5272 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5273 | } else { |
| 5274 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5275 | |
| 5276 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5277 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5278 | Location::RegisterLocation(source), |
| 5279 | IP, |
| 5280 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5281 | } |
| 5282 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5283 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5284 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5285 | } |
| 5286 | |
| 5287 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5288 | |
| 5289 | if (done.IsLinked()) { |
| 5290 | __ Bind(&done); |
| 5291 | } |
| 5292 | |
| 5293 | if (slow_path != nullptr) { |
| 5294 | __ Bind(slow_path->GetExitLabel()); |
| 5295 | } |
| 5296 | |
| 5297 | break; |
| 5298 | } |
| 5299 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5300 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5301 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5303 | size_t offset = |
| 5304 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5307 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5308 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5309 | } |
| 5310 | break; |
| 5311 | } |
| 5312 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5313 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5314 | Location value = locations->InAt(2); |
| 5315 | DCHECK(value.IsFpuRegister()); |
| 5316 | if (index.IsConstant()) { |
| 5317 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5318 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5319 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5320 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5321 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5322 | } |
| 5323 | break; |
| 5324 | } |
| 5325 | |
| 5326 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5327 | Location value = locations->InAt(2); |
| 5328 | DCHECK(value.IsFpuRegisterPair()); |
| 5329 | if (index.IsConstant()) { |
| 5330 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5331 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5332 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5333 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5334 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5335 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5336 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5337 | break; |
| 5338 | } |
| 5339 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5340 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5341 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5342 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5343 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5344 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5345 | // Objects are handled in the switch. |
| 5346 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5347 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5348 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5352 | LocationSummary* locations = |
| 5353 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5355 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5359 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5360 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5361 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5362 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5363 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5364 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5365 | // Mask out compression flag from String's array length. |
| 5366 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5367 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5368 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5369 | } |
| 5370 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5371 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5372 | LocationSummary* locations = |
| 5373 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5374 | |
| 5375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5376 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5378 | } |
| 5379 | |
| 5380 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5381 | LocationSummary* locations = instruction->GetLocations(); |
| 5382 | Location out = locations->Out(); |
| 5383 | Location first = locations->InAt(0); |
| 5384 | Location second = locations->InAt(1); |
| 5385 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5386 | if (second.IsRegister()) { |
| 5387 | __ add(out.AsRegister<Register>(), |
| 5388 | first.AsRegister<Register>(), |
| 5389 | ShifterOperand(second.AsRegister<Register>())); |
| 5390 | } else { |
| 5391 | __ AddConstant(out.AsRegister<Register>(), |
| 5392 | first.AsRegister<Register>(), |
| 5393 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5394 | } |
| 5395 | } |
| 5396 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5397 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5398 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5399 | InvokeRuntimeCallingConvention calling_convention; |
| 5400 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5401 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5402 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5404 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5408 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5409 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5410 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5411 | codegen_->AddSlowPath(slow_path); |
| 5412 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5413 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5414 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5415 | |
| 5416 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5417 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5418 | } |
| 5419 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5420 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5421 | Register card, |
| 5422 | Register object, |
| 5423 | Register value, |
| 5424 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5425 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5426 | if (can_be_null) { |
| 5427 | __ CompareAndBranchIfZero(value, &is_null); |
| 5428 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5429 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5430 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5431 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5432 | if (can_be_null) { |
| 5433 | __ Bind(&is_null); |
| 5434 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | } |
| 5436 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5437 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5438 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5442 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5443 | } |
| 5444 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5445 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5446 | LocationSummary* locations = |
| 5447 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5448 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5452 | HBasicBlock* block = instruction->GetBlock(); |
| 5453 | if (block->GetLoopInformation() != nullptr) { |
| 5454 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5455 | // The back edge will generate the suspend check. |
| 5456 | return; |
| 5457 | } |
| 5458 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5459 | // The goto will generate the suspend check. |
| 5460 | return; |
| 5461 | } |
| 5462 | GenerateSuspendCheck(instruction, nullptr); |
| 5463 | } |
| 5464 | |
| 5465 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5466 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5467 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5468 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5469 | if (slow_path == nullptr) { |
| 5470 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5471 | instruction->SetSlowPath(slow_path); |
| 5472 | codegen_->AddSlowPath(slow_path); |
| 5473 | if (successor != nullptr) { |
| 5474 | DCHECK(successor->IsLoopHeader()); |
| 5475 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5476 | } |
| 5477 | } else { |
| 5478 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5479 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5480 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5481 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5482 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5483 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5484 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5485 | __ Bind(slow_path->GetReturnLabel()); |
| 5486 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5487 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5488 | __ b(slow_path->GetEntryLabel()); |
| 5489 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5490 | } |
| 5491 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5492 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5493 | return codegen_->GetAssembler(); |
| 5494 | } |
| 5495 | |
| 5496 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5497 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5498 | Location source = move->GetSource(); |
| 5499 | Location destination = move->GetDestination(); |
| 5500 | |
| 5501 | if (source.IsRegister()) { |
| 5502 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5503 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5504 | } else if (destination.IsFpuRegister()) { |
| 5505 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5506 | } else { |
| 5507 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5508 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5509 | SP, destination.GetStackIndex()); |
| 5510 | } |
| 5511 | } else if (source.IsStackSlot()) { |
| 5512 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5513 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5514 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5515 | } else if (destination.IsFpuRegister()) { |
| 5516 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5517 | } else { |
| 5518 | DCHECK(destination.IsStackSlot()); |
| 5519 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5520 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5521 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5522 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5523 | if (destination.IsRegister()) { |
| 5524 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5525 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5526 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5527 | } else { |
| 5528 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5529 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5530 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5531 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5532 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5533 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5534 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5535 | } else if (destination.IsRegisterPair()) { |
| 5536 | DCHECK(ExpectedPairLayout(destination)); |
| 5537 | __ LoadFromOffset( |
| 5538 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5539 | } else { |
| 5540 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5541 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5542 | SP, |
| 5543 | source.GetStackIndex()); |
| 5544 | } |
| 5545 | } else if (source.IsRegisterPair()) { |
| 5546 | if (destination.IsRegisterPair()) { |
| 5547 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5548 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5549 | } else if (destination.IsFpuRegisterPair()) { |
| 5550 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5551 | source.AsRegisterPairLow<Register>(), |
| 5552 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5553 | } else { |
| 5554 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5555 | DCHECK(ExpectedPairLayout(source)); |
| 5556 | __ StoreToOffset( |
| 5557 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5558 | } |
| 5559 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5560 | if (destination.IsRegisterPair()) { |
| 5561 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5562 | destination.AsRegisterPairHigh<Register>(), |
| 5563 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5564 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5565 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5566 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5567 | } else { |
| 5568 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5569 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5570 | SP, |
| 5571 | destination.GetStackIndex()); |
| 5572 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5573 | } else { |
| 5574 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5575 | HConstant* constant = source.GetConstant(); |
| 5576 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5577 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5578 | if (destination.IsRegister()) { |
| 5579 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5580 | } else { |
| 5581 | DCHECK(destination.IsStackSlot()); |
| 5582 | __ LoadImmediate(IP, value); |
| 5583 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5584 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5585 | } else if (constant->IsLongConstant()) { |
| 5586 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5587 | if (destination.IsRegisterPair()) { |
| 5588 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5589 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5590 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5591 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5592 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5593 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5594 | __ LoadImmediate(IP, High32Bits(value)); |
| 5595 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5596 | } |
| 5597 | } else if (constant->IsDoubleConstant()) { |
| 5598 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5599 | if (destination.IsFpuRegisterPair()) { |
| 5600 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5601 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5602 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5603 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5604 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5605 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5606 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5607 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5608 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5609 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5610 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5611 | float value = constant->AsFloatConstant()->GetValue(); |
| 5612 | if (destination.IsFpuRegister()) { |
| 5613 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5614 | } else { |
| 5615 | DCHECK(destination.IsStackSlot()); |
| 5616 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5617 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5618 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5619 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5624 | __ Mov(IP, reg); |
| 5625 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5626 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5627 | } |
| 5628 | |
| 5629 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5630 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5631 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5632 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5633 | SP, mem1 + stack_offset); |
| 5634 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5635 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5636 | SP, mem2 + stack_offset); |
| 5637 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5638 | } |
| 5639 | |
| 5640 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5641 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5642 | Location source = move->GetSource(); |
| 5643 | Location destination = move->GetDestination(); |
| 5644 | |
| 5645 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5646 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5647 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5648 | __ Mov(IP, source.AsRegister<Register>()); |
| 5649 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5650 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5651 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5652 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5653 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5654 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5655 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5656 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5657 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5658 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5659 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5660 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5661 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5662 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5663 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5664 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5665 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5666 | destination.AsRegisterPairHigh<Register>(), |
| 5667 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5668 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5669 | Register low_reg = source.IsRegisterPair() |
| 5670 | ? source.AsRegisterPairLow<Register>() |
| 5671 | : destination.AsRegisterPairLow<Register>(); |
| 5672 | int mem = source.IsRegisterPair() |
| 5673 | ? destination.GetStackIndex() |
| 5674 | : source.GetStackIndex(); |
| 5675 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5676 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5677 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5678 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5679 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5680 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5681 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5682 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5683 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5684 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5685 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5686 | DRegister reg = source.IsFpuRegisterPair() |
| 5687 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5688 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5689 | int mem = source.IsFpuRegisterPair() |
| 5690 | ? destination.GetStackIndex() |
| 5691 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5692 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5693 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5694 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5695 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5696 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5697 | : destination.AsFpuRegister<SRegister>(); |
| 5698 | int mem = source.IsFpuRegister() |
| 5699 | ? destination.GetStackIndex() |
| 5700 | : source.GetStackIndex(); |
| 5701 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5702 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5703 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5704 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5705 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5706 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5707 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5708 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5709 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5714 | __ Push(static_cast<Register>(reg)); |
| 5715 | } |
| 5716 | |
| 5717 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5718 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5719 | } |
| 5720 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5721 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5722 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5723 | switch (desired_class_load_kind) { |
| 5724 | case HLoadClass::LoadKind::kReferrersClass: |
| 5725 | break; |
| 5726 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5727 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5728 | break; |
| 5729 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5730 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5731 | break; |
| 5732 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5733 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5734 | case HLoadClass::LoadKind::kBssEntry: |
| 5735 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5736 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5737 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5738 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5739 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5740 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5741 | break; |
| 5742 | } |
| 5743 | return desired_class_load_kind; |
| 5744 | } |
| 5745 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5746 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5747 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5748 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5749 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5750 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5751 | cls, |
| 5752 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5753 | Location::RegisterLocation(R0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5754 | return; |
| 5755 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5756 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5757 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5758 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5759 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5760 | ? LocationSummary::kCallOnSlowPath |
| 5761 | : LocationSummary::kNoCall; |
| 5762 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5763 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5764 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5765 | } |
| 5766 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5767 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5768 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5769 | } |
| 5770 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5771 | } |
| 5772 | |
| 5773 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
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); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5824 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5825 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5826 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5827 | break; |
| 5828 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5829 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5830 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 5831 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5832 | __ BindTrackedLabel(&labels->movw_label); |
| 5833 | __ movw(out, /* placeholder */ 0u); |
| 5834 | __ BindTrackedLabel(&labels->movt_label); |
| 5835 | __ movt(out, /* placeholder */ 0u); |
| 5836 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5837 | __ add(out, out, ShifterOperand(PC)); |
| 5838 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, kCompilerReadBarrierOption); |
| 5839 | generate_null_check = true; |
| 5840 | break; |
| 5841 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5842 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5843 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5844 | cls->GetTypeIndex(), |
| 5845 | cls->GetAddress())); |
| 5846 | // /* GcRoot<mirror::Class> */ out = *out |
| 5847 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5848 | break; |
| 5849 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5850 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5851 | LOG(FATAL) << "UNREACHABLE"; |
| 5852 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5853 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5854 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5855 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5856 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5857 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5858 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5859 | codegen_->AddSlowPath(slow_path); |
| 5860 | if (generate_null_check) { |
| 5861 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5862 | } |
| 5863 | if (cls->MustGenerateClinitCheck()) { |
| 5864 | GenerateClassInitializationCheck(slow_path, out); |
| 5865 | } else { |
| 5866 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5867 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5872 | LocationSummary* locations = |
| 5873 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5875 | if (check->HasUses()) { |
| 5876 | locations->SetOut(Location::SameAsFirstInput()); |
| 5877 | } |
| 5878 | } |
| 5879 | |
| 5880 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5881 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5882 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5883 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5884 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5885 | GenerateClassInitializationCheck(slow_path, |
| 5886 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5887 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5888 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5889 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5890 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5891 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5892 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5893 | __ b(slow_path->GetEntryLabel(), LT); |
| 5894 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5895 | // properly. Therefore, we do a memory fence. |
| 5896 | __ dmb(ISH); |
| 5897 | __ Bind(slow_path->GetExitLabel()); |
| 5898 | } |
| 5899 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5900 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5901 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5902 | switch (desired_string_load_kind) { |
| 5903 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5904 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5905 | break; |
| 5906 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5907 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5908 | break; |
| 5909 | case HLoadString::LoadKind::kBootImageAddress: |
| 5910 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5911 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5912 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5913 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5914 | case HLoadString::LoadKind::kJitTableAddress: |
| 5915 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5916 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5917 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5918 | break; |
| 5919 | } |
| 5920 | return desired_string_load_kind; |
| 5921 | } |
| 5922 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5923 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5924 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5925 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5926 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5927 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5928 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5929 | } else { |
| 5930 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5931 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5932 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5933 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 5934 | // Note that IP may theoretically be clobbered by saving/restoring the live register |
| 5935 | // (only one thanks to the custom calling convention), so we request a different temp. |
| 5936 | locations->AddTemp(Location::RequiresRegister()); |
| 5937 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5938 | InvokeRuntimeCallingConvention calling_convention; |
| 5939 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5940 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5941 | // that the the kPrimNot result register is the same as the first argument register. |
| 5942 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5943 | } else { |
| 5944 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5945 | } |
| 5946 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5947 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5948 | } |
| 5949 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5950 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5951 | // move. |
| 5952 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5953 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5954 | Location out_loc = locations->Out(); |
| 5955 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5956 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5957 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5958 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5959 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5960 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5961 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5962 | load->GetStringIndex())); |
| 5963 | return; // No dex cache slow path. |
| 5964 | } |
| 5965 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5966 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5967 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5968 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5969 | __ BindTrackedLabel(&labels->movw_label); |
| 5970 | __ movw(out, /* placeholder */ 0u); |
| 5971 | __ BindTrackedLabel(&labels->movt_label); |
| 5972 | __ movt(out, /* placeholder */ 0u); |
| 5973 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5974 | __ add(out, out, ShifterOperand(PC)); |
| 5975 | return; // No dex cache slow path. |
| 5976 | } |
| 5977 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5978 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5979 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5980 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5981 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5982 | return; // No dex cache slow path. |
| 5983 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5984 | case HLoadString::LoadKind::kBssEntry: { |
| 5985 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5986 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5987 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5988 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5989 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5990 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5991 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5992 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5993 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5994 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5995 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5996 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5997 | codegen_->AddSlowPath(slow_path); |
| 5998 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5999 | __ Bind(slow_path->GetExitLabel()); |
| 6000 | return; |
| 6001 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6002 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6003 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6004 | load->GetStringIndex(), |
| 6005 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6006 | // /* GcRoot<mirror::String> */ out = *out |
| 6007 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6008 | return; |
| 6009 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6010 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6011 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6012 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6013 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6014 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6015 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6016 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6017 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6018 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6019 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6020 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6023 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6024 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6025 | } |
| 6026 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6027 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6028 | LocationSummary* locations = |
| 6029 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6030 | locations->SetOut(Location::RequiresRegister()); |
| 6031 | } |
| 6032 | |
| 6033 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6034 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6035 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6036 | } |
| 6037 | |
| 6038 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6039 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6040 | } |
| 6041 | |
| 6042 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6043 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6044 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6045 | } |
| 6046 | |
| 6047 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6048 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6049 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6050 | InvokeRuntimeCallingConvention calling_convention; |
| 6051 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6052 | } |
| 6053 | |
| 6054 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6055 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6056 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6059 | // Temp is used for read barrier. |
| 6060 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6061 | if (kEmitCompilerReadBarrier && |
| 6062 | (kUseBakerReadBarrier || |
| 6063 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6064 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6065 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6066 | return 1; |
| 6067 | } |
| 6068 | return 0; |
| 6069 | } |
| 6070 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6071 | // 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] | 6072 | // interface pointer, one for loading the current interface. |
| 6073 | // The other checks have one temp for loading the object's class. |
| 6074 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6075 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6076 | return 3; |
| 6077 | } |
| 6078 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6081 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6082 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6083 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6084 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6085 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6086 | case TypeCheckKind::kExactCheck: |
| 6087 | case TypeCheckKind::kAbstractClassCheck: |
| 6088 | case TypeCheckKind::kClassHierarchyCheck: |
| 6089 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6090 | call_kind = |
| 6091 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6092 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6093 | break; |
| 6094 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6095 | case TypeCheckKind::kUnresolvedCheck: |
| 6096 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6097 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6098 | break; |
| 6099 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6100 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6101 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6102 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6103 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6104 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6105 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6106 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6107 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6108 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6109 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6110 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6111 | } |
| 6112 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6113 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6114 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6115 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6116 | Location obj_loc = locations->InAt(0); |
| 6117 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6118 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6119 | Location out_loc = locations->Out(); |
| 6120 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6121 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6122 | DCHECK_LE(num_temps, 1u); |
| 6123 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6124 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6125 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6126 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6127 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6128 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6129 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6130 | |
| 6131 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6132 | // avoid null check if we know obj is not null. |
| 6133 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6134 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6135 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6136 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6137 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6138 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6139 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6140 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6141 | out_loc, |
| 6142 | obj_loc, |
| 6143 | class_offset, |
| 6144 | maybe_temp_loc, |
| 6145 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6146 | __ cmp(out, ShifterOperand(cls)); |
| 6147 | // Classes must be equal for the instanceof to succeed. |
| 6148 | __ b(&zero, NE); |
| 6149 | __ LoadImmediate(out, 1); |
| 6150 | __ b(&done); |
| 6151 | break; |
| 6152 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6153 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6154 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6155 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6156 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6157 | out_loc, |
| 6158 | obj_loc, |
| 6159 | class_offset, |
| 6160 | maybe_temp_loc, |
| 6161 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6162 | // If the class is abstract, we eagerly fetch the super class of the |
| 6163 | // object to avoid doing a comparison we know will fail. |
| 6164 | Label loop; |
| 6165 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6166 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6167 | GenerateReferenceLoadOneRegister(instruction, |
| 6168 | out_loc, |
| 6169 | super_offset, |
| 6170 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6171 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6172 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6173 | __ CompareAndBranchIfZero(out, &done); |
| 6174 | __ cmp(out, ShifterOperand(cls)); |
| 6175 | __ b(&loop, NE); |
| 6176 | __ LoadImmediate(out, 1); |
| 6177 | if (zero.IsLinked()) { |
| 6178 | __ b(&done); |
| 6179 | } |
| 6180 | break; |
| 6181 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6182 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6184 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6185 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6186 | out_loc, |
| 6187 | obj_loc, |
| 6188 | class_offset, |
| 6189 | maybe_temp_loc, |
| 6190 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6191 | // Walk over the class hierarchy to find a match. |
| 6192 | Label loop, success; |
| 6193 | __ Bind(&loop); |
| 6194 | __ cmp(out, ShifterOperand(cls)); |
| 6195 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6196 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6197 | GenerateReferenceLoadOneRegister(instruction, |
| 6198 | out_loc, |
| 6199 | super_offset, |
| 6200 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6201 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6202 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6203 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6204 | __ b(&done); |
| 6205 | __ Bind(&success); |
| 6206 | __ LoadImmediate(out, 1); |
| 6207 | if (zero.IsLinked()) { |
| 6208 | __ b(&done); |
| 6209 | } |
| 6210 | break; |
| 6211 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6212 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6213 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6214 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6215 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6216 | out_loc, |
| 6217 | obj_loc, |
| 6218 | class_offset, |
| 6219 | maybe_temp_loc, |
| 6220 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6221 | // Do an exact check. |
| 6222 | Label exact_check; |
| 6223 | __ cmp(out, ShifterOperand(cls)); |
| 6224 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6225 | // 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] | 6226 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6227 | GenerateReferenceLoadOneRegister(instruction, |
| 6228 | out_loc, |
| 6229 | component_offset, |
| 6230 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6231 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6232 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6233 | __ CompareAndBranchIfZero(out, &done); |
| 6234 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6235 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6236 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6237 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6238 | __ LoadImmediate(out, 1); |
| 6239 | __ b(&done); |
| 6240 | break; |
| 6241 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6242 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6243 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6244 | // No read barrier since the slow path will retry upon failure. |
| 6245 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6246 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6247 | out_loc, |
| 6248 | obj_loc, |
| 6249 | class_offset, |
| 6250 | maybe_temp_loc, |
| 6251 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6252 | __ cmp(out, ShifterOperand(cls)); |
| 6253 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6254 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6255 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6256 | codegen_->AddSlowPath(slow_path); |
| 6257 | __ b(slow_path->GetEntryLabel(), NE); |
| 6258 | __ LoadImmediate(out, 1); |
| 6259 | if (zero.IsLinked()) { |
| 6260 | __ b(&done); |
| 6261 | } |
| 6262 | break; |
| 6263 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6264 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6265 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6266 | case TypeCheckKind::kInterfaceCheck: { |
| 6267 | // 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] | 6268 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6269 | // cases. |
| 6270 | // |
| 6271 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6272 | // entry point without resorting to a type checking slow path |
| 6273 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6274 | // require to assign fixed registers for the inputs of this |
| 6275 | // HInstanceOf instruction (following the runtime calling |
| 6276 | // convention), which might be cluttered by the potential first |
| 6277 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6278 | // |
| 6279 | // TODO: Introduce a new runtime entry point taking the object |
| 6280 | // to test (instead of its class) as argument, and let it deal |
| 6281 | // with the read barrier issues. This will let us refactor this |
| 6282 | // case of the `switch` code as it was previously (with a direct |
| 6283 | // call to the runtime not using a type checking slow path). |
| 6284 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6285 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6286 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6287 | /* is_fatal */ false); |
| 6288 | codegen_->AddSlowPath(slow_path); |
| 6289 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6290 | if (zero.IsLinked()) { |
| 6291 | __ b(&done); |
| 6292 | } |
| 6293 | break; |
| 6294 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6295 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6296 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6297 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6298 | __ Bind(&zero); |
| 6299 | __ LoadImmediate(out, 0); |
| 6300 | } |
| 6301 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6302 | if (done.IsLinked()) { |
| 6303 | __ Bind(&done); |
| 6304 | } |
| 6305 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6306 | if (slow_path != nullptr) { |
| 6307 | __ Bind(slow_path->GetExitLabel()); |
| 6308 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6311 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6313 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6314 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6315 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6316 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6317 | case TypeCheckKind::kExactCheck: |
| 6318 | case TypeCheckKind::kAbstractClassCheck: |
| 6319 | case TypeCheckKind::kClassHierarchyCheck: |
| 6320 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6321 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6322 | LocationSummary::kCallOnSlowPath : |
| 6323 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6324 | break; |
| 6325 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6326 | case TypeCheckKind::kUnresolvedCheck: |
| 6327 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6328 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6329 | break; |
| 6330 | } |
| 6331 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6332 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6334 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6335 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6339 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6340 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6341 | Location obj_loc = locations->InAt(0); |
| 6342 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6343 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6344 | Location temp_loc = locations->GetTemp(0); |
| 6345 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6346 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6347 | DCHECK_LE(num_temps, 3u); |
| 6348 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6349 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6350 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6351 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6352 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6353 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6354 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6355 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6356 | const uint32_t object_array_data_offset = |
| 6357 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6358 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6359 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6360 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6361 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6362 | bool is_type_check_slow_path_fatal = false; |
| 6363 | if (!kEmitCompilerReadBarrier) { |
| 6364 | is_type_check_slow_path_fatal = |
| 6365 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6366 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6367 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6368 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6369 | !instruction->CanThrowIntoCatchBlock(); |
| 6370 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6371 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6372 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6373 | is_type_check_slow_path_fatal); |
| 6374 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6375 | |
| 6376 | Label done; |
| 6377 | // Avoid null check if we know obj is not null. |
| 6378 | if (instruction->MustDoNullCheck()) { |
| 6379 | __ CompareAndBranchIfZero(obj, &done); |
| 6380 | } |
| 6381 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6382 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6383 | case TypeCheckKind::kExactCheck: |
| 6384 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6385 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6386 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6387 | temp_loc, |
| 6388 | obj_loc, |
| 6389 | class_offset, |
| 6390 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6391 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6392 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6393 | __ cmp(temp, ShifterOperand(cls)); |
| 6394 | // Jump to slow path for throwing the exception or doing a |
| 6395 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6396 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6397 | break; |
| 6398 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6399 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6400 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6401 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6402 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6403 | temp_loc, |
| 6404 | obj_loc, |
| 6405 | class_offset, |
| 6406 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6407 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6408 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6409 | // If the class is abstract, we eagerly fetch the super class of the |
| 6410 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6411 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6412 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6413 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6414 | GenerateReferenceLoadOneRegister(instruction, |
| 6415 | temp_loc, |
| 6416 | super_offset, |
| 6417 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6418 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6419 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6420 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6421 | // exception. |
| 6422 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6423 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6424 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6425 | __ cmp(temp, ShifterOperand(cls)); |
| 6426 | __ b(&loop, NE); |
| 6427 | break; |
| 6428 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6429 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6430 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6431 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6432 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6433 | temp_loc, |
| 6434 | obj_loc, |
| 6435 | class_offset, |
| 6436 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6437 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6438 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6439 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6440 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6441 | __ Bind(&loop); |
| 6442 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6443 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6444 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6445 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6446 | GenerateReferenceLoadOneRegister(instruction, |
| 6447 | temp_loc, |
| 6448 | super_offset, |
| 6449 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6450 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6451 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6452 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6453 | // exception. |
| 6454 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6455 | // Otherwise, jump to the beginning of the loop. |
| 6456 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6457 | break; |
| 6458 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6459 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6460 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6461 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6462 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6463 | temp_loc, |
| 6464 | obj_loc, |
| 6465 | class_offset, |
| 6466 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6467 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6468 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6469 | // Do an exact check. |
| 6470 | __ cmp(temp, ShifterOperand(cls)); |
| 6471 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6472 | |
| 6473 | // 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] | 6474 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6475 | GenerateReferenceLoadOneRegister(instruction, |
| 6476 | temp_loc, |
| 6477 | component_offset, |
| 6478 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6479 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6480 | // If the component type is null, jump to the slow path to throw the exception. |
| 6481 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6482 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6483 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6484 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6485 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6486 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6487 | break; |
| 6488 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6489 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6490 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6491 | // 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] | 6492 | // We cannot directly call the CheckCast runtime entry point |
| 6493 | // without resorting to a type checking slow path here (i.e. by |
| 6494 | // calling InvokeRuntime directly), as it would require to |
| 6495 | // assign fixed registers for the inputs of this HInstanceOf |
| 6496 | // instruction (following the runtime calling convention), which |
| 6497 | // might be cluttered by the potential first read barrier |
| 6498 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6499 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6500 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6501 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6502 | |
| 6503 | case TypeCheckKind::kInterfaceCheck: { |
| 6504 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6505 | // positives by doing this. |
| 6506 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6507 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6508 | temp_loc, |
| 6509 | obj_loc, |
| 6510 | class_offset, |
| 6511 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6512 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6513 | |
| 6514 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6515 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6516 | temp_loc, |
| 6517 | temp_loc, |
| 6518 | iftable_offset, |
| 6519 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6520 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6521 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6522 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6523 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6524 | Label start_loop; |
| 6525 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6526 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 6527 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6528 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6529 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6530 | // Go to next interface. |
| 6531 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 6532 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 6533 | maybe_temp2_loc.AsRegister<Register>(), |
| 6534 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6535 | // Compare the classes and continue the loop if they do not match. |
| 6536 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 6537 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6538 | break; |
| 6539 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6540 | } |
| 6541 | __ Bind(&done); |
| 6542 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6543 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6544 | } |
| 6545 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6546 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6547 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6548 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6549 | InvokeRuntimeCallingConvention calling_convention; |
| 6550 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6551 | } |
| 6552 | |
| 6553 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6554 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6555 | instruction, |
| 6556 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6557 | if (instruction->IsEnter()) { |
| 6558 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6559 | } else { |
| 6560 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6561 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6562 | } |
| 6563 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6564 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6565 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6566 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6567 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6568 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6569 | LocationSummary* locations = |
| 6570 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6571 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6572 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6573 | // 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] | 6574 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6575 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6577 | } |
| 6578 | |
| 6579 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6580 | HandleBitwiseOperation(instruction); |
| 6581 | } |
| 6582 | |
| 6583 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6584 | HandleBitwiseOperation(instruction); |
| 6585 | } |
| 6586 | |
| 6587 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6588 | HandleBitwiseOperation(instruction); |
| 6589 | } |
| 6590 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6591 | |
| 6592 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6593 | LocationSummary* locations = |
| 6594 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6595 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6596 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6597 | |
| 6598 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6599 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6600 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6601 | } |
| 6602 | |
| 6603 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6604 | LocationSummary* locations = instruction->GetLocations(); |
| 6605 | Location first = locations->InAt(0); |
| 6606 | Location second = locations->InAt(1); |
| 6607 | Location out = locations->Out(); |
| 6608 | |
| 6609 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6610 | Register first_reg = first.AsRegister<Register>(); |
| 6611 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6612 | Register out_reg = out.AsRegister<Register>(); |
| 6613 | |
| 6614 | switch (instruction->GetOpKind()) { |
| 6615 | case HInstruction::kAnd: |
| 6616 | __ bic(out_reg, first_reg, second_reg); |
| 6617 | break; |
| 6618 | case HInstruction::kOr: |
| 6619 | __ orn(out_reg, first_reg, second_reg); |
| 6620 | break; |
| 6621 | // There is no EON on arm. |
| 6622 | case HInstruction::kXor: |
| 6623 | default: |
| 6624 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6625 | UNREACHABLE(); |
| 6626 | } |
| 6627 | return; |
| 6628 | |
| 6629 | } else { |
| 6630 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6631 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6632 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6633 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6634 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6635 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6636 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6637 | |
| 6638 | switch (instruction->GetOpKind()) { |
| 6639 | case HInstruction::kAnd: |
| 6640 | __ bic(out_low, first_low, second_low); |
| 6641 | __ bic(out_high, first_high, second_high); |
| 6642 | break; |
| 6643 | case HInstruction::kOr: |
| 6644 | __ orn(out_low, first_low, second_low); |
| 6645 | __ orn(out_high, first_high, second_high); |
| 6646 | break; |
| 6647 | // There is no EON on arm. |
| 6648 | case HInstruction::kXor: |
| 6649 | default: |
| 6650 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6651 | UNREACHABLE(); |
| 6652 | } |
| 6653 | } |
| 6654 | } |
| 6655 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6656 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6657 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6658 | if (value == 0xffffffffu) { |
| 6659 | if (out != first) { |
| 6660 | __ mov(out, ShifterOperand(first)); |
| 6661 | } |
| 6662 | return; |
| 6663 | } |
| 6664 | if (value == 0u) { |
| 6665 | __ mov(out, ShifterOperand(0)); |
| 6666 | return; |
| 6667 | } |
| 6668 | ShifterOperand so; |
| 6669 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6670 | __ and_(out, first, so); |
| 6671 | } else { |
| 6672 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6673 | __ bic(out, first, ShifterOperand(~value)); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6678 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6679 | if (value == 0u) { |
| 6680 | if (out != first) { |
| 6681 | __ mov(out, ShifterOperand(first)); |
| 6682 | } |
| 6683 | return; |
| 6684 | } |
| 6685 | if (value == 0xffffffffu) { |
| 6686 | __ mvn(out, ShifterOperand(0)); |
| 6687 | return; |
| 6688 | } |
| 6689 | ShifterOperand so; |
| 6690 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6691 | __ orr(out, first, so); |
| 6692 | } else { |
| 6693 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6694 | __ orn(out, first, ShifterOperand(~value)); |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6699 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6700 | if (value == 0u) { |
| 6701 | if (out != first) { |
| 6702 | __ mov(out, ShifterOperand(first)); |
| 6703 | } |
| 6704 | return; |
| 6705 | } |
| 6706 | __ eor(out, first, ShifterOperand(value)); |
| 6707 | } |
| 6708 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6709 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6710 | Location first, |
| 6711 | uint64_t value) { |
| 6712 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6713 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6714 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6715 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6716 | uint32_t value_low = Low32Bits(value); |
| 6717 | uint32_t value_high = High32Bits(value); |
| 6718 | if (value_low == 0u) { |
| 6719 | if (out_low != first_low) { |
| 6720 | __ mov(out_low, ShifterOperand(first_low)); |
| 6721 | } |
| 6722 | __ AddConstant(out_high, first_high, value_high); |
| 6723 | return; |
| 6724 | } |
| 6725 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6726 | ShifterOperand so; |
| 6727 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6728 | __ adc(out_high, first_high, so); |
| 6729 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6730 | __ sbc(out_high, first_high, so); |
| 6731 | } else { |
| 6732 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6733 | UNREACHABLE(); |
| 6734 | } |
| 6735 | } |
| 6736 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6737 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6738 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6739 | Location first = locations->InAt(0); |
| 6740 | Location second = locations->InAt(1); |
| 6741 | Location out = locations->Out(); |
| 6742 | |
| 6743 | if (second.IsConstant()) { |
| 6744 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6745 | uint32_t value_low = Low32Bits(value); |
| 6746 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6747 | Register first_reg = first.AsRegister<Register>(); |
| 6748 | Register out_reg = out.AsRegister<Register>(); |
| 6749 | if (instruction->IsAnd()) { |
| 6750 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6751 | } else if (instruction->IsOr()) { |
| 6752 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6753 | } else { |
| 6754 | DCHECK(instruction->IsXor()); |
| 6755 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6756 | } |
| 6757 | } else { |
| 6758 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6759 | uint32_t value_high = High32Bits(value); |
| 6760 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6761 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6762 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6763 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6764 | if (instruction->IsAnd()) { |
| 6765 | GenerateAndConst(out_low, first_low, value_low); |
| 6766 | GenerateAndConst(out_high, first_high, value_high); |
| 6767 | } else if (instruction->IsOr()) { |
| 6768 | GenerateOrrConst(out_low, first_low, value_low); |
| 6769 | GenerateOrrConst(out_high, first_high, value_high); |
| 6770 | } else { |
| 6771 | DCHECK(instruction->IsXor()); |
| 6772 | GenerateEorConst(out_low, first_low, value_low); |
| 6773 | GenerateEorConst(out_high, first_high, value_high); |
| 6774 | } |
| 6775 | } |
| 6776 | return; |
| 6777 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6778 | |
| 6779 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6780 | Register first_reg = first.AsRegister<Register>(); |
| 6781 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6782 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6783 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6784 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6785 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6786 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6787 | } else { |
| 6788 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6789 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6790 | } |
| 6791 | } else { |
| 6792 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6793 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6794 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6795 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6796 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6797 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6798 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6799 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6800 | __ and_(out_low, first_low, second_low); |
| 6801 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6802 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6803 | __ orr(out_low, first_low, second_low); |
| 6804 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6805 | } else { |
| 6806 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6807 | __ eor(out_low, first_low, second_low); |
| 6808 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6809 | } |
| 6810 | } |
| 6811 | } |
| 6812 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6813 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 6814 | HInstruction* instruction, |
| 6815 | Location out, |
| 6816 | uint32_t offset, |
| 6817 | Location maybe_temp, |
| 6818 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6819 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6820 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6821 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6822 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6823 | if (kUseBakerReadBarrier) { |
| 6824 | // Load with fast path based Baker's read barrier. |
| 6825 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6826 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6827 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6828 | } else { |
| 6829 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6830 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6831 | // in the following move operation, as we will need it for the |
| 6832 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6833 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6834 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6835 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6836 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6837 | } |
| 6838 | } else { |
| 6839 | // Plain load with no read barrier. |
| 6840 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6841 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6842 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6843 | } |
| 6844 | } |
| 6845 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6846 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 6847 | HInstruction* instruction, |
| 6848 | Location out, |
| 6849 | Location obj, |
| 6850 | uint32_t offset, |
| 6851 | Location maybe_temp, |
| 6852 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6853 | Register out_reg = out.AsRegister<Register>(); |
| 6854 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6855 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6856 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6857 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6858 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6859 | // Load with fast path based Baker's read barrier. |
| 6860 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6861 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6862 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6863 | } else { |
| 6864 | // Load with slow path based read barrier. |
| 6865 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6866 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6867 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6868 | } |
| 6869 | } else { |
| 6870 | // Plain load with no read barrier. |
| 6871 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6872 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6873 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6874 | } |
| 6875 | } |
| 6876 | |
| 6877 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6878 | Location root, |
| 6879 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6880 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6881 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6882 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6883 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6884 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6885 | if (kUseBakerReadBarrier) { |
| 6886 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6887 | // Baker's read barrier are used: |
| 6888 | // |
| 6889 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6890 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6891 | // if (temp != null) { |
| 6892 | // root = temp(root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6893 | // } |
| 6894 | |
| 6895 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6896 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6897 | static_assert( |
| 6898 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6899 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6900 | "have different sizes."); |
| 6901 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6902 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6903 | "have different sizes."); |
| 6904 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6905 | // Slow path marking the GC root `root`. |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6906 | Location temp = Location::RegisterLocation(LR); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6907 | SlowPathCodeARM* slow_path = |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6908 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 6909 | instruction, |
| 6910 | root, |
| 6911 | /*entrypoint*/ temp); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6912 | codegen_->AddSlowPath(slow_path); |
| 6913 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6914 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6915 | const int32_t entry_point_offset = |
| 6916 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 6917 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6918 | // threads are suspended or running a checkpoint. |
| 6919 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6920 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6921 | // checking GetIsGcMarking. |
| 6922 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6923 | __ Bind(slow_path->GetExitLabel()); |
| 6924 | } else { |
| 6925 | // GC root loaded through a slow path for read barriers other |
| 6926 | // than Baker's. |
| 6927 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6928 | __ AddConstant(root_reg, obj, offset); |
| 6929 | // /* mirror::Object* */ root = root->Read() |
| 6930 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6931 | } |
| 6932 | } else { |
| 6933 | // Plain GC root load with no read barrier. |
| 6934 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6935 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6936 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6937 | // do not have to unpoison `root_reg` here. |
| 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6942 | Location ref, |
| 6943 | Register obj, |
| 6944 | uint32_t offset, |
| 6945 | Location temp, |
| 6946 | bool needs_null_check) { |
| 6947 | DCHECK(kEmitCompilerReadBarrier); |
| 6948 | DCHECK(kUseBakerReadBarrier); |
| 6949 | |
| 6950 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6951 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6952 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6953 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6954 | 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] | 6955 | } |
| 6956 | |
| 6957 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6958 | Location ref, |
| 6959 | Register obj, |
| 6960 | uint32_t data_offset, |
| 6961 | Location index, |
| 6962 | Location temp, |
| 6963 | bool needs_null_check) { |
| 6964 | DCHECK(kEmitCompilerReadBarrier); |
| 6965 | DCHECK(kUseBakerReadBarrier); |
| 6966 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6967 | static_assert( |
| 6968 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6969 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6970 | // /* HeapReference<Object> */ ref = |
| 6971 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6972 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6973 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6974 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6978 | Location ref, |
| 6979 | Register obj, |
| 6980 | uint32_t offset, |
| 6981 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6982 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6983 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6984 | bool needs_null_check, |
| 6985 | bool always_update_field, |
| 6986 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6987 | DCHECK(kEmitCompilerReadBarrier); |
| 6988 | DCHECK(kUseBakerReadBarrier); |
| 6989 | |
| 6990 | // In slow path based read barriers, the read barrier call is |
| 6991 | // inserted after the original load. However, in fast path based |
| 6992 | // Baker's read barriers, we need to perform the load of |
| 6993 | // mirror::Object::monitor_ *before* the original reference load. |
| 6994 | // This load-load ordering is required by the read barrier. |
| 6995 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6996 | // |
| 6997 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6998 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6999 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7000 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7001 | // if (is_gray) { |
| 7002 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7003 | // } |
| 7004 | // |
| 7005 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7006 | // slightly more complex as it performs additional checks that we do |
| 7007 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7008 | |
| 7009 | Register ref_reg = ref.AsRegister<Register>(); |
| 7010 | Register temp_reg = temp.AsRegister<Register>(); |
| 7011 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7012 | |
| 7013 | // /* int32_t */ monitor = obj->monitor_ |
| 7014 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7015 | if (needs_null_check) { |
| 7016 | MaybeRecordImplicitNullCheck(instruction); |
| 7017 | } |
| 7018 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7019 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7020 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7021 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7022 | // Introduce a dependency on the lock_word including the rb_state, |
| 7023 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7024 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 7025 | // `obj` is unchanged by this operation, but its value now depends |
| 7026 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7027 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7028 | |
| 7029 | // The actual reference load. |
| 7030 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7031 | // Load types involving an "index": ArrayGet, |
| 7032 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7033 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7034 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7035 | if (index.IsConstant()) { |
| 7036 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7037 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7038 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7039 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7040 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7041 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7042 | // intrinsics, which use a register pair as index ("long |
| 7043 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7044 | Register index_reg = index.IsRegisterPair() |
| 7045 | ? index.AsRegisterPairLow<Register>() |
| 7046 | : index.AsRegister<Register>(); |
| 7047 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7048 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7049 | } |
| 7050 | } else { |
| 7051 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7052 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7053 | } |
| 7054 | |
| 7055 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7056 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7057 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7058 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7059 | SlowPathCodeARM* slow_path; |
| 7060 | if (always_update_field) { |
| 7061 | DCHECK(temp2 != nullptr); |
| 7062 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 7063 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7064 | // `field_offset` is a register pair (of which only the lower half |
| 7065 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7066 | // to be null in this code path. |
| 7067 | DCHECK_EQ(offset, 0u); |
| 7068 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7069 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 7070 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7071 | } else { |
| 7072 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 7073 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7074 | AddSlowPath(slow_path); |
| 7075 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7076 | // if (rb_state == ReadBarrier::GrayState()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7077 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7078 | // Given the numeric representation, it's enough to check the low bit of the |
| 7079 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7080 | // which can be a 16-bit instruction unlike the TST immediate. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7081 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7082 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7083 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7084 | __ 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] | 7085 | __ Bind(slow_path->GetExitLabel()); |
| 7086 | } |
| 7087 | |
| 7088 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7089 | Location out, |
| 7090 | Location ref, |
| 7091 | Location obj, |
| 7092 | uint32_t offset, |
| 7093 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7094 | DCHECK(kEmitCompilerReadBarrier); |
| 7095 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7096 | // Insert a slow path based read barrier *after* the reference load. |
| 7097 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7098 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7099 | // reference will be carried out by the runtime within the slow |
| 7100 | // path. |
| 7101 | // |
| 7102 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7103 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7104 | // not used by the artReadBarrierSlow entry point. |
| 7105 | // |
| 7106 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7107 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7108 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7109 | AddSlowPath(slow_path); |
| 7110 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7111 | __ b(slow_path->GetEntryLabel()); |
| 7112 | __ Bind(slow_path->GetExitLabel()); |
| 7113 | } |
| 7114 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7115 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7116 | Location out, |
| 7117 | Location ref, |
| 7118 | Location obj, |
| 7119 | uint32_t offset, |
| 7120 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7121 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7122 | // Baker's read barriers shall be handled by the fast path |
| 7123 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7124 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7125 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7126 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7127 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7128 | } else if (kPoisonHeapReferences) { |
| 7129 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7130 | } |
| 7131 | } |
| 7132 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7133 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7134 | Location out, |
| 7135 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7136 | DCHECK(kEmitCompilerReadBarrier); |
| 7137 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7138 | // Insert a slow path based read barrier *after* the GC root load. |
| 7139 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7140 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7141 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7142 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7143 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7144 | AddSlowPath(slow_path); |
| 7145 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7146 | __ b(slow_path->GetEntryLabel()); |
| 7147 | __ Bind(slow_path->GetExitLabel()); |
| 7148 | } |
| 7149 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7150 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7151 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7152 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7153 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 7154 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 7155 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7156 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 7157 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7158 | if (GetGraph()->HasIrreducibleLoops() && |
| 7159 | (dispatch_info.method_load_kind == |
| 7160 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 7161 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 7162 | } |
| 7163 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7164 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7165 | } |
| 7166 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7167 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7168 | Register temp) { |
| 7169 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7170 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7171 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7172 | return location.AsRegister<Register>(); |
| 7173 | } |
| 7174 | // For intrinsics we allow any location, so it may be on the stack. |
| 7175 | if (!location.IsRegister()) { |
| 7176 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7177 | return temp; |
| 7178 | } |
| 7179 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7180 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7181 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7182 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7183 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7184 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7185 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7186 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7187 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7188 | return temp; |
| 7189 | } |
| 7190 | return location.AsRegister<Register>(); |
| 7191 | } |
| 7192 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 7193 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7194 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7195 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7196 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7197 | uint32_t offset = |
| 7198 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7199 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7200 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7201 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7202 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7203 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7204 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7205 | break; |
| 7206 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7207 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7208 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7209 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7210 | HArmDexCacheArraysBase* base = |
| 7211 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7212 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7213 | temp.AsRegister<Register>()); |
| 7214 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7215 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7216 | break; |
| 7217 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7218 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7219 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7220 | Register method_reg; |
| 7221 | Register reg = temp.AsRegister<Register>(); |
| 7222 | if (current_method.IsRegister()) { |
| 7223 | method_reg = current_method.AsRegister<Register>(); |
| 7224 | } else { |
| 7225 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7226 | DCHECK(!current_method.IsValid()); |
| 7227 | method_reg = reg; |
| 7228 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7229 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7230 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7231 | __ LoadFromOffset(kLoadWord, |
| 7232 | reg, |
| 7233 | method_reg, |
| 7234 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7235 | // temp = temp[index_in_cache]; |
| 7236 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7237 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7238 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7239 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7240 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | switch (invoke->GetCodePtrLocation()) { |
| 7244 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7245 | __ bl(GetFrameEntryLabel()); |
| 7246 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7247 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7248 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7249 | __ LoadFromOffset( |
| 7250 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7251 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7252 | // LR() |
| 7253 | __ blx(LR); |
| 7254 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7255 | } |
| 7256 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7257 | DCHECK(!IsLeafMethod()); |
| 7258 | } |
| 7259 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7260 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7261 | Register temp = temp_location.AsRegister<Register>(); |
| 7262 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7263 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7264 | |
| 7265 | // Use the calling convention instead of the location of the receiver, as |
| 7266 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7267 | // slow path, the arguments have been moved to the right place, so here we are |
| 7268 | // guaranteed that the receiver is the first register of the calling convention. |
| 7269 | InvokeDexCallingConvention calling_convention; |
| 7270 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7271 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7272 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7273 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7274 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7275 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7276 | // emit a read barrier for the previous class reference load. |
| 7277 | // However this is not required in practice, as this is an |
| 7278 | // intermediate/temporary reference and because the current |
| 7279 | // concurrent copying collector keeps the from-space memory |
| 7280 | // intact/accessible until the end of the marking phase (the |
| 7281 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7282 | __ MaybeUnpoisonHeapReference(temp); |
| 7283 | // temp = temp->GetMethodAt(method_offset); |
| 7284 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7285 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7286 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7287 | // LR = temp->GetEntryPoint(); |
| 7288 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7289 | // LR(); |
| 7290 | __ blx(LR); |
| 7291 | } |
| 7292 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7293 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7294 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7295 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7296 | } |
| 7297 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7298 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7299 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7300 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7301 | } |
| 7302 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 7303 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 7304 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7305 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7306 | } |
| 7307 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7308 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7309 | const DexFile& dex_file, uint32_t element_offset) { |
| 7310 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7311 | } |
| 7312 | |
| 7313 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7314 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7315 | patches->emplace_back(dex_file, offset_or_index); |
| 7316 | return &patches->back(); |
| 7317 | } |
| 7318 | |
| 7319 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7320 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7321 | return boot_image_string_patches_.GetOrCreate( |
| 7322 | StringReference(&dex_file, string_index), |
| 7323 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7324 | } |
| 7325 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7326 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7327 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7328 | return boot_image_type_patches_.GetOrCreate( |
| 7329 | TypeReference(&dex_file, type_index), |
| 7330 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7331 | } |
| 7332 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7333 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7334 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7335 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7336 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7337 | } |
| 7338 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7339 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7340 | dex::StringIndex string_index, |
| 7341 | Handle<mirror::String> handle) { |
| 7342 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7343 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7344 | return jit_string_patches_.GetOrCreate( |
| 7345 | StringReference(&dex_file, string_index), |
| 7346 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7347 | } |
| 7348 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7349 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7350 | dex::TypeIndex type_index, |
| 7351 | uint64_t address) { |
| 7352 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), address); |
| 7353 | return jit_class_patches_.GetOrCreate( |
| 7354 | TypeReference(&dex_file, type_index), |
| 7355 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7356 | } |
| 7357 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7358 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7359 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7360 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7361 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7362 | for (const PcRelativePatchInfo& info : infos) { |
| 7363 | const DexFile& dex_file = info.target_dex_file; |
| 7364 | size_t offset_or_index = info.offset_or_index; |
| 7365 | DCHECK(info.add_pc_label.IsBound()); |
| 7366 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7367 | // Add MOVW patch. |
| 7368 | DCHECK(info.movw_label.IsBound()); |
| 7369 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7370 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7371 | // Add MOVT patch. |
| 7372 | DCHECK(info.movt_label.IsBound()); |
| 7373 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7374 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7375 | } |
| 7376 | } |
| 7377 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7378 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7379 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7380 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7381 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7382 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7383 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7384 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7385 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 7386 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7387 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7388 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7389 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7390 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7391 | for (const auto& entry : boot_image_string_patches_) { |
| 7392 | const StringReference& target_string = entry.first; |
| 7393 | Literal* literal = entry.second; |
| 7394 | DCHECK(literal->GetLabel()->IsBound()); |
| 7395 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7396 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7397 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7398 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7399 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7400 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 7401 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7402 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7403 | linker_patches); |
| 7404 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7405 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7406 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7407 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7408 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7409 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 7410 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7411 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7412 | for (const auto& entry : boot_image_type_patches_) { |
| 7413 | const TypeReference& target_type = entry.first; |
| 7414 | Literal* literal = entry.second; |
| 7415 | DCHECK(literal->GetLabel()->IsBound()); |
| 7416 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7417 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7418 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7419 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7420 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7421 | for (const auto& entry : boot_image_address_patches_) { |
| 7422 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7423 | Literal* literal = entry.second; |
| 7424 | DCHECK(literal->GetLabel()->IsBound()); |
| 7425 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7426 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7427 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame^] | 7428 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7432 | return map->GetOrCreate( |
| 7433 | value, |
| 7434 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7435 | } |
| 7436 | |
| 7437 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7438 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7439 | return map->GetOrCreate( |
| 7440 | target_method, |
| 7441 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7442 | } |
| 7443 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7444 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7445 | LocationSummary* locations = |
| 7446 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7447 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7448 | Location::RequiresRegister()); |
| 7449 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7450 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7451 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7452 | } |
| 7453 | |
| 7454 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7455 | LocationSummary* locations = instr->GetLocations(); |
| 7456 | Register res = locations->Out().AsRegister<Register>(); |
| 7457 | Register accumulator = |
| 7458 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7459 | Register mul_left = |
| 7460 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7461 | Register mul_right = |
| 7462 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7463 | |
| 7464 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7465 | __ mla(res, mul_left, mul_right, accumulator); |
| 7466 | } else { |
| 7467 | __ mls(res, mul_left, mul_right, accumulator); |
| 7468 | } |
| 7469 | } |
| 7470 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7471 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7472 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7473 | LOG(FATAL) << "Unreachable"; |
| 7474 | } |
| 7475 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7476 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7477 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7478 | LOG(FATAL) << "Unreachable"; |
| 7479 | } |
| 7480 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7481 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7482 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7483 | LocationSummary* locations = |
| 7484 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7485 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7486 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7487 | codegen_->GetAssembler()->IsThumb()) { |
| 7488 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7489 | if (switch_instr->GetStartValue() != 0) { |
| 7490 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7491 | } |
| 7492 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7496 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7497 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7498 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7499 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7500 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7501 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7502 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7503 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7504 | Register temp_reg = IP; |
| 7505 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7506 | // the immediate, because IP is used as the destination register. For the other |
| 7507 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7508 | // and they can be encoded in the instruction without making use of IP register. |
| 7509 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7510 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7511 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7512 | // Jump to successors[0] if value == lower_bound. |
| 7513 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7514 | int32_t last_index = 0; |
| 7515 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7516 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7517 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7518 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7519 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7520 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7521 | } |
| 7522 | if (num_entries - last_index == 2) { |
| 7523 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7524 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7525 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7526 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7527 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7528 | // And the default for any other value. |
| 7529 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7530 | __ b(codegen_->GetLabelOf(default_block)); |
| 7531 | } |
| 7532 | } else { |
| 7533 | // Create a table lookup. |
| 7534 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7535 | |
| 7536 | // Materialize a pointer to the switch table |
| 7537 | std::vector<Label*> labels(num_entries); |
| 7538 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7539 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7540 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7541 | } |
| 7542 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7543 | |
| 7544 | // Remove the bias. |
| 7545 | Register key_reg; |
| 7546 | if (lower_bound != 0) { |
| 7547 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7548 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7549 | } else { |
| 7550 | key_reg = value_reg; |
| 7551 | } |
| 7552 | |
| 7553 | // Check whether the value is in the table, jump to default block if not. |
| 7554 | __ CmpConstant(key_reg, num_entries - 1); |
| 7555 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7556 | |
| 7557 | // Load the displacement from the table. |
| 7558 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7559 | |
| 7560 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7561 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7562 | } |
| 7563 | } |
| 7564 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7565 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7566 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7567 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7568 | } |
| 7569 | |
| 7570 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7571 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7572 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7573 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7574 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7575 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7576 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7577 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7578 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7579 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7580 | } |
| 7581 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7582 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7583 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7584 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7585 | return; |
| 7586 | } |
| 7587 | |
| 7588 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7589 | |
| 7590 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7591 | if (return_loc.Equals(trg)) { |
| 7592 | return; |
| 7593 | } |
| 7594 | |
| 7595 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7596 | // with the last branch. |
| 7597 | if (type == Primitive::kPrimLong) { |
| 7598 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7599 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7600 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7601 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7602 | } else if (type == Primitive::kPrimDouble) { |
| 7603 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7604 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7605 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7606 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7607 | } else { |
| 7608 | // Let the parallel move resolver take care of all of this. |
| 7609 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7610 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7611 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7612 | } |
| 7613 | } |
| 7614 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7615 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7616 | LocationSummary* locations = |
| 7617 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7619 | locations->SetOut(Location::RequiresRegister()); |
| 7620 | } |
| 7621 | |
| 7622 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7623 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7624 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7625 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7626 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7627 | __ LoadFromOffset(kLoadWord, |
| 7628 | locations->Out().AsRegister<Register>(), |
| 7629 | locations->InAt(0).AsRegister<Register>(), |
| 7630 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7631 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7632 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7633 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7634 | __ LoadFromOffset(kLoadWord, |
| 7635 | locations->Out().AsRegister<Register>(), |
| 7636 | locations->InAt(0).AsRegister<Register>(), |
| 7637 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7638 | __ LoadFromOffset(kLoadWord, |
| 7639 | locations->Out().AsRegister<Register>(), |
| 7640 | locations->Out().AsRegister<Register>(), |
| 7641 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7642 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7643 | } |
| 7644 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7645 | static void PatchJitRootUse(uint8_t* code, |
| 7646 | const uint8_t* roots_data, |
| 7647 | Literal* literal, |
| 7648 | uint64_t index_in_table) { |
| 7649 | DCHECK(literal->GetLabel()->IsBound()); |
| 7650 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7651 | uintptr_t address = |
| 7652 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7653 | uint8_t* data = code + literal_offset; |
| 7654 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 7655 | } |
| 7656 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7657 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7658 | for (const auto& entry : jit_string_patches_) { |
| 7659 | const auto& it = jit_string_roots_.find(entry.first); |
| 7660 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7661 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 7662 | } |
| 7663 | for (const auto& entry : jit_class_patches_) { |
| 7664 | const auto& it = jit_class_roots_.find(entry.first); |
| 7665 | DCHECK(it != jit_class_roots_.end()); |
| 7666 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7667 | } |
| 7668 | } |
| 7669 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7670 | #undef __ |
| 7671 | #undef QUICK_ENTRY_POINT |
| 7672 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7673 | } // namespace arm |
| 7674 | } // namespace art |