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: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 370 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 371 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 372 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 373 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 374 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 375 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 376 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 377 | Location out = locations->Out(); |
| 378 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 379 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 380 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 381 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 382 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 383 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 384 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 385 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 386 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 387 | bool is_load_class_bss_entry = |
| 388 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 389 | Register entry_address = kNoRegister; |
| 390 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 391 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 392 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 393 | // the kSaveEverything call. |
| 394 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 395 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 396 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 397 | if (temp_is_r0) { |
| 398 | __ mov(entry_address, ShifterOperand(temp)); |
| 399 | } |
| 400 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 401 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 402 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 403 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 404 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 405 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 406 | if (do_clinit_) { |
| 407 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 408 | } else { |
| 409 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 410 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 411 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 412 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 413 | if (is_load_class_bss_entry) { |
| 414 | if (call_saves_everything_except_r0) { |
| 415 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 416 | __ str(R0, Address(entry_address)); |
| 417 | } else { |
| 418 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 419 | Register temp = IP; |
| 420 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 421 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 422 | __ BindTrackedLabel(&labels->movw_label); |
| 423 | __ movw(temp, /* placeholder */ 0u); |
| 424 | __ BindTrackedLabel(&labels->movt_label); |
| 425 | __ movt(temp, /* placeholder */ 0u); |
| 426 | __ BindTrackedLabel(&labels->add_pc_label); |
| 427 | __ add(temp, temp, ShifterOperand(PC)); |
| 428 | __ str(R0, Address(temp)); |
| 429 | } |
| 430 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 431 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 432 | if (out.IsValid()) { |
| 433 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 434 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 435 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 436 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 437 | __ b(GetExitLabel()); |
| 438 | } |
| 439 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 440 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 441 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 442 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 443 | // The class this slow path will load. |
| 444 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 445 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 446 | // The dex PC of `at_`. |
| 447 | const uint32_t dex_pc_; |
| 448 | |
| 449 | // Whether to initialize the class. |
| 450 | const bool do_clinit_; |
| 451 | |
| 452 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 453 | }; |
| 454 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 455 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 456 | public: |
| 457 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 458 | |
| 459 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 460 | DCHECK(instruction_->IsLoadString()); |
| 461 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 462 | LocationSummary* locations = instruction_->GetLocations(); |
| 463 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 464 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 465 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 466 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 467 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 468 | |
| 469 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 470 | __ Bind(GetEntryLabel()); |
| 471 | SaveLiveRegisters(codegen, locations); |
| 472 | |
| 473 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 474 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 475 | // the kSaveEverything call. |
| 476 | Register entry_address = kNoRegister; |
| 477 | if (call_saves_everything_except_r0) { |
| 478 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 479 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 480 | entry_address = temp_is_r0 ? out : temp; |
| 481 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 482 | if (temp_is_r0) { |
| 483 | __ mov(entry_address, ShifterOperand(temp)); |
| 484 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 485 | } |
| 486 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 487 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 488 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 489 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 490 | |
| 491 | // Store the resolved String to the .bss entry. |
| 492 | if (call_saves_everything_except_r0) { |
| 493 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 494 | __ str(R0, Address(entry_address)); |
| 495 | } else { |
| 496 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 497 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 498 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 499 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 500 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 501 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 502 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 503 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 504 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 505 | __ add(temp, temp, ShifterOperand(PC)); |
| 506 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 509 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 510 | RestoreLiveRegisters(codegen, locations); |
| 511 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 512 | __ b(GetExitLabel()); |
| 513 | } |
| 514 | |
| 515 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 516 | |
| 517 | private: |
| 518 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 519 | }; |
| 520 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 521 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 522 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 523 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 524 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 525 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 526 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 527 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 528 | DCHECK(instruction_->IsCheckCast() |
| 529 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 530 | |
| 531 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 532 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 533 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 534 | if (!is_fatal_) { |
| 535 | SaveLiveRegisters(codegen, locations); |
| 536 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 537 | |
| 538 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 539 | // move resolver. |
| 540 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 541 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 542 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 543 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 544 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 545 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 546 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 547 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 548 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 549 | instruction_, |
| 550 | instruction_->GetDexPc(), |
| 551 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 552 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 553 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 554 | } else { |
| 555 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 556 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 557 | instruction_, |
| 558 | instruction_->GetDexPc(), |
| 559 | this); |
| 560 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 561 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 562 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 563 | if (!is_fatal_) { |
| 564 | RestoreLiveRegisters(codegen, locations); |
| 565 | __ b(GetExitLabel()); |
| 566 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 569 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 570 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 571 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 572 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 573 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 574 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 575 | |
| 576 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 577 | }; |
| 578 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 579 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 580 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 581 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 582 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 583 | |
| 584 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 585 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 586 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 587 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 588 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 591 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 592 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 593 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 594 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 595 | }; |
| 596 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 597 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 598 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 599 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 600 | |
| 601 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 602 | LocationSummary* locations = instruction_->GetLocations(); |
| 603 | __ Bind(GetEntryLabel()); |
| 604 | SaveLiveRegisters(codegen, locations); |
| 605 | |
| 606 | InvokeRuntimeCallingConvention calling_convention; |
| 607 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 608 | parallel_move.AddMove( |
| 609 | locations->InAt(0), |
| 610 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 611 | Primitive::kPrimNot, |
| 612 | nullptr); |
| 613 | parallel_move.AddMove( |
| 614 | locations->InAt(1), |
| 615 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 616 | Primitive::kPrimInt, |
| 617 | nullptr); |
| 618 | parallel_move.AddMove( |
| 619 | locations->InAt(2), |
| 620 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 621 | Primitive::kPrimNot, |
| 622 | nullptr); |
| 623 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 624 | |
| 625 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 626 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 627 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 628 | RestoreLiveRegisters(codegen, locations); |
| 629 | __ b(GetExitLabel()); |
| 630 | } |
| 631 | |
| 632 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 633 | |
| 634 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 635 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 636 | }; |
| 637 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 638 | // Slow path marking an object reference `ref` during a read |
| 639 | // barrier. The field `obj.field` in the object `obj` holding this |
| 640 | // reference does not get updated by this slow path after marking (see |
| 641 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
| 642 | // |
| 643 | // This means that after the execution of this slow path, `ref` will |
| 644 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 645 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 646 | // probably still be a from-space reference (unless it gets updated by |
| 647 | // another thread, or if another thread installed another object |
| 648 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 649 | // |
| 650 | // If `entrypoint` is a valid location it is assumed to already be |
| 651 | // holding the entrypoint. The case where the entrypoint is passed in |
| 652 | // is for the GcRoot read barrier. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 653 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 654 | public: |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 655 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 656 | Location ref, |
| 657 | Location entrypoint = Location::NoLocation()) |
| 658 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 659 | DCHECK(kEmitCompilerReadBarrier); |
| 660 | } |
| 661 | |
| 662 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 663 | |
| 664 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 665 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 666 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 667 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 668 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 669 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 670 | instruction_->IsStaticFieldGet() || |
| 671 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 672 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 673 | instruction_->IsLoadClass() || |
| 674 | instruction_->IsLoadString() || |
| 675 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 676 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 677 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 678 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 679 | << "Unexpected instruction in read barrier marking slow path: " |
| 680 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 681 | // The read barrier instrumentation of object ArrayGet |
| 682 | // instructions does not support the HIntermediateAddress |
| 683 | // instruction. |
| 684 | DCHECK(!(instruction_->IsArrayGet() && |
| 685 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 686 | |
| 687 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 688 | // No need to save live registers; it's taken care of by the |
| 689 | // entrypoint. Also, there is no need to update the stack mask, |
| 690 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 691 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 692 | DCHECK_NE(ref_reg, SP); |
| 693 | DCHECK_NE(ref_reg, LR); |
| 694 | DCHECK_NE(ref_reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 695 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 696 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 697 | DCHECK_NE(ref_reg, IP); |
| 698 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 699 | // "Compact" slow path, saving two moves. |
| 700 | // |
| 701 | // Instead of using the standard runtime calling convention (input |
| 702 | // and output in R0): |
| 703 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 704 | // R0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 705 | // R0 <- ReadBarrierMark(R0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 706 | // ref <- R0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 707 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 708 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 709 | // of a dedicated entrypoint: |
| 710 | // |
| 711 | // rX <- ReadBarrierMarkRegX(rX) |
| 712 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 713 | if (entrypoint_.IsValid()) { |
| 714 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 715 | __ blx(entrypoint_.AsRegister<Register>()); |
| 716 | } else { |
| 717 | int32_t entry_point_offset = |
| 718 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 719 | // This runtime call does not require a stack map. |
| 720 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 721 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 722 | __ b(GetExitLabel()); |
| 723 | } |
| 724 | |
| 725 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 726 | // The location (register) of the marked object reference. |
| 727 | const Location ref_; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 728 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 729 | // The location of the entrypoint if already loaded. |
| 730 | const Location entrypoint_; |
| 731 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 732 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 733 | }; |
| 734 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 735 | // Slow path marking an object reference `ref` during a read barrier, |
| 736 | // and if needed, atomically updating the field `obj.field` in the |
| 737 | // object `obj` holding this reference after marking (contrary to |
| 738 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 739 | // `obj.field`). |
| 740 | // |
| 741 | // This means that after the execution of this slow path, both `ref` |
| 742 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 743 | // hold the same to-space reference (unless another thread installed |
| 744 | // another object reference (different from `ref`) in `obj.field`). |
| 745 | class ReadBarrierMarkAndUpdateFieldSlowPathARM : public SlowPathCodeARM { |
| 746 | public: |
| 747 | ReadBarrierMarkAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 748 | Location ref, |
| 749 | Register obj, |
| 750 | Location field_offset, |
| 751 | Register temp1, |
| 752 | Register temp2) |
| 753 | : SlowPathCodeARM(instruction), |
| 754 | ref_(ref), |
| 755 | obj_(obj), |
| 756 | field_offset_(field_offset), |
| 757 | temp1_(temp1), |
| 758 | temp2_(temp2) { |
| 759 | DCHECK(kEmitCompilerReadBarrier); |
| 760 | } |
| 761 | |
| 762 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathARM"; } |
| 763 | |
| 764 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 765 | LocationSummary* locations = instruction_->GetLocations(); |
| 766 | Register ref_reg = ref_.AsRegister<Register>(); |
| 767 | DCHECK(locations->CanCall()); |
| 768 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 769 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 770 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 771 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 772 | << instruction_->DebugName(); |
| 773 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 774 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 775 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 776 | |
| 777 | __ Bind(GetEntryLabel()); |
| 778 | |
| 779 | // Save the old reference. |
| 780 | // Note that we cannot use IP to save the old reference, as IP is |
| 781 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 782 | // need the old reference after the call to that entry point. |
| 783 | DCHECK_NE(temp1_, IP); |
| 784 | __ Mov(temp1_, ref_reg); |
| 785 | |
| 786 | // No need to save live registers; it's taken care of by the |
| 787 | // entrypoint. Also, there is no need to update the stack mask, |
| 788 | // as this runtime call will not trigger a garbage collection. |
| 789 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 790 | DCHECK_NE(ref_reg, SP); |
| 791 | DCHECK_NE(ref_reg, LR); |
| 792 | DCHECK_NE(ref_reg, PC); |
| 793 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 794 | // as a temporary, it cannot be the entry point's input/output. |
| 795 | DCHECK_NE(ref_reg, IP); |
| 796 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 797 | // "Compact" slow path, saving two moves. |
| 798 | // |
| 799 | // Instead of using the standard runtime calling convention (input |
| 800 | // and output in R0): |
| 801 | // |
| 802 | // R0 <- ref |
| 803 | // R0 <- ReadBarrierMark(R0) |
| 804 | // ref <- R0 |
| 805 | // |
| 806 | // we just use rX (the register containing `ref`) as input and output |
| 807 | // of a dedicated entrypoint: |
| 808 | // |
| 809 | // rX <- ReadBarrierMarkRegX(rX) |
| 810 | // |
| 811 | int32_t entry_point_offset = |
| 812 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 813 | // This runtime call does not require a stack map. |
| 814 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 815 | |
| 816 | // If the new reference is different from the old reference, |
| 817 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 818 | // |
| 819 | // Note that this field could also hold a different object, if |
| 820 | // another thread had concurrently changed it. In that case, the |
| 821 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 822 | // (CAS) operation below would abort the CAS, leaving the field |
| 823 | // as-is. |
| 824 | Label done; |
| 825 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
| 826 | __ b(&done, EQ); |
| 827 | |
| 828 | // Update the the holder's field atomically. This may fail if |
| 829 | // mutator updates before us, but it's OK. This is achieved |
| 830 | // using a strong compare-and-set (CAS) operation with relaxed |
| 831 | // memory synchronization ordering, where the expected value is |
| 832 | // the old reference and the desired value is the new reference. |
| 833 | |
| 834 | // Convenience aliases. |
| 835 | Register base = obj_; |
| 836 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 837 | // offset ("long offset"), of which only the low part contains |
| 838 | // data. |
| 839 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 840 | Register expected = temp1_; |
| 841 | Register value = ref_reg; |
| 842 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 843 | Register tmp = temp2_; // Value in memory. |
| 844 | |
| 845 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 846 | |
| 847 | if (kPoisonHeapReferences) { |
| 848 | __ PoisonHeapReference(expected); |
| 849 | if (value == expected) { |
| 850 | // Do not poison `value`, as it is the same register as |
| 851 | // `expected`, which has just been poisoned. |
| 852 | } else { |
| 853 | __ PoisonHeapReference(value); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | // do { |
| 858 | // tmp = [r_ptr] - expected; |
| 859 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 860 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 861 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 862 | __ Bind(&loop_head); |
| 863 | |
| 864 | __ ldrex(tmp, tmp_ptr); |
| 865 | |
| 866 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 867 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 868 | __ it(NE); |
| 869 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 870 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 871 | __ b(&exit_loop, NE); |
| 872 | |
| 873 | __ strex(tmp, value, tmp_ptr); |
| 874 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 875 | __ b(&loop_head, EQ); |
| 876 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 877 | __ Bind(&exit_loop); |
| 878 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 879 | if (kPoisonHeapReferences) { |
| 880 | __ UnpoisonHeapReference(expected); |
| 881 | if (value == expected) { |
| 882 | // Do not unpoison `value`, as it is the same register as |
| 883 | // `expected`, which has just been unpoisoned. |
| 884 | } else { |
| 885 | __ UnpoisonHeapReference(value); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | __ Bind(&done); |
| 890 | __ b(GetExitLabel()); |
| 891 | } |
| 892 | |
| 893 | private: |
| 894 | // The location (register) of the marked object reference. |
| 895 | const Location ref_; |
| 896 | // The register containing the object holding the marked object reference field. |
| 897 | const Register obj_; |
| 898 | // The location of the offset of the marked reference field within `obj_`. |
| 899 | Location field_offset_; |
| 900 | |
| 901 | const Register temp1_; |
| 902 | const Register temp2_; |
| 903 | |
| 904 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM); |
| 905 | }; |
| 906 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 907 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 908 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 909 | public: |
| 910 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 911 | Location out, |
| 912 | Location ref, |
| 913 | Location obj, |
| 914 | uint32_t offset, |
| 915 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 916 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 917 | out_(out), |
| 918 | ref_(ref), |
| 919 | obj_(obj), |
| 920 | offset_(offset), |
| 921 | index_(index) { |
| 922 | DCHECK(kEmitCompilerReadBarrier); |
| 923 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 924 | // has been overwritten by (or after) the heap object reference load |
| 925 | // to be instrumented, e.g.: |
| 926 | // |
| 927 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 928 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 929 | // |
| 930 | // In that case, we have lost the information about the original |
| 931 | // object, and the emitted read barrier cannot work properly. |
| 932 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 933 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 934 | } |
| 935 | |
| 936 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 937 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 938 | LocationSummary* locations = instruction_->GetLocations(); |
| 939 | Register reg_out = out_.AsRegister<Register>(); |
| 940 | DCHECK(locations->CanCall()); |
| 941 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 942 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 943 | instruction_->IsStaticFieldGet() || |
| 944 | instruction_->IsArrayGet() || |
| 945 | instruction_->IsInstanceOf() || |
| 946 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 947 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 948 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 949 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 950 | // The read barrier instrumentation of object ArrayGet |
| 951 | // instructions does not support the HIntermediateAddress |
| 952 | // instruction. |
| 953 | DCHECK(!(instruction_->IsArrayGet() && |
| 954 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 955 | |
| 956 | __ Bind(GetEntryLabel()); |
| 957 | SaveLiveRegisters(codegen, locations); |
| 958 | |
| 959 | // We may have to change the index's value, but as `index_` is a |
| 960 | // constant member (like other "inputs" of this slow path), |
| 961 | // introduce a copy of it, `index`. |
| 962 | Location index = index_; |
| 963 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 964 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 965 | if (instruction_->IsArrayGet()) { |
| 966 | // Compute the actual memory offset and store it in `index`. |
| 967 | Register index_reg = index_.AsRegister<Register>(); |
| 968 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 969 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 970 | // We are about to change the value of `index_reg` (see the |
| 971 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 972 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 973 | // not been saved by the previous call to |
| 974 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 975 | // callee-save register -- |
| 976 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 977 | // callee-save registers, as it has been designed with the |
| 978 | // assumption that callee-save registers are supposed to be |
| 979 | // handled by the called function. So, as a callee-save |
| 980 | // register, `index_reg` _would_ eventually be saved onto |
| 981 | // the stack, but it would be too late: we would have |
| 982 | // changed its value earlier. Therefore, we manually save |
| 983 | // it here into another freely available register, |
| 984 | // `free_reg`, chosen of course among the caller-save |
| 985 | // registers (as a callee-save `free_reg` register would |
| 986 | // exhibit the same problem). |
| 987 | // |
| 988 | // Note we could have requested a temporary register from |
| 989 | // the register allocator instead; but we prefer not to, as |
| 990 | // this is a slow path, and we know we can find a |
| 991 | // caller-save register that is available. |
| 992 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 993 | __ Mov(free_reg, index_reg); |
| 994 | index_reg = free_reg; |
| 995 | index = Location::RegisterLocation(index_reg); |
| 996 | } else { |
| 997 | // The initial register stored in `index_` has already been |
| 998 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 999 | // (as it is not a callee-save register), so we can freely |
| 1000 | // use it. |
| 1001 | } |
| 1002 | // Shifting the index value contained in `index_reg` by the scale |
| 1003 | // factor (2) cannot overflow in practice, as the runtime is |
| 1004 | // unable to allocate object arrays with a size larger than |
| 1005 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1006 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1007 | static_assert( |
| 1008 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1009 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1010 | __ AddConstant(index_reg, index_reg, offset_); |
| 1011 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1012 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1013 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1014 | // (as in the case of ArrayGet), as it is actually an offset |
| 1015 | // to an object field within an object. |
| 1016 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1017 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1018 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1019 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1020 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1021 | DCHECK_EQ(offset_, 0U); |
| 1022 | DCHECK(index_.IsRegisterPair()); |
| 1023 | // UnsafeGet's offset location is a register pair, the low |
| 1024 | // part contains the correct offset. |
| 1025 | index = index_.ToLow(); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | // We're moving two or three locations to locations that could |
| 1030 | // overlap, so we need a parallel move resolver. |
| 1031 | InvokeRuntimeCallingConvention calling_convention; |
| 1032 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1033 | parallel_move.AddMove(ref_, |
| 1034 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1035 | Primitive::kPrimNot, |
| 1036 | nullptr); |
| 1037 | parallel_move.AddMove(obj_, |
| 1038 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1039 | Primitive::kPrimNot, |
| 1040 | nullptr); |
| 1041 | if (index.IsValid()) { |
| 1042 | parallel_move.AddMove(index, |
| 1043 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1044 | Primitive::kPrimInt, |
| 1045 | nullptr); |
| 1046 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1047 | } else { |
| 1048 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1049 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1050 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1051 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1052 | CheckEntrypointTypes< |
| 1053 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1054 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1055 | |
| 1056 | RestoreLiveRegisters(codegen, locations); |
| 1057 | __ b(GetExitLabel()); |
| 1058 | } |
| 1059 | |
| 1060 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1061 | |
| 1062 | private: |
| 1063 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1064 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1065 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1066 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1067 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1068 | return static_cast<Register>(i); |
| 1069 | } |
| 1070 | } |
| 1071 | // We shall never fail to find a free caller-save register, as |
| 1072 | // there are more than two core caller-save registers on ARM |
| 1073 | // (meaning it is possible to find one which is different from |
| 1074 | // `ref` and `obj`). |
| 1075 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1076 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1077 | UNREACHABLE(); |
| 1078 | } |
| 1079 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1080 | const Location out_; |
| 1081 | const Location ref_; |
| 1082 | const Location obj_; |
| 1083 | const uint32_t offset_; |
| 1084 | // An additional location containing an index to an array. |
| 1085 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1086 | // UnsafeGetObjectVolatile intrinsics. |
| 1087 | const Location index_; |
| 1088 | |
| 1089 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1090 | }; |
| 1091 | |
| 1092 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1093 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1094 | public: |
| 1095 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1096 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1097 | DCHECK(kEmitCompilerReadBarrier); |
| 1098 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1099 | |
| 1100 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1101 | LocationSummary* locations = instruction_->GetLocations(); |
| 1102 | Register reg_out = out_.AsRegister<Register>(); |
| 1103 | DCHECK(locations->CanCall()); |
| 1104 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1105 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1106 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1107 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1108 | |
| 1109 | __ Bind(GetEntryLabel()); |
| 1110 | SaveLiveRegisters(codegen, locations); |
| 1111 | |
| 1112 | InvokeRuntimeCallingConvention calling_convention; |
| 1113 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1114 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1115 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1116 | instruction_, |
| 1117 | instruction_->GetDexPc(), |
| 1118 | this); |
| 1119 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1120 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1121 | |
| 1122 | RestoreLiveRegisters(codegen, locations); |
| 1123 | __ b(GetExitLabel()); |
| 1124 | } |
| 1125 | |
| 1126 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1127 | |
| 1128 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1129 | const Location out_; |
| 1130 | const Location root_; |
| 1131 | |
| 1132 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1133 | }; |
| 1134 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1135 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1136 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1137 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1138 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1139 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1140 | switch (cond) { |
| 1141 | case kCondEQ: return EQ; |
| 1142 | case kCondNE: return NE; |
| 1143 | case kCondLT: return LT; |
| 1144 | case kCondLE: return LE; |
| 1145 | case kCondGT: return GT; |
| 1146 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1147 | case kCondB: return LO; |
| 1148 | case kCondBE: return LS; |
| 1149 | case kCondA: return HI; |
| 1150 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1151 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1152 | LOG(FATAL) << "Unreachable"; |
| 1153 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1156 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1157 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1158 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1159 | case kCondEQ: return EQ; |
| 1160 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1161 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1162 | case kCondLT: return LO; |
| 1163 | case kCondLE: return LS; |
| 1164 | case kCondGT: return HI; |
| 1165 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1166 | // Unsigned remain unchanged. |
| 1167 | case kCondB: return LO; |
| 1168 | case kCondBE: return LS; |
| 1169 | case kCondA: return HI; |
| 1170 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1171 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1172 | LOG(FATAL) << "Unreachable"; |
| 1173 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1176 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1177 | // The ARM condition codes can express all the necessary branches, see the |
| 1178 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1179 | // There is no dex instruction or HIR that would need the missing conditions |
| 1180 | // "equal or unordered" or "not equal". |
| 1181 | switch (cond) { |
| 1182 | case kCondEQ: return EQ; |
| 1183 | case kCondNE: return NE /* unordered */; |
| 1184 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1185 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1186 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1187 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1188 | default: |
| 1189 | LOG(FATAL) << "UNREACHABLE"; |
| 1190 | UNREACHABLE(); |
| 1191 | } |
| 1192 | } |
| 1193 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1194 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1195 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1199 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1200 | } |
| 1201 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1202 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1203 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1204 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1205 | } |
| 1206 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1207 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1208 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1209 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1210 | } |
| 1211 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1212 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1213 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1214 | return kArmWordSize; |
| 1215 | } |
| 1216 | |
| 1217 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1218 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1219 | return kArmWordSize; |
| 1220 | } |
| 1221 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1222 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1223 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1224 | const CompilerOptions& compiler_options, |
| 1225 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1226 | : CodeGenerator(graph, |
| 1227 | kNumberOfCoreRegisters, |
| 1228 | kNumberOfSRegisters, |
| 1229 | kNumberOfRegisterPairs, |
| 1230 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1231 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1232 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1233 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1234 | compiler_options, |
| 1235 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1236 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1237 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1238 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1239 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1240 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1241 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1242 | uint32_literals_(std::less<uint32_t>(), |
| 1243 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1244 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1245 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1246 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1247 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1248 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1249 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1250 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1251 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1252 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1253 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1254 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1255 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1256 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1257 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1258 | // Always save the LR register to mimic Quick. |
| 1259 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1262 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1263 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1264 | __ FinalizeCode(); |
| 1265 | |
| 1266 | // Adjust native pc offsets in stack maps. |
| 1267 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1268 | uint32_t old_position = |
| 1269 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1270 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1271 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1272 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1273 | // Adjust pc offsets for the disassembly information. |
| 1274 | if (disasm_info_ != nullptr) { |
| 1275 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1276 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1277 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1278 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1279 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1280 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1281 | } |
| 1282 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1283 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1284 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1285 | } |
| 1286 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1287 | |
| 1288 | CodeGenerator::Finalize(allocator); |
| 1289 | } |
| 1290 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1291 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1292 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1293 | blocked_core_registers_[SP] = true; |
| 1294 | blocked_core_registers_[LR] = true; |
| 1295 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1296 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1297 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1298 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1299 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1300 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1301 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1302 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1303 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1304 | // Stubs do not save callee-save floating point registers. If the graph |
| 1305 | // is debuggable, we need to deal with these registers differently. For |
| 1306 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1307 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1308 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1309 | } |
| 1310 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1313 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1314 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1315 | assembler_(codegen->GetAssembler()), |
| 1316 | codegen_(codegen) {} |
| 1317 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1318 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1319 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1320 | 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] | 1321 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1322 | // restore another arbitrary register. |
| 1323 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1324 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1325 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1326 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1327 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1328 | // but in the range. |
| 1329 | if (fpu_spill_mask_ != 0) { |
| 1330 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1331 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1332 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1333 | fpu_spill_mask_ |= (1 << i); |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1338 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1339 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1343 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1346 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1347 | bool skip_overflow_check = |
| 1348 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1349 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1350 | __ Bind(&frame_entry_label_); |
| 1351 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1352 | if (HasEmptyFrame()) { |
| 1353 | return; |
| 1354 | } |
| 1355 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1356 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1357 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1358 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1359 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1360 | } |
| 1361 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1362 | __ PushList(core_spill_mask_); |
| 1363 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1364 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1365 | if (fpu_spill_mask_ != 0) { |
| 1366 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1367 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1368 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1369 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1370 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1371 | |
| 1372 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1373 | // Initialize should_deoptimize flag to 0. |
| 1374 | __ mov(IP, ShifterOperand(0)); |
| 1375 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1376 | } |
| 1377 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1378 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1379 | __ AddConstant(SP, -adjust); |
| 1380 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1381 | |
| 1382 | // Save the current method if we need it. Note that we do not |
| 1383 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1384 | // in the SSA graph. |
| 1385 | if (RequiresCurrentMethod()) { |
| 1386 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1387 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1391 | if (HasEmptyFrame()) { |
| 1392 | __ bx(LR); |
| 1393 | return; |
| 1394 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1395 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1396 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1397 | __ AddConstant(SP, adjust); |
| 1398 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1399 | if (fpu_spill_mask_ != 0) { |
| 1400 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1401 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1402 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1403 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1404 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1405 | // Pop LR into PC to return. |
| 1406 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1407 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1408 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1409 | __ cfi().RestoreState(); |
| 1410 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1413 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1414 | Label* label = GetLabelOf(block); |
| 1415 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1418 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1419 | switch (type) { |
| 1420 | case Primitive::kPrimBoolean: |
| 1421 | case Primitive::kPrimByte: |
| 1422 | case Primitive::kPrimChar: |
| 1423 | case Primitive::kPrimShort: |
| 1424 | case Primitive::kPrimInt: |
| 1425 | case Primitive::kPrimNot: { |
| 1426 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1427 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1428 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1429 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1430 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1431 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1432 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1433 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1434 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1435 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1436 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1437 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1438 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1439 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1440 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1441 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1442 | // Skip R1, and use R2_R3 instead. |
| 1443 | gp_index_++; |
| 1444 | index++; |
| 1445 | } |
| 1446 | } |
| 1447 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1448 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1449 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1450 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1451 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1452 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1453 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1454 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | case Primitive::kPrimFloat: { |
| 1459 | uint32_t stack_index = stack_index_++; |
| 1460 | if (float_index_ % 2 == 0) { |
| 1461 | float_index_ = std::max(double_index_, float_index_); |
| 1462 | } |
| 1463 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1464 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1465 | } else { |
| 1466 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | case Primitive::kPrimDouble: { |
| 1471 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1472 | uint32_t stack_index = stack_index_; |
| 1473 | stack_index_ += 2; |
| 1474 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1475 | uint32_t index = double_index_; |
| 1476 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1477 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1478 | calling_convention.GetFpuRegisterAt(index), |
| 1479 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1480 | DCHECK(ExpectedPairLayout(result)); |
| 1481 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1482 | } else { |
| 1483 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1487 | case Primitive::kPrimVoid: |
| 1488 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1489 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1490 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1491 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1492 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1493 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1494 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1495 | switch (type) { |
| 1496 | case Primitive::kPrimBoolean: |
| 1497 | case Primitive::kPrimByte: |
| 1498 | case Primitive::kPrimChar: |
| 1499 | case Primitive::kPrimShort: |
| 1500 | case Primitive::kPrimInt: |
| 1501 | case Primitive::kPrimNot: { |
| 1502 | return Location::RegisterLocation(R0); |
| 1503 | } |
| 1504 | |
| 1505 | case Primitive::kPrimFloat: { |
| 1506 | return Location::FpuRegisterLocation(S0); |
| 1507 | } |
| 1508 | |
| 1509 | case Primitive::kPrimLong: { |
| 1510 | return Location::RegisterPairLocation(R0, R1); |
| 1511 | } |
| 1512 | |
| 1513 | case Primitive::kPrimDouble: { |
| 1514 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1515 | } |
| 1516 | |
| 1517 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1518 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1519 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1520 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1521 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1524 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1525 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1526 | } |
| 1527 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1528 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1529 | if (source.Equals(destination)) { |
| 1530 | return; |
| 1531 | } |
| 1532 | if (destination.IsRegister()) { |
| 1533 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1534 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1535 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1536 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1537 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1538 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1539 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1540 | } else if (destination.IsFpuRegister()) { |
| 1541 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1542 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1543 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1544 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1545 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1546 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1547 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1548 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1549 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1550 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1551 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1552 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1553 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1554 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1555 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1556 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1557 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1563 | if (source.Equals(destination)) { |
| 1564 | return; |
| 1565 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1566 | if (destination.IsRegisterPair()) { |
| 1567 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1568 | EmitParallelMoves( |
| 1569 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1570 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1571 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1572 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1573 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1574 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1575 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1576 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1577 | } else if (source.IsFpuRegisterPair()) { |
| 1578 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1579 | destination.AsRegisterPairHigh<Register>(), |
| 1580 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1581 | } else { |
| 1582 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1583 | DCHECK(ExpectedPairLayout(destination)); |
| 1584 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1585 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1586 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1587 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1588 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1589 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1590 | SP, |
| 1591 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1592 | } else if (source.IsRegisterPair()) { |
| 1593 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1594 | source.AsRegisterPairLow<Register>(), |
| 1595 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1596 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1597 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1598 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1599 | } else { |
| 1600 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1601 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1602 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1603 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1604 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1605 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1606 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1607 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1608 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1609 | SP, destination.GetStackIndex()); |
| 1610 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1611 | } else if (source.IsFpuRegisterPair()) { |
| 1612 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1613 | SP, |
| 1614 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1615 | } else { |
| 1616 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1617 | EmitParallelMoves( |
| 1618 | Location::StackSlot(source.GetStackIndex()), |
| 1619 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1620 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1621 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1622 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1623 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1628 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1629 | DCHECK(location.IsRegister()); |
| 1630 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1631 | } |
| 1632 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1633 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1634 | HParallelMove move(GetGraph()->GetArena()); |
| 1635 | move.AddMove(src, dst, dst_type, nullptr); |
| 1636 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1640 | if (location.IsRegister()) { |
| 1641 | locations->AddTemp(location); |
| 1642 | } else if (location.IsRegisterPair()) { |
| 1643 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1644 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1645 | } else { |
| 1646 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1647 | } |
| 1648 | } |
| 1649 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1650 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1651 | HInstruction* instruction, |
| 1652 | uint32_t dex_pc, |
| 1653 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1654 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1655 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1656 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1657 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1658 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1659 | } |
| 1660 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1661 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1662 | HInstruction* instruction, |
| 1663 | SlowPathCode* slow_path) { |
| 1664 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1665 | GenerateInvokeRuntime(entry_point_offset); |
| 1666 | } |
| 1667 | |
| 1668 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1669 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1670 | __ blx(LR); |
| 1671 | } |
| 1672 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1673 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1674 | DCHECK(!successor->IsExitBlock()); |
| 1675 | |
| 1676 | HBasicBlock* block = got->GetBlock(); |
| 1677 | HInstruction* previous = got->GetPrevious(); |
| 1678 | |
| 1679 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1680 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1681 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1682 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1683 | return; |
| 1684 | } |
| 1685 | |
| 1686 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1687 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1688 | } |
| 1689 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1690 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1694 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1695 | got->SetLocations(nullptr); |
| 1696 | } |
| 1697 | |
| 1698 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1699 | HandleGoto(got, got->GetSuccessor()); |
| 1700 | } |
| 1701 | |
| 1702 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1703 | try_boundary->SetLocations(nullptr); |
| 1704 | } |
| 1705 | |
| 1706 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1707 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1708 | if (!successor->IsExitBlock()) { |
| 1709 | HandleGoto(try_boundary, successor); |
| 1710 | } |
| 1711 | } |
| 1712 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1713 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1714 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1717 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1720 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1721 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1722 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1723 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1724 | if (rhs_loc.IsConstant()) { |
| 1725 | // 0.0 is the only immediate that can be encoded directly in |
| 1726 | // a VCMP instruction. |
| 1727 | // |
| 1728 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1729 | // specify that in a floating-point comparison, positive zero |
| 1730 | // and negative zero are considered equal, so we can use the |
| 1731 | // literal 0.0 for both cases here. |
| 1732 | // |
| 1733 | // Note however that some methods (Float.equal, Float.compare, |
| 1734 | // Float.compareTo, Double.equal, Double.compare, |
| 1735 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1736 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1737 | // -0.0. So if we ever translate calls to these methods into a |
| 1738 | // HCompare instruction, we must handle the -0.0 case with |
| 1739 | // care here. |
| 1740 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1741 | if (type == Primitive::kPrimFloat) { |
| 1742 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1743 | } else { |
| 1744 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1745 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1746 | } |
| 1747 | } else { |
| 1748 | if (type == Primitive::kPrimFloat) { |
| 1749 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1750 | } else { |
| 1751 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1752 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1753 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1754 | } |
| 1755 | } |
| 1756 | } |
| 1757 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1758 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1759 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1760 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1761 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1762 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1766 | Label* true_label, |
| 1767 | Label* false_label) { |
| 1768 | LocationSummary* locations = cond->GetLocations(); |
| 1769 | Location left = locations->InAt(0); |
| 1770 | Location right = locations->InAt(1); |
| 1771 | IfCondition if_cond = cond->GetCondition(); |
| 1772 | |
| 1773 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1774 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1775 | IfCondition true_high_cond = if_cond; |
| 1776 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1777 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1778 | |
| 1779 | // Set the conditions for the test, remembering that == needs to be |
| 1780 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1781 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1782 | switch (if_cond) { |
| 1783 | case kCondEQ: |
| 1784 | case kCondNE: |
| 1785 | // Nothing to do. |
| 1786 | break; |
| 1787 | case kCondLT: |
| 1788 | false_high_cond = kCondGT; |
| 1789 | break; |
| 1790 | case kCondLE: |
| 1791 | true_high_cond = kCondLT; |
| 1792 | break; |
| 1793 | case kCondGT: |
| 1794 | false_high_cond = kCondLT; |
| 1795 | break; |
| 1796 | case kCondGE: |
| 1797 | true_high_cond = kCondGT; |
| 1798 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | case kCondB: |
| 1800 | false_high_cond = kCondA; |
| 1801 | break; |
| 1802 | case kCondBE: |
| 1803 | true_high_cond = kCondB; |
| 1804 | break; |
| 1805 | case kCondA: |
| 1806 | false_high_cond = kCondB; |
| 1807 | break; |
| 1808 | case kCondAE: |
| 1809 | true_high_cond = kCondA; |
| 1810 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1811 | } |
| 1812 | if (right.IsConstant()) { |
| 1813 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1814 | int32_t val_low = Low32Bits(value); |
| 1815 | int32_t val_high = High32Bits(value); |
| 1816 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1817 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1818 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1820 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1821 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1822 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1823 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1824 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1825 | } |
| 1826 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1827 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1828 | } else { |
| 1829 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1830 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1831 | |
| 1832 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1833 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1834 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1835 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1836 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1837 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1838 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1839 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1840 | } |
| 1841 | // Must be equal high, so compare the lows. |
| 1842 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1843 | } |
| 1844 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1845 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1846 | __ b(true_label, final_condition); |
| 1847 | } |
| 1848 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1849 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1850 | Label* true_target_in, |
| 1851 | Label* false_target_in) { |
| 1852 | // Generated branching requires both targets to be explicit. If either of the |
| 1853 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1854 | Label fallthrough_target; |
| 1855 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1856 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1857 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1858 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1859 | switch (type) { |
| 1860 | case Primitive::kPrimLong: |
| 1861 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1862 | break; |
| 1863 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1864 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1865 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1866 | GenerateFPJumps(condition, true_target, false_target); |
| 1867 | break; |
| 1868 | default: |
| 1869 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1870 | } |
| 1871 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1872 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1873 | __ b(false_target); |
| 1874 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1875 | |
| 1876 | if (fallthrough_target.IsLinked()) { |
| 1877 | __ Bind(&fallthrough_target); |
| 1878 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1881 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1882 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1883 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1884 | Label* false_target) { |
| 1885 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1886 | |
| 1887 | if (true_target == nullptr && false_target == nullptr) { |
| 1888 | // Nothing to do. The code always falls through. |
| 1889 | return; |
| 1890 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1891 | // Constant condition, statically compared against "true" (integer value 1). |
| 1892 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1893 | if (true_target != nullptr) { |
| 1894 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1895 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1896 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1897 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1898 | if (false_target != nullptr) { |
| 1899 | __ b(false_target); |
| 1900 | } |
| 1901 | } |
| 1902 | return; |
| 1903 | } |
| 1904 | |
| 1905 | // The following code generates these patterns: |
| 1906 | // (1) true_target == nullptr && false_target != nullptr |
| 1907 | // - opposite condition true => branch to false_target |
| 1908 | // (2) true_target != nullptr && false_target == nullptr |
| 1909 | // - condition true => branch to true_target |
| 1910 | // (3) true_target != nullptr && false_target != nullptr |
| 1911 | // - condition true => branch to true_target |
| 1912 | // - branch to false_target |
| 1913 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1914 | // Condition has been materialized, compare the output to 0. |
| 1915 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1916 | DCHECK(cond_val.IsRegister()); |
| 1917 | if (true_target == nullptr) { |
| 1918 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1919 | } else { |
| 1920 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1921 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1922 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1923 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1924 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1925 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1926 | |
| 1927 | // If this is a long or FP comparison that has been folded into |
| 1928 | // the HCondition, generate the comparison directly. |
| 1929 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1930 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1931 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1932 | return; |
| 1933 | } |
| 1934 | |
| 1935 | LocationSummary* locations = cond->GetLocations(); |
| 1936 | DCHECK(locations->InAt(0).IsRegister()); |
| 1937 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1938 | Location right = locations->InAt(1); |
| 1939 | if (right.IsRegister()) { |
| 1940 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1941 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1942 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1943 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1944 | } |
| 1945 | if (true_target == nullptr) { |
| 1946 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1947 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1948 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1949 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1950 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1951 | |
| 1952 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1953 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1954 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1955 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1956 | } |
| 1957 | } |
| 1958 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1959 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1960 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1961 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1962 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1967 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1968 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1969 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1970 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1971 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1972 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1973 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1977 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1978 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1979 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1980 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1981 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1986 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1987 | GenerateTestAndBranch(deoptimize, |
| 1988 | /* condition_input_index */ 0, |
| 1989 | slow_path->GetEntryLabel(), |
| 1990 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1991 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1992 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1993 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1994 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1995 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1996 | locations->SetOut(Location::RequiresRegister()); |
| 1997 | } |
| 1998 | |
| 1999 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2000 | __ LoadFromOffset(kLoadWord, |
| 2001 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2002 | SP, |
| 2003 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2004 | } |
| 2005 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2006 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2007 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 2008 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2009 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2010 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2011 | } else { |
| 2012 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2013 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2014 | } |
| 2015 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2016 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2017 | } |
| 2018 | locations->SetOut(Location::SameAsFirstInput()); |
| 2019 | } |
| 2020 | |
| 2021 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 2022 | LocationSummary* locations = select->GetLocations(); |
| 2023 | Label false_target; |
| 2024 | GenerateTestAndBranch(select, |
| 2025 | /* condition_input_index */ 2, |
| 2026 | /* true_target */ nullptr, |
| 2027 | &false_target); |
| 2028 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2029 | __ Bind(&false_target); |
| 2030 | } |
| 2031 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2032 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2033 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2034 | } |
| 2035 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2036 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2037 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | void CodeGeneratorARM::GenerateNop() { |
| 2041 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2044 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2045 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2046 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2047 | // Handle the long/FP comparisons made in instruction simplification. |
| 2048 | switch (cond->InputAt(0)->GetType()) { |
| 2049 | case Primitive::kPrimLong: |
| 2050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2051 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2052 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2053 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2054 | } |
| 2055 | break; |
| 2056 | |
| 2057 | case Primitive::kPrimFloat: |
| 2058 | case Primitive::kPrimDouble: |
| 2059 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2060 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2061 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2062 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2063 | } |
| 2064 | break; |
| 2065 | |
| 2066 | default: |
| 2067 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2068 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2069 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2070 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2071 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2072 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2075 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2076 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2077 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2078 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2079 | |
| 2080 | LocationSummary* locations = cond->GetLocations(); |
| 2081 | Location left = locations->InAt(0); |
| 2082 | Location right = locations->InAt(1); |
| 2083 | Register out = locations->Out().AsRegister<Register>(); |
| 2084 | Label true_label, false_label; |
| 2085 | |
| 2086 | switch (cond->InputAt(0)->GetType()) { |
| 2087 | default: { |
| 2088 | // Integer case. |
| 2089 | if (right.IsRegister()) { |
| 2090 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2091 | } else { |
| 2092 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2093 | __ CmpConstant(left.AsRegister<Register>(), |
| 2094 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2095 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2096 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2097 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2098 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2099 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2100 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2101 | return; |
| 2102 | } |
| 2103 | case Primitive::kPrimLong: |
| 2104 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2105 | break; |
| 2106 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2107 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2108 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2109 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2110 | break; |
| 2111 | } |
| 2112 | |
| 2113 | // Convert the jumps into the result. |
| 2114 | Label done_label; |
| 2115 | |
| 2116 | // False case: result = 0. |
| 2117 | __ Bind(&false_label); |
| 2118 | __ LoadImmediate(out, 0); |
| 2119 | __ b(&done_label); |
| 2120 | |
| 2121 | // True case: result = 1. |
| 2122 | __ Bind(&true_label); |
| 2123 | __ LoadImmediate(out, 1); |
| 2124 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2128 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2132 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2136 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2140 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2144 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2148 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2152 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2156 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2160 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2164 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2168 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2172 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2175 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2176 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2180 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2184 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2188 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2192 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2196 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2200 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2204 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2207 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2208 | LocationSummary* locations = |
| 2209 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2210 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2213 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2214 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2217 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2218 | LocationSummary* locations = |
| 2219 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2220 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2221 | } |
| 2222 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2223 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2224 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2227 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2228 | LocationSummary* locations = |
| 2229 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2230 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2231 | } |
| 2232 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2233 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2234 | // Will be generated at use site. |
| 2235 | } |
| 2236 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2237 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2238 | LocationSummary* locations = |
| 2239 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2240 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2241 | } |
| 2242 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2243 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2244 | // Will be generated at use site. |
| 2245 | } |
| 2246 | |
| 2247 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2248 | LocationSummary* locations = |
| 2249 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2250 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2251 | } |
| 2252 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2253 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2254 | // Will be generated at use site. |
| 2255 | } |
| 2256 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2257 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2258 | memory_barrier->SetLocations(nullptr); |
| 2259 | } |
| 2260 | |
| 2261 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2262 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2263 | } |
| 2264 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2265 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2266 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2269 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2270 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2273 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2274 | LocationSummary* locations = |
| 2275 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2276 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2279 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2280 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2283 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2284 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2285 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2286 | // the method_idx. |
| 2287 | HandleInvoke(invoke); |
| 2288 | } |
| 2289 | |
| 2290 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2291 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2292 | } |
| 2293 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2294 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2295 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2296 | // art::PrepareForRegisterAllocation. |
| 2297 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2298 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2299 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2300 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2301 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2302 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2303 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2304 | return; |
| 2305 | } |
| 2306 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2307 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2308 | |
| 2309 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2310 | if (invoke->HasPcRelativeDexCache()) { |
| 2311 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2312 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2313 | } |
| 2314 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2315 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2316 | if (invoke->GetLocations()->Intrinsified()) { |
| 2317 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2318 | intrinsic.Dispatch(invoke); |
| 2319 | return true; |
| 2320 | } |
| 2321 | return false; |
| 2322 | } |
| 2323 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2324 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2325 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2326 | // art::PrepareForRegisterAllocation. |
| 2327 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2328 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2329 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2330 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2331 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2332 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2333 | LocationSummary* locations = invoke->GetLocations(); |
| 2334 | codegen_->GenerateStaticOrDirectCall( |
| 2335 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2336 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2337 | } |
| 2338 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2339 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2340 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2341 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2344 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2345 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2346 | if (intrinsic.TryDispatch(invoke)) { |
| 2347 | return; |
| 2348 | } |
| 2349 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2350 | HandleInvoke(invoke); |
| 2351 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2352 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2353 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2354 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2355 | return; |
| 2356 | } |
| 2357 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2358 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2359 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2360 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2363 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2364 | HandleInvoke(invoke); |
| 2365 | // Add the hidden argument. |
| 2366 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2367 | } |
| 2368 | |
| 2369 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2370 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2371 | LocationSummary* locations = invoke->GetLocations(); |
| 2372 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2373 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2374 | Location receiver = locations->InAt(0); |
| 2375 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2376 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2377 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2378 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2379 | DCHECK_EQ(R12, hidden_reg); |
| 2380 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2381 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2382 | if (receiver.IsStackSlot()) { |
| 2383 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2384 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2385 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2386 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2387 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2388 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2389 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2390 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2391 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2392 | // emit a read barrier for the previous class reference load. |
| 2393 | // However this is not required in practice, as this is an |
| 2394 | // intermediate/temporary reference and because the current |
| 2395 | // concurrent copying collector keeps the from-space memory |
| 2396 | // intact/accessible until the end of the marking phase (the |
| 2397 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2398 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2399 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2400 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2401 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2402 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2403 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2404 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2405 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2406 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2407 | // LR = temp->GetEntryPoint(); |
| 2408 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2409 | // LR(); |
| 2410 | __ blx(LR); |
| 2411 | DCHECK(!codegen_->IsLeafMethod()); |
| 2412 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2413 | } |
| 2414 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2415 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2416 | HandleInvoke(invoke); |
| 2417 | } |
| 2418 | |
| 2419 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2420 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2421 | } |
| 2422 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2423 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2424 | LocationSummary* locations = |
| 2425 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2426 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2428 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2429 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2430 | break; |
| 2431 | } |
| 2432 | case Primitive::kPrimLong: { |
| 2433 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2434 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2435 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2436 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2437 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2438 | case Primitive::kPrimFloat: |
| 2439 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2440 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2441 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2442 | break; |
| 2443 | |
| 2444 | default: |
| 2445 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2450 | LocationSummary* locations = neg->GetLocations(); |
| 2451 | Location out = locations->Out(); |
| 2452 | Location in = locations->InAt(0); |
| 2453 | switch (neg->GetResultType()) { |
| 2454 | case Primitive::kPrimInt: |
| 2455 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2456 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2457 | break; |
| 2458 | |
| 2459 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2460 | DCHECK(in.IsRegisterPair()); |
| 2461 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2462 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2463 | in.AsRegisterPairLow<Register>(), |
| 2464 | ShifterOperand(0)); |
| 2465 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2466 | // instruction here, as it does not exist in the Thumb-2 |
| 2467 | // instruction set. We use the following approach |
| 2468 | // using SBC and SUB instead. |
| 2469 | // |
| 2470 | // out.hi = -C |
| 2471 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2472 | out.AsRegisterPairHigh<Register>(), |
| 2473 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2474 | // out.hi = out.hi - in.hi |
| 2475 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2476 | out.AsRegisterPairHigh<Register>(), |
| 2477 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2478 | break; |
| 2479 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2480 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2481 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2482 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2483 | break; |
| 2484 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2485 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2486 | DCHECK(in.IsFpuRegisterPair()); |
| 2487 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2488 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2489 | break; |
| 2490 | |
| 2491 | default: |
| 2492 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2493 | } |
| 2494 | } |
| 2495 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2496 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2497 | Primitive::Type result_type = conversion->GetResultType(); |
| 2498 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2499 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2500 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2501 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2502 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2503 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2504 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2505 | && result_type == Primitive::kPrimLong) |
| 2506 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2507 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2508 | : LocationSummary::kNoCall; |
| 2509 | LocationSummary* locations = |
| 2510 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2511 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2512 | // The Java language does not allow treating boolean as an integral type but |
| 2513 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2514 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2515 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimByte: |
| 2517 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2518 | case Primitive::kPrimLong: |
| 2519 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimBoolean: |
| 2521 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2522 | case Primitive::kPrimShort: |
| 2523 | case Primitive::kPrimInt: |
| 2524 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2525 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2527 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2528 | break; |
| 2529 | |
| 2530 | default: |
| 2531 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2532 | << " to " << result_type; |
| 2533 | } |
| 2534 | break; |
| 2535 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimShort: |
| 2537 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimLong: |
| 2539 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimBoolean: |
| 2541 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2542 | case Primitive::kPrimByte: |
| 2543 | case Primitive::kPrimInt: |
| 2544 | case Primitive::kPrimChar: |
| 2545 | // Processing a Dex `int-to-short' instruction. |
| 2546 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2547 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2548 | break; |
| 2549 | |
| 2550 | default: |
| 2551 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2552 | << " to " << result_type; |
| 2553 | } |
| 2554 | break; |
| 2555 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimInt: |
| 2557 | switch (input_type) { |
| 2558 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2559 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2560 | locations->SetInAt(0, Location::Any()); |
| 2561 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2562 | break; |
| 2563 | |
| 2564 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2565 | // Processing a Dex `float-to-int' instruction. |
| 2566 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2567 | locations->SetOut(Location::RequiresRegister()); |
| 2568 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2569 | break; |
| 2570 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2571 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2572 | // Processing a Dex `double-to-int' instruction. |
| 2573 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2574 | locations->SetOut(Location::RequiresRegister()); |
| 2575 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | |
| 2578 | default: |
| 2579 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2580 | << " to " << result_type; |
| 2581 | } |
| 2582 | break; |
| 2583 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2584 | case Primitive::kPrimLong: |
| 2585 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimBoolean: |
| 2587 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimByte: |
| 2589 | case Primitive::kPrimShort: |
| 2590 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2591 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2592 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2594 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2595 | break; |
| 2596 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimFloat: { |
| 2598 | // Processing a Dex `float-to-long' instruction. |
| 2599 | InvokeRuntimeCallingConvention calling_convention; |
| 2600 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2601 | calling_convention.GetFpuRegisterAt(0))); |
| 2602 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2603 | break; |
| 2604 | } |
| 2605 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimDouble: { |
| 2607 | // Processing a Dex `double-to-long' instruction. |
| 2608 | InvokeRuntimeCallingConvention calling_convention; |
| 2609 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2610 | calling_convention.GetFpuRegisterAt(0), |
| 2611 | calling_convention.GetFpuRegisterAt(1))); |
| 2612 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2613 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2614 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2615 | |
| 2616 | default: |
| 2617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2618 | << " to " << result_type; |
| 2619 | } |
| 2620 | break; |
| 2621 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimChar: |
| 2623 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimLong: |
| 2625 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimBoolean: |
| 2627 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2628 | case Primitive::kPrimByte: |
| 2629 | case Primitive::kPrimShort: |
| 2630 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2631 | // Processing a Dex `int-to-char' instruction. |
| 2632 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2634 | break; |
| 2635 | |
| 2636 | default: |
| 2637 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2638 | << " to " << result_type; |
| 2639 | } |
| 2640 | break; |
| 2641 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2643 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimBoolean: |
| 2645 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimByte: |
| 2647 | case Primitive::kPrimShort: |
| 2648 | case Primitive::kPrimInt: |
| 2649 | case Primitive::kPrimChar: |
| 2650 | // Processing a Dex `int-to-float' instruction. |
| 2651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2652 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2653 | break; |
| 2654 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2655 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2656 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2657 | InvokeRuntimeCallingConvention calling_convention; |
| 2658 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2659 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2660 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2661 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2662 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2663 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2665 | // Processing a Dex `double-to-float' instruction. |
| 2666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2667 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2668 | break; |
| 2669 | |
| 2670 | default: |
| 2671 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2672 | << " to " << result_type; |
| 2673 | }; |
| 2674 | break; |
| 2675 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2677 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimBoolean: |
| 2679 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimByte: |
| 2681 | case Primitive::kPrimShort: |
| 2682 | case Primitive::kPrimInt: |
| 2683 | case Primitive::kPrimChar: |
| 2684 | // Processing a Dex `int-to-double' instruction. |
| 2685 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2686 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2687 | break; |
| 2688 | |
| 2689 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2690 | // Processing a Dex `long-to-double' instruction. |
| 2691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2692 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2693 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2694 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2695 | break; |
| 2696 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2697 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2698 | // Processing a Dex `float-to-double' instruction. |
| 2699 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2700 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2701 | break; |
| 2702 | |
| 2703 | default: |
| 2704 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2705 | << " to " << result_type; |
| 2706 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2707 | break; |
| 2708 | |
| 2709 | default: |
| 2710 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2711 | << " to " << result_type; |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2716 | LocationSummary* locations = conversion->GetLocations(); |
| 2717 | Location out = locations->Out(); |
| 2718 | Location in = locations->InAt(0); |
| 2719 | Primitive::Type result_type = conversion->GetResultType(); |
| 2720 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2721 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2722 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2723 | case Primitive::kPrimByte: |
| 2724 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2725 | case Primitive::kPrimLong: |
| 2726 | // Type conversion from long to byte is a result of code transformations. |
| 2727 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2728 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimBoolean: |
| 2730 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2731 | case Primitive::kPrimShort: |
| 2732 | case Primitive::kPrimInt: |
| 2733 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2734 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2735 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | |
| 2738 | default: |
| 2739 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2740 | << " to " << result_type; |
| 2741 | } |
| 2742 | break; |
| 2743 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2744 | case Primitive::kPrimShort: |
| 2745 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2746 | case Primitive::kPrimLong: |
| 2747 | // Type conversion from long to short is a result of code transformations. |
| 2748 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2749 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2750 | case Primitive::kPrimBoolean: |
| 2751 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2752 | case Primitive::kPrimByte: |
| 2753 | case Primitive::kPrimInt: |
| 2754 | case Primitive::kPrimChar: |
| 2755 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2756 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2757 | break; |
| 2758 | |
| 2759 | default: |
| 2760 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2761 | << " to " << result_type; |
| 2762 | } |
| 2763 | break; |
| 2764 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2765 | case Primitive::kPrimInt: |
| 2766 | switch (input_type) { |
| 2767 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2768 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2769 | DCHECK(out.IsRegister()); |
| 2770 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2771 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2772 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2773 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2774 | } else { |
| 2775 | DCHECK(in.IsConstant()); |
| 2776 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2777 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2778 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2779 | } |
| 2780 | break; |
| 2781 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2782 | case Primitive::kPrimFloat: { |
| 2783 | // Processing a Dex `float-to-int' instruction. |
| 2784 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2785 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2786 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2787 | break; |
| 2788 | } |
| 2789 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2790 | case Primitive::kPrimDouble: { |
| 2791 | // Processing a Dex `double-to-int' instruction. |
| 2792 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2793 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2794 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2795 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2796 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2797 | |
| 2798 | default: |
| 2799 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2800 | << " to " << result_type; |
| 2801 | } |
| 2802 | break; |
| 2803 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2804 | case Primitive::kPrimLong: |
| 2805 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2806 | case Primitive::kPrimBoolean: |
| 2807 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2808 | case Primitive::kPrimByte: |
| 2809 | case Primitive::kPrimShort: |
| 2810 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2811 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2812 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2813 | DCHECK(out.IsRegisterPair()); |
| 2814 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2815 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2816 | // Sign extension. |
| 2817 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2818 | out.AsRegisterPairLow<Register>(), |
| 2819 | 31); |
| 2820 | break; |
| 2821 | |
| 2822 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2823 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2824 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2825 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2828 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2829 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2830 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2831 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2832 | break; |
| 2833 | |
| 2834 | default: |
| 2835 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2836 | << " to " << result_type; |
| 2837 | } |
| 2838 | break; |
| 2839 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2840 | case Primitive::kPrimChar: |
| 2841 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2842 | case Primitive::kPrimLong: |
| 2843 | // Type conversion from long to char is a result of code transformations. |
| 2844 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2845 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2846 | case Primitive::kPrimBoolean: |
| 2847 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2848 | case Primitive::kPrimByte: |
| 2849 | case Primitive::kPrimShort: |
| 2850 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2851 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2852 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2853 | break; |
| 2854 | |
| 2855 | default: |
| 2856 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2857 | << " to " << result_type; |
| 2858 | } |
| 2859 | break; |
| 2860 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2861 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2862 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2863 | case Primitive::kPrimBoolean: |
| 2864 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2865 | case Primitive::kPrimByte: |
| 2866 | case Primitive::kPrimShort: |
| 2867 | case Primitive::kPrimInt: |
| 2868 | case Primitive::kPrimChar: { |
| 2869 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2870 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2871 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2872 | break; |
| 2873 | } |
| 2874 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2875 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2876 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2877 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2878 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2879 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2880 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2881 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2882 | // Processing a Dex `double-to-float' instruction. |
| 2883 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2884 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2885 | break; |
| 2886 | |
| 2887 | default: |
| 2888 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2889 | << " to " << result_type; |
| 2890 | }; |
| 2891 | break; |
| 2892 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2893 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2894 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2895 | case Primitive::kPrimBoolean: |
| 2896 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2897 | case Primitive::kPrimByte: |
| 2898 | case Primitive::kPrimShort: |
| 2899 | case Primitive::kPrimInt: |
| 2900 | case Primitive::kPrimChar: { |
| 2901 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2903 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2904 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2905 | break; |
| 2906 | } |
| 2907 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2908 | case Primitive::kPrimLong: { |
| 2909 | // Processing a Dex `long-to-double' instruction. |
| 2910 | Register low = in.AsRegisterPairLow<Register>(); |
| 2911 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2912 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2913 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2914 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2915 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2916 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2917 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2918 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2919 | // temp_d = int-to-double(high) |
| 2920 | __ vmovsr(temp_s, high); |
| 2921 | __ vcvtdi(temp_d, temp_s); |
| 2922 | // constant_d = k2Pow32EncodingForDouble |
| 2923 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2924 | // out_d = unsigned-to-double(low) |
| 2925 | __ vmovsr(out_s, low); |
| 2926 | __ vcvtdu(out_d, out_s); |
| 2927 | // out_d += temp_d * constant_d |
| 2928 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2929 | break; |
| 2930 | } |
| 2931 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2932 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2933 | // Processing a Dex `float-to-double' instruction. |
| 2934 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2935 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2936 | break; |
| 2937 | |
| 2938 | default: |
| 2939 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2940 | << " to " << result_type; |
| 2941 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2942 | break; |
| 2943 | |
| 2944 | default: |
| 2945 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2946 | << " to " << result_type; |
| 2947 | } |
| 2948 | } |
| 2949 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2950 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2951 | LocationSummary* locations = |
| 2952 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2953 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2954 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2955 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2956 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2957 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2958 | break; |
| 2959 | } |
| 2960 | |
| 2961 | case Primitive::kPrimLong: { |
| 2962 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2963 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2964 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2965 | break; |
| 2966 | } |
| 2967 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2968 | case Primitive::kPrimFloat: |
| 2969 | case Primitive::kPrimDouble: { |
| 2970 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2971 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2972 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2973 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2974 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2975 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2976 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2977 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2978 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2982 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2983 | Location out = locations->Out(); |
| 2984 | Location first = locations->InAt(0); |
| 2985 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2986 | switch (add->GetResultType()) { |
| 2987 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2988 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2989 | __ add(out.AsRegister<Register>(), |
| 2990 | first.AsRegister<Register>(), |
| 2991 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2992 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2993 | __ AddConstant(out.AsRegister<Register>(), |
| 2994 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2995 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2996 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2997 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2998 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2999 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3000 | if (second.IsConstant()) { |
| 3001 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3002 | GenerateAddLongConst(out, first, value); |
| 3003 | } else { |
| 3004 | DCHECK(second.IsRegisterPair()); |
| 3005 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3006 | first.AsRegisterPairLow<Register>(), |
| 3007 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3008 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3009 | first.AsRegisterPairHigh<Register>(), |
| 3010 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3011 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3012 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3013 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3014 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3015 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3016 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3017 | first.AsFpuRegister<SRegister>(), |
| 3018 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3019 | break; |
| 3020 | |
| 3021 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3022 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3023 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3024 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3025 | break; |
| 3026 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3027 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3028 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3032 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3033 | LocationSummary* locations = |
| 3034 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3035 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3036 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3037 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3038 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3039 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3040 | break; |
| 3041 | } |
| 3042 | |
| 3043 | case Primitive::kPrimLong: { |
| 3044 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3045 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3046 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3047 | break; |
| 3048 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3049 | case Primitive::kPrimFloat: |
| 3050 | case Primitive::kPrimDouble: { |
| 3051 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3052 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3053 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3054 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3055 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3056 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3057 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3058 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3062 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3063 | Location out = locations->Out(); |
| 3064 | Location first = locations->InAt(0); |
| 3065 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3066 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3067 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3068 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3069 | __ sub(out.AsRegister<Register>(), |
| 3070 | first.AsRegister<Register>(), |
| 3071 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3072 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3073 | __ AddConstant(out.AsRegister<Register>(), |
| 3074 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3076 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3077 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3078 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3079 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3080 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3081 | if (second.IsConstant()) { |
| 3082 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3083 | GenerateAddLongConst(out, first, -value); |
| 3084 | } else { |
| 3085 | DCHECK(second.IsRegisterPair()); |
| 3086 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3087 | first.AsRegisterPairLow<Register>(), |
| 3088 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3089 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3090 | first.AsRegisterPairHigh<Register>(), |
| 3091 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3092 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3093 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3094 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3095 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3096 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3097 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3098 | first.AsFpuRegister<SRegister>(), |
| 3099 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3100 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3104 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3105 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3106 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3107 | break; |
| 3108 | } |
| 3109 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3110 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3111 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3112 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3113 | } |
| 3114 | } |
| 3115 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3116 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3117 | LocationSummary* locations = |
| 3118 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3119 | switch (mul->GetResultType()) { |
| 3120 | case Primitive::kPrimInt: |
| 3121 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3123 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3124 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | break; |
| 3126 | } |
| 3127 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3128 | case Primitive::kPrimFloat: |
| 3129 | case Primitive::kPrimDouble: { |
| 3130 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3131 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3132 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3133 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3134 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3135 | |
| 3136 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3137 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3142 | LocationSummary* locations = mul->GetLocations(); |
| 3143 | Location out = locations->Out(); |
| 3144 | Location first = locations->InAt(0); |
| 3145 | Location second = locations->InAt(1); |
| 3146 | switch (mul->GetResultType()) { |
| 3147 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3148 | __ mul(out.AsRegister<Register>(), |
| 3149 | first.AsRegister<Register>(), |
| 3150 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3151 | break; |
| 3152 | } |
| 3153 | case Primitive::kPrimLong: { |
| 3154 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3155 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3156 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3157 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3158 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3159 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3160 | |
| 3161 | // Extra checks to protect caused by the existence of R1_R2. |
| 3162 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3163 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3164 | DCHECK_NE(out_hi, in1_lo); |
| 3165 | DCHECK_NE(out_hi, in2_lo); |
| 3166 | |
| 3167 | // input: in1 - 64 bits, in2 - 64 bits |
| 3168 | // output: out |
| 3169 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3170 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3171 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3172 | |
| 3173 | // IP <- in1.lo * in2.hi |
| 3174 | __ mul(IP, in1_lo, in2_hi); |
| 3175 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3176 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3177 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3178 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3179 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3180 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3181 | break; |
| 3182 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3183 | |
| 3184 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3185 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3186 | first.AsFpuRegister<SRegister>(), |
| 3187 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3188 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3192 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3193 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3194 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3195 | break; |
| 3196 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | |
| 3198 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3199 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3200 | } |
| 3201 | } |
| 3202 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3203 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3204 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3205 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3206 | |
| 3207 | LocationSummary* locations = instruction->GetLocations(); |
| 3208 | Location second = locations->InAt(1); |
| 3209 | DCHECK(second.IsConstant()); |
| 3210 | |
| 3211 | Register out = locations->Out().AsRegister<Register>(); |
| 3212 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3213 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3214 | DCHECK(imm == 1 || imm == -1); |
| 3215 | |
| 3216 | if (instruction->IsRem()) { |
| 3217 | __ LoadImmediate(out, 0); |
| 3218 | } else { |
| 3219 | if (imm == 1) { |
| 3220 | __ Mov(out, dividend); |
| 3221 | } else { |
| 3222 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3223 | } |
| 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3228 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3229 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3230 | |
| 3231 | LocationSummary* locations = instruction->GetLocations(); |
| 3232 | Location second = locations->InAt(1); |
| 3233 | DCHECK(second.IsConstant()); |
| 3234 | |
| 3235 | Register out = locations->Out().AsRegister<Register>(); |
| 3236 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3237 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3238 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3239 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3240 | int ctz_imm = CTZ(abs_imm); |
| 3241 | |
| 3242 | if (ctz_imm == 1) { |
| 3243 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3244 | } else { |
| 3245 | __ Asr(temp, dividend, 31); |
| 3246 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3247 | } |
| 3248 | __ add(out, temp, ShifterOperand(dividend)); |
| 3249 | |
| 3250 | if (instruction->IsDiv()) { |
| 3251 | __ Asr(out, out, ctz_imm); |
| 3252 | if (imm < 0) { |
| 3253 | __ rsb(out, out, ShifterOperand(0)); |
| 3254 | } |
| 3255 | } else { |
| 3256 | __ ubfx(out, out, 0, ctz_imm); |
| 3257 | __ sub(out, out, ShifterOperand(temp)); |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3262 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3263 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3264 | |
| 3265 | LocationSummary* locations = instruction->GetLocations(); |
| 3266 | Location second = locations->InAt(1); |
| 3267 | DCHECK(second.IsConstant()); |
| 3268 | |
| 3269 | Register out = locations->Out().AsRegister<Register>(); |
| 3270 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3271 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3272 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3273 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3274 | |
| 3275 | int64_t magic; |
| 3276 | int shift; |
| 3277 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3278 | |
| 3279 | __ LoadImmediate(temp1, magic); |
| 3280 | __ smull(temp2, temp1, dividend, temp1); |
| 3281 | |
| 3282 | if (imm > 0 && magic < 0) { |
| 3283 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3284 | } else if (imm < 0 && magic > 0) { |
| 3285 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3286 | } |
| 3287 | |
| 3288 | if (shift != 0) { |
| 3289 | __ Asr(temp1, temp1, shift); |
| 3290 | } |
| 3291 | |
| 3292 | if (instruction->IsDiv()) { |
| 3293 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3294 | } else { |
| 3295 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3296 | // TODO: Strength reduction for mls. |
| 3297 | __ LoadImmediate(temp2, imm); |
| 3298 | __ mls(out, temp1, temp2, dividend); |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3303 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3304 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3305 | |
| 3306 | LocationSummary* locations = instruction->GetLocations(); |
| 3307 | Location second = locations->InAt(1); |
| 3308 | DCHECK(second.IsConstant()); |
| 3309 | |
| 3310 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3311 | if (imm == 0) { |
| 3312 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3313 | } else if (imm == 1 || imm == -1) { |
| 3314 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3315 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3316 | DivRemByPowerOfTwo(instruction); |
| 3317 | } else { |
| 3318 | DCHECK(imm <= -2 || imm >= 2); |
| 3319 | GenerateDivRemWithAnyConstant(instruction); |
| 3320 | } |
| 3321 | } |
| 3322 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3323 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3324 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3325 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3326 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3327 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3328 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3329 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3330 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3331 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3332 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3333 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3336 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3337 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3338 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3339 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3340 | if (div->InputAt(1)->IsConstant()) { |
| 3341 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3342 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3343 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3344 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3345 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3346 | // No temp register required. |
| 3347 | } else { |
| 3348 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3349 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3350 | locations->AddTemp(Location::RequiresRegister()); |
| 3351 | } |
| 3352 | } |
| 3353 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3355 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3356 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3357 | } else { |
| 3358 | InvokeRuntimeCallingConvention calling_convention; |
| 3359 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3360 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3361 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3362 | // we only need the former. |
| 3363 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3364 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3365 | break; |
| 3366 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3367 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3368 | InvokeRuntimeCallingConvention calling_convention; |
| 3369 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3370 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3371 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3372 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3373 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3374 | break; |
| 3375 | } |
| 3376 | case Primitive::kPrimFloat: |
| 3377 | case Primitive::kPrimDouble: { |
| 3378 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3379 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3380 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3381 | break; |
| 3382 | } |
| 3383 | |
| 3384 | default: |
| 3385 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3390 | LocationSummary* locations = div->GetLocations(); |
| 3391 | Location out = locations->Out(); |
| 3392 | Location first = locations->InAt(0); |
| 3393 | Location second = locations->InAt(1); |
| 3394 | |
| 3395 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3396 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3397 | if (second.IsConstant()) { |
| 3398 | GenerateDivRemConstantIntegral(div); |
| 3399 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3400 | __ sdiv(out.AsRegister<Register>(), |
| 3401 | first.AsRegister<Register>(), |
| 3402 | second.AsRegister<Register>()); |
| 3403 | } else { |
| 3404 | InvokeRuntimeCallingConvention calling_convention; |
| 3405 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3406 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3407 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3408 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3409 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3410 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3411 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3412 | break; |
| 3413 | } |
| 3414 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3415 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3416 | InvokeRuntimeCallingConvention calling_convention; |
| 3417 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3418 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3419 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3420 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3421 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3422 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3423 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3424 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3425 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3426 | break; |
| 3427 | } |
| 3428 | |
| 3429 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3430 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3431 | first.AsFpuRegister<SRegister>(), |
| 3432 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3433 | break; |
| 3434 | } |
| 3435 | |
| 3436 | case Primitive::kPrimDouble: { |
| 3437 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3438 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3439 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3440 | break; |
| 3441 | } |
| 3442 | |
| 3443 | default: |
| 3444 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3445 | } |
| 3446 | } |
| 3447 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3448 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3449 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3450 | |
| 3451 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3452 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3453 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3454 | // sdiv will be replaced by other instruction sequence. |
| 3455 | call_kind = LocationSummary::kNoCall; |
| 3456 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3457 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3458 | // Have hardware divide instruction for int, do it with three instructions. |
| 3459 | call_kind = LocationSummary::kNoCall; |
| 3460 | } |
| 3461 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3462 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3463 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3464 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3465 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3466 | if (rem->InputAt(1)->IsConstant()) { |
| 3467 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3468 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3469 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3470 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3471 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3472 | // No temp register required. |
| 3473 | } else { |
| 3474 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3475 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3476 | locations->AddTemp(Location::RequiresRegister()); |
| 3477 | } |
| 3478 | } |
| 3479 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3480 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3481 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3482 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3483 | locations->AddTemp(Location::RequiresRegister()); |
| 3484 | } else { |
| 3485 | InvokeRuntimeCallingConvention calling_convention; |
| 3486 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3487 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3488 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3489 | // we only need the latter. |
| 3490 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3491 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3492 | break; |
| 3493 | } |
| 3494 | case Primitive::kPrimLong: { |
| 3495 | InvokeRuntimeCallingConvention calling_convention; |
| 3496 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3497 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3498 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3499 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3500 | // The runtime helper puts the output in R2,R3. |
| 3501 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3502 | break; |
| 3503 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3504 | case Primitive::kPrimFloat: { |
| 3505 | InvokeRuntimeCallingConvention calling_convention; |
| 3506 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3507 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3508 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3509 | break; |
| 3510 | } |
| 3511 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3512 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3513 | InvokeRuntimeCallingConvention calling_convention; |
| 3514 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3515 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3516 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3517 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3518 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3519 | break; |
| 3520 | } |
| 3521 | |
| 3522 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3523 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3528 | LocationSummary* locations = rem->GetLocations(); |
| 3529 | Location out = locations->Out(); |
| 3530 | Location first = locations->InAt(0); |
| 3531 | Location second = locations->InAt(1); |
| 3532 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3533 | Primitive::Type type = rem->GetResultType(); |
| 3534 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3535 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3536 | if (second.IsConstant()) { |
| 3537 | GenerateDivRemConstantIntegral(rem); |
| 3538 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3539 | Register reg1 = first.AsRegister<Register>(); |
| 3540 | Register reg2 = second.AsRegister<Register>(); |
| 3541 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3542 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3543 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3544 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3545 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3546 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3547 | } else { |
| 3548 | InvokeRuntimeCallingConvention calling_convention; |
| 3549 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3550 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3551 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3552 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3553 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3554 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3555 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3556 | break; |
| 3557 | } |
| 3558 | |
| 3559 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3560 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3561 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | break; |
| 3563 | } |
| 3564 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3565 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3566 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3567 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3568 | break; |
| 3569 | } |
| 3570 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3571 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3572 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3573 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | } |
| 3576 | |
| 3577 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3578 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3582 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3583 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3584 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3588 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3589 | codegen_->AddSlowPath(slow_path); |
| 3590 | |
| 3591 | LocationSummary* locations = instruction->GetLocations(); |
| 3592 | Location value = locations->InAt(0); |
| 3593 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3594 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3595 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3596 | case Primitive::kPrimByte: |
| 3597 | case Primitive::kPrimChar: |
| 3598 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3599 | case Primitive::kPrimInt: { |
| 3600 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3601 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3602 | } else { |
| 3603 | DCHECK(value.IsConstant()) << value; |
| 3604 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3605 | __ b(slow_path->GetEntryLabel()); |
| 3606 | } |
| 3607 | } |
| 3608 | break; |
| 3609 | } |
| 3610 | case Primitive::kPrimLong: { |
| 3611 | if (value.IsRegisterPair()) { |
| 3612 | __ orrs(IP, |
| 3613 | value.AsRegisterPairLow<Register>(), |
| 3614 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3615 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3616 | } else { |
| 3617 | DCHECK(value.IsConstant()) << value; |
| 3618 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3619 | __ b(slow_path->GetEntryLabel()); |
| 3620 | } |
| 3621 | } |
| 3622 | break; |
| 3623 | default: |
| 3624 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3625 | } |
| 3626 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3629 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3630 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3631 | Location rhs = locations->InAt(1); |
| 3632 | Register out = locations->Out().AsRegister<Register>(); |
| 3633 | |
| 3634 | if (rhs.IsConstant()) { |
| 3635 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3636 | // so map all rotations to a +ve. equivalent in that range. |
| 3637 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3638 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3639 | if (rot) { |
| 3640 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3641 | // (e.g. left by 2 bits == right by 30.) |
| 3642 | __ Ror(out, in, rot); |
| 3643 | } else if (out != in) { |
| 3644 | __ Mov(out, in); |
| 3645 | } |
| 3646 | } else { |
| 3647 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3652 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3653 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3654 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3655 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3656 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3657 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3658 | Location rhs = locations->InAt(1); |
| 3659 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3660 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3661 | |
| 3662 | if (rhs.IsConstant()) { |
| 3663 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3664 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3665 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3666 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3667 | // logic below to a simple pair of binary orr. |
| 3668 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3669 | if (rot >= kArmBitsPerWord) { |
| 3670 | rot -= kArmBitsPerWord; |
| 3671 | std::swap(in_reg_hi, in_reg_lo); |
| 3672 | } |
| 3673 | // Rotate, or mov to out for zero or word size rotations. |
| 3674 | if (rot != 0u) { |
| 3675 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3676 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3677 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3678 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3679 | } else { |
| 3680 | __ Mov(out_reg_lo, in_reg_lo); |
| 3681 | __ Mov(out_reg_hi, in_reg_hi); |
| 3682 | } |
| 3683 | } else { |
| 3684 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3685 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3686 | Label end; |
| 3687 | Label shift_by_32_plus_shift_right; |
| 3688 | |
| 3689 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3690 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3691 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3692 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3693 | |
| 3694 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3695 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3696 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3697 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3698 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3699 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3700 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3701 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3702 | __ b(&end); |
| 3703 | |
| 3704 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3705 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3706 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3707 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3708 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3709 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3710 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3711 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3712 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3713 | |
| 3714 | __ Bind(&end); |
| 3715 | } |
| 3716 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3717 | |
| 3718 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3719 | LocationSummary* locations = |
| 3720 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3721 | switch (ror->GetResultType()) { |
| 3722 | case Primitive::kPrimInt: { |
| 3723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3724 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3725 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3726 | break; |
| 3727 | } |
| 3728 | case Primitive::kPrimLong: { |
| 3729 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3730 | if (ror->InputAt(1)->IsConstant()) { |
| 3731 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3732 | } else { |
| 3733 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3734 | locations->AddTemp(Location::RequiresRegister()); |
| 3735 | locations->AddTemp(Location::RequiresRegister()); |
| 3736 | } |
| 3737 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3738 | break; |
| 3739 | } |
| 3740 | default: |
| 3741 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3742 | } |
| 3743 | } |
| 3744 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3745 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3746 | LocationSummary* locations = ror->GetLocations(); |
| 3747 | Primitive::Type type = ror->GetResultType(); |
| 3748 | switch (type) { |
| 3749 | case Primitive::kPrimInt: { |
| 3750 | HandleIntegerRotate(locations); |
| 3751 | break; |
| 3752 | } |
| 3753 | case Primitive::kPrimLong: { |
| 3754 | HandleLongRotate(locations); |
| 3755 | break; |
| 3756 | } |
| 3757 | default: |
| 3758 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3759 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3760 | } |
| 3761 | } |
| 3762 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3763 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3764 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3765 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3766 | LocationSummary* locations = |
| 3767 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3768 | |
| 3769 | switch (op->GetResultType()) { |
| 3770 | case Primitive::kPrimInt: { |
| 3771 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3772 | if (op->InputAt(1)->IsConstant()) { |
| 3773 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3774 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3775 | } else { |
| 3776 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3777 | // Make the output overlap, as it will be used to hold the masked |
| 3778 | // second input. |
| 3779 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3780 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | } |
| 3783 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3784 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3785 | if (op->InputAt(1)->IsConstant()) { |
| 3786 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3787 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3788 | // don't clash with high registers which the register allocator currently guarantees. |
| 3789 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3790 | } else { |
| 3791 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3792 | locations->AddTemp(Location::RequiresRegister()); |
| 3793 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3794 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3795 | break; |
| 3796 | } |
| 3797 | default: |
| 3798 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3803 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3804 | |
| 3805 | LocationSummary* locations = op->GetLocations(); |
| 3806 | Location out = locations->Out(); |
| 3807 | Location first = locations->InAt(0); |
| 3808 | Location second = locations->InAt(1); |
| 3809 | |
| 3810 | Primitive::Type type = op->GetResultType(); |
| 3811 | switch (type) { |
| 3812 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3813 | Register out_reg = out.AsRegister<Register>(); |
| 3814 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3815 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3816 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3817 | // 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] | 3818 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3819 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3820 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3821 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3822 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3823 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3824 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3825 | } |
| 3826 | } else { |
| 3827 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3828 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3829 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3830 | __ Mov(out_reg, first_reg); |
| 3831 | } else if (op->IsShl()) { |
| 3832 | __ Lsl(out_reg, first_reg, shift_value); |
| 3833 | } else if (op->IsShr()) { |
| 3834 | __ Asr(out_reg, first_reg, shift_value); |
| 3835 | } else { |
| 3836 | __ Lsr(out_reg, first_reg, shift_value); |
| 3837 | } |
| 3838 | } |
| 3839 | break; |
| 3840 | } |
| 3841 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3842 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3843 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3844 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3845 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3846 | Register low = first.AsRegisterPairLow<Register>(); |
| 3847 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3848 | if (second.IsRegister()) { |
| 3849 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3850 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3851 | Register second_reg = second.AsRegister<Register>(); |
| 3852 | |
| 3853 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3854 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3855 | // Shift the high part |
| 3856 | __ Lsl(o_h, high, o_l); |
| 3857 | // Shift the low part and `or` what overflew on the high part |
| 3858 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3859 | __ Lsr(temp, low, temp); |
| 3860 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3861 | // If the shift is > 32 bits, override the high part |
| 3862 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3863 | __ it(PL); |
| 3864 | __ Lsl(o_h, low, temp, PL); |
| 3865 | // Shift the low part |
| 3866 | __ Lsl(o_l, low, o_l); |
| 3867 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3868 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3869 | // Shift the low part |
| 3870 | __ Lsr(o_l, low, o_h); |
| 3871 | // Shift the high part and `or` what underflew on the low part |
| 3872 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3873 | __ Lsl(temp, high, temp); |
| 3874 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3875 | // If the shift is > 32 bits, override the low part |
| 3876 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3877 | __ it(PL); |
| 3878 | __ Asr(o_l, high, temp, PL); |
| 3879 | // Shift the high part |
| 3880 | __ Asr(o_h, high, o_h); |
| 3881 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3882 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3883 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3884 | __ Lsr(o_l, low, o_h); |
| 3885 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3886 | __ Lsl(temp, high, temp); |
| 3887 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3888 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3889 | __ it(PL); |
| 3890 | __ Lsr(o_l, high, temp, PL); |
| 3891 | __ Lsr(o_h, high, o_h); |
| 3892 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3893 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3894 | // Register allocator doesn't create partial overlap. |
| 3895 | DCHECK_NE(o_l, high); |
| 3896 | DCHECK_NE(o_h, low); |
| 3897 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3898 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3899 | if (shift_value > 32) { |
| 3900 | if (op->IsShl()) { |
| 3901 | __ Lsl(o_h, low, shift_value - 32); |
| 3902 | __ LoadImmediate(o_l, 0); |
| 3903 | } else if (op->IsShr()) { |
| 3904 | __ Asr(o_l, high, shift_value - 32); |
| 3905 | __ Asr(o_h, high, 31); |
| 3906 | } else { |
| 3907 | __ Lsr(o_l, high, shift_value - 32); |
| 3908 | __ LoadImmediate(o_h, 0); |
| 3909 | } |
| 3910 | } else if (shift_value == 32) { |
| 3911 | if (op->IsShl()) { |
| 3912 | __ mov(o_h, ShifterOperand(low)); |
| 3913 | __ LoadImmediate(o_l, 0); |
| 3914 | } else if (op->IsShr()) { |
| 3915 | __ mov(o_l, ShifterOperand(high)); |
| 3916 | __ Asr(o_h, high, 31); |
| 3917 | } else { |
| 3918 | __ mov(o_l, ShifterOperand(high)); |
| 3919 | __ LoadImmediate(o_h, 0); |
| 3920 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3921 | } else if (shift_value == 1) { |
| 3922 | if (op->IsShl()) { |
| 3923 | __ Lsls(o_l, low, 1); |
| 3924 | __ adc(o_h, high, ShifterOperand(high)); |
| 3925 | } else if (op->IsShr()) { |
| 3926 | __ Asrs(o_h, high, 1); |
| 3927 | __ Rrx(o_l, low); |
| 3928 | } else { |
| 3929 | __ Lsrs(o_h, high, 1); |
| 3930 | __ Rrx(o_l, low); |
| 3931 | } |
| 3932 | } else { |
| 3933 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3934 | if (op->IsShl()) { |
| 3935 | __ Lsl(o_h, high, shift_value); |
| 3936 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3937 | __ Lsl(o_l, low, shift_value); |
| 3938 | } else if (op->IsShr()) { |
| 3939 | __ Lsr(o_l, low, shift_value); |
| 3940 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3941 | __ Asr(o_h, high, shift_value); |
| 3942 | } else { |
| 3943 | __ Lsr(o_l, low, shift_value); |
| 3944 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3945 | __ Lsr(o_h, high, shift_value); |
| 3946 | } |
| 3947 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3948 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3949 | break; |
| 3950 | } |
| 3951 | default: |
| 3952 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3953 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3958 | HandleShift(shl); |
| 3959 | } |
| 3960 | |
| 3961 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3962 | HandleShift(shl); |
| 3963 | } |
| 3964 | |
| 3965 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3966 | HandleShift(shr); |
| 3967 | } |
| 3968 | |
| 3969 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3970 | HandleShift(shr); |
| 3971 | } |
| 3972 | |
| 3973 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3974 | HandleShift(ushr); |
| 3975 | } |
| 3976 | |
| 3977 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3978 | HandleShift(ushr); |
| 3979 | } |
| 3980 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3981 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3982 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3983 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3984 | if (instruction->IsStringAlloc()) { |
| 3985 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3986 | } else { |
| 3987 | InvokeRuntimeCallingConvention calling_convention; |
| 3988 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3989 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3990 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3994 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3995 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3996 | if (instruction->IsStringAlloc()) { |
| 3997 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3998 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3999 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4000 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4001 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4002 | __ blx(LR); |
| 4003 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4004 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4005 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4006 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4007 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4008 | } |
| 4009 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4010 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4011 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4012 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4013 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4014 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4015 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4016 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4020 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4021 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4022 | QuickEntrypointEnum entrypoint = |
| 4023 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4024 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4025 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4026 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4029 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4030 | LocationSummary* locations = |
| 4031 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4032 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4033 | if (location.IsStackSlot()) { |
| 4034 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4035 | } else if (location.IsDoubleStackSlot()) { |
| 4036 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4037 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4038 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4039 | } |
| 4040 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4041 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4042 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4043 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4047 | LocationSummary* locations = |
| 4048 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4049 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4050 | } |
| 4051 | |
| 4052 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4053 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4054 | } |
| 4055 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4056 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4057 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4058 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4059 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4060 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4061 | } |
| 4062 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4063 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4064 | LocationSummary* locations = not_->GetLocations(); |
| 4065 | Location out = locations->Out(); |
| 4066 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4067 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4068 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4069 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4070 | break; |
| 4071 | |
| 4072 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4073 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4074 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4075 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4076 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4077 | break; |
| 4078 | |
| 4079 | default: |
| 4080 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4081 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4082 | } |
| 4083 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4084 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4085 | LocationSummary* locations = |
| 4086 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4088 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4089 | } |
| 4090 | |
| 4091 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4092 | LocationSummary* locations = bool_not->GetLocations(); |
| 4093 | Location out = locations->Out(); |
| 4094 | Location in = locations->InAt(0); |
| 4095 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4096 | } |
| 4097 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4098 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4099 | LocationSummary* locations = |
| 4100 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4101 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4102 | case Primitive::kPrimBoolean: |
| 4103 | case Primitive::kPrimByte: |
| 4104 | case Primitive::kPrimShort: |
| 4105 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4106 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4107 | case Primitive::kPrimLong: { |
| 4108 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4109 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4110 | // Output overlaps because it is written before doing the low comparison. |
| 4111 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4112 | break; |
| 4113 | } |
| 4114 | case Primitive::kPrimFloat: |
| 4115 | case Primitive::kPrimDouble: { |
| 4116 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4117 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4118 | locations->SetOut(Location::RequiresRegister()); |
| 4119 | break; |
| 4120 | } |
| 4121 | default: |
| 4122 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4123 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4127 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4128 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4129 | Location left = locations->InAt(0); |
| 4130 | Location right = locations->InAt(1); |
| 4131 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4132 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4133 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4134 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4135 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4136 | case Primitive::kPrimBoolean: |
| 4137 | case Primitive::kPrimByte: |
| 4138 | case Primitive::kPrimShort: |
| 4139 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4140 | case Primitive::kPrimInt: { |
| 4141 | __ LoadImmediate(out, 0); |
| 4142 | __ cmp(left.AsRegister<Register>(), |
| 4143 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4144 | less_cond = LT; |
| 4145 | break; |
| 4146 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4147 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4148 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4149 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4150 | __ b(&less, LT); |
| 4151 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4152 | // 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] | 4153 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4154 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4155 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4156 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4157 | break; |
| 4158 | } |
| 4159 | case Primitive::kPrimFloat: |
| 4160 | case Primitive::kPrimDouble: { |
| 4161 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4162 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4163 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4164 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4165 | break; |
| 4166 | } |
| 4167 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4168 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4169 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4170 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4171 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4172 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4173 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4174 | |
| 4175 | __ Bind(&greater); |
| 4176 | __ LoadImmediate(out, 1); |
| 4177 | __ b(&done); |
| 4178 | |
| 4179 | __ Bind(&less); |
| 4180 | __ LoadImmediate(out, -1); |
| 4181 | |
| 4182 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4183 | } |
| 4184 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4185 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4186 | LocationSummary* locations = |
| 4187 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4188 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4189 | locations->SetInAt(i, Location::Any()); |
| 4190 | } |
| 4191 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4192 | } |
| 4193 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4194 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4195 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4198 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4199 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4200 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4201 | switch (kind) { |
| 4202 | case MemBarrierKind::kAnyStore: |
| 4203 | case MemBarrierKind::kLoadAny: |
| 4204 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4205 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4206 | break; |
| 4207 | } |
| 4208 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4209 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4210 | break; |
| 4211 | } |
| 4212 | default: |
| 4213 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4214 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4215 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4219 | uint32_t offset, |
| 4220 | Register out_lo, |
| 4221 | Register out_hi) { |
| 4222 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4223 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4224 | // `offset` into `out_lo` does not clutter `addr`. |
| 4225 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4227 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4228 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4229 | } |
| 4230 | __ ldrexd(out_lo, out_hi, addr); |
| 4231 | } |
| 4232 | |
| 4233 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4234 | uint32_t offset, |
| 4235 | Register value_lo, |
| 4236 | Register value_hi, |
| 4237 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4238 | Register temp2, |
| 4239 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4240 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4241 | if (offset != 0) { |
| 4242 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4243 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4244 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4245 | } |
| 4246 | __ Bind(&fail); |
| 4247 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4248 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4249 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4250 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4251 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4252 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4256 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4257 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4258 | LocationSummary* locations = |
| 4259 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4260 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4261 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4262 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4263 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4264 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4265 | } else { |
| 4266 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4267 | } |
| 4268 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4269 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4270 | bool generate_volatile = field_info.IsVolatile() |
| 4271 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4272 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4273 | bool needs_write_barrier = |
| 4274 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4275 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4276 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4277 | if (needs_write_barrier) { |
| 4278 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4279 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4280 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4281 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | // - registers need to be consecutive |
| 4283 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4284 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4285 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4286 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4287 | |
| 4288 | locations->AddTemp(Location::RequiresRegister()); |
| 4289 | locations->AddTemp(Location::RequiresRegister()); |
| 4290 | if (field_type == Primitive::kPrimDouble) { |
| 4291 | // For doubles we need two more registers to copy the value. |
| 4292 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4293 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4294 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4295 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4298 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4299 | const FieldInfo& field_info, |
| 4300 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4301 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4302 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4303 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4304 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4305 | Location value = locations->InAt(1); |
| 4306 | |
| 4307 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4308 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4309 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4310 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4311 | bool needs_write_barrier = |
| 4312 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4313 | |
| 4314 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4315 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4316 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4317 | |
| 4318 | switch (field_type) { |
| 4319 | case Primitive::kPrimBoolean: |
| 4320 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4321 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4322 | break; |
| 4323 | } |
| 4324 | |
| 4325 | case Primitive::kPrimShort: |
| 4326 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4327 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4328 | break; |
| 4329 | } |
| 4330 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4331 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4332 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4333 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4334 | // Note that in the case where `value` is a null reference, |
| 4335 | // we do not enter this block, as a null reference does not |
| 4336 | // need poisoning. |
| 4337 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4338 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4339 | __ Mov(temp, value.AsRegister<Register>()); |
| 4340 | __ PoisonHeapReference(temp); |
| 4341 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4342 | } else { |
| 4343 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4344 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4345 | break; |
| 4346 | } |
| 4347 | |
| 4348 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4349 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4350 | GenerateWideAtomicStore(base, offset, |
| 4351 | value.AsRegisterPairLow<Register>(), |
| 4352 | value.AsRegisterPairHigh<Register>(), |
| 4353 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4354 | locations->GetTemp(1).AsRegister<Register>(), |
| 4355 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4356 | } else { |
| 4357 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4358 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4359 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4360 | break; |
| 4361 | } |
| 4362 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4363 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4364 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4365 | break; |
| 4366 | } |
| 4367 | |
| 4368 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4369 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4370 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4371 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4372 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4373 | |
| 4374 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4375 | |
| 4376 | GenerateWideAtomicStore(base, offset, |
| 4377 | value_reg_lo, |
| 4378 | value_reg_hi, |
| 4379 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4380 | locations->GetTemp(3).AsRegister<Register>(), |
| 4381 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4382 | } else { |
| 4383 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4384 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4385 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4386 | break; |
| 4387 | } |
| 4388 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4389 | case Primitive::kPrimVoid: |
| 4390 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4391 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4392 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4393 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4394 | // Longs and doubles are handled in the switch. |
| 4395 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4396 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4397 | } |
| 4398 | |
| 4399 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4400 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4401 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4402 | codegen_->MarkGCCard( |
| 4403 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4406 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4407 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4408 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4409 | } |
| 4410 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4411 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4412 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4413 | |
| 4414 | bool object_field_get_with_read_barrier = |
| 4415 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4416 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4417 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4418 | object_field_get_with_read_barrier ? |
| 4419 | LocationSummary::kCallOnSlowPath : |
| 4420 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4421 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4422 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4423 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4424 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4425 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4426 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4427 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4428 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4429 | // The output overlaps in case of volatile long: we don't want the |
| 4430 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4431 | // object's location. Likewise, in the case of an object field get |
| 4432 | // with read barriers enabled, we do not want the load to overwrite |
| 4433 | // the object's location, as we need it to emit the read barrier. |
| 4434 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4435 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4436 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4437 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4438 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4439 | } else { |
| 4440 | locations->SetOut(Location::RequiresRegister(), |
| 4441 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4442 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4443 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4444 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4445 | // - registers need to be consecutive |
| 4446 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4447 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4448 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4449 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4450 | locations->AddTemp(Location::RequiresRegister()); |
| 4451 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4452 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4453 | // We need a temporary register for the read barrier marking slow |
| 4454 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4455 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4456 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4457 | } |
| 4458 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4459 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4460 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4461 | << input->GetType(); |
| 4462 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4463 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4464 | return Location::ConstantLocation(input->AsConstant()); |
| 4465 | } else { |
| 4466 | return Location::RequiresFpuRegister(); |
| 4467 | } |
| 4468 | } |
| 4469 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4470 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4471 | Opcode opcode) { |
| 4472 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4473 | if (constant->IsConstant() && |
| 4474 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4475 | return Location::ConstantLocation(constant->AsConstant()); |
| 4476 | } |
| 4477 | return Location::RequiresRegister(); |
| 4478 | } |
| 4479 | |
| 4480 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4481 | Opcode opcode) { |
| 4482 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4483 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4484 | Opcode high_opcode = opcode; |
| 4485 | SetCc low_set_cc = kCcDontCare; |
| 4486 | switch (opcode) { |
| 4487 | case SUB: |
| 4488 | // Flip the operation to an ADD. |
| 4489 | value = -value; |
| 4490 | opcode = ADD; |
| 4491 | FALLTHROUGH_INTENDED; |
| 4492 | case ADD: |
| 4493 | if (Low32Bits(value) == 0u) { |
| 4494 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4495 | } |
| 4496 | high_opcode = ADC; |
| 4497 | low_set_cc = kCcSet; |
| 4498 | break; |
| 4499 | default: |
| 4500 | break; |
| 4501 | } |
| 4502 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4503 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4504 | } else { |
| 4505 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4506 | } |
| 4507 | } |
| 4508 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4509 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4510 | Opcode opcode, |
| 4511 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4512 | ShifterOperand so; |
| 4513 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4514 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4515 | return true; |
| 4516 | } |
| 4517 | Opcode neg_opcode = kNoOperand; |
| 4518 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4519 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4520 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4521 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4522 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4523 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4524 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4525 | default: |
| 4526 | return false; |
| 4527 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4528 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4529 | } |
| 4530 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4531 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4532 | const FieldInfo& field_info) { |
| 4533 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4534 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4536 | Location base_loc = locations->InAt(0); |
| 4537 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4538 | Location out = locations->Out(); |
| 4539 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4540 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4541 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4542 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4543 | |
| 4544 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4545 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4546 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4547 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4548 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4549 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4550 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4551 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4552 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4553 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4555 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4556 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4557 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4558 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4559 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4560 | |
| 4561 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4562 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4563 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4564 | |
| 4565 | case Primitive::kPrimNot: { |
| 4566 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4567 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4568 | Location temp_loc = locations->GetTemp(0); |
| 4569 | // Note that a potential implicit null check is handled in this |
| 4570 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4571 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4572 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4573 | if (is_volatile) { |
| 4574 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4575 | } |
| 4576 | } else { |
| 4577 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4578 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4579 | if (is_volatile) { |
| 4580 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4581 | } |
| 4582 | // If read barriers are enabled, emit read barriers other than |
| 4583 | // Baker's using a slow path (and also unpoison the loaded |
| 4584 | // reference, if heap poisoning is enabled). |
| 4585 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4586 | } |
| 4587 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4588 | } |
| 4589 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4590 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4591 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4592 | GenerateWideAtomicLoad(base, offset, |
| 4593 | out.AsRegisterPairLow<Register>(), |
| 4594 | out.AsRegisterPairHigh<Register>()); |
| 4595 | } else { |
| 4596 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4597 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4598 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4599 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4600 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4601 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4602 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4603 | |
| 4604 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4605 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4606 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4607 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4608 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4609 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4610 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4611 | __ vmovdrr(out_reg, lo, hi); |
| 4612 | } else { |
| 4613 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4614 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4615 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4616 | break; |
| 4617 | } |
| 4618 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4619 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4620 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4621 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4622 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4623 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4624 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4625 | // Potential implicit null checks, in the case of reference or |
| 4626 | // double fields, are handled in the previous switch statement. |
| 4627 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4628 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4629 | } |
| 4630 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4631 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4632 | if (field_type == Primitive::kPrimNot) { |
| 4633 | // Memory barriers, in the case of references, are also handled |
| 4634 | // in the previous switch statement. |
| 4635 | } else { |
| 4636 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4637 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4638 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4642 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4643 | } |
| 4644 | |
| 4645 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4646 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4650 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4651 | } |
| 4652 | |
| 4653 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4654 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4655 | } |
| 4656 | |
| 4657 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4658 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4659 | } |
| 4660 | |
| 4661 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4662 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4663 | } |
| 4664 | |
| 4665 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4666 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4667 | } |
| 4668 | |
| 4669 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4670 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4671 | } |
| 4672 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4673 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4674 | HUnresolvedInstanceFieldGet* instruction) { |
| 4675 | FieldAccessCallingConventionARM calling_convention; |
| 4676 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4677 | instruction, instruction->GetFieldType(), calling_convention); |
| 4678 | } |
| 4679 | |
| 4680 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4681 | HUnresolvedInstanceFieldGet* instruction) { |
| 4682 | FieldAccessCallingConventionARM calling_convention; |
| 4683 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4684 | instruction->GetFieldType(), |
| 4685 | instruction->GetFieldIndex(), |
| 4686 | instruction->GetDexPc(), |
| 4687 | calling_convention); |
| 4688 | } |
| 4689 | |
| 4690 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4691 | HUnresolvedInstanceFieldSet* instruction) { |
| 4692 | FieldAccessCallingConventionARM calling_convention; |
| 4693 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4694 | instruction, instruction->GetFieldType(), calling_convention); |
| 4695 | } |
| 4696 | |
| 4697 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4698 | HUnresolvedInstanceFieldSet* instruction) { |
| 4699 | FieldAccessCallingConventionARM calling_convention; |
| 4700 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4701 | instruction->GetFieldType(), |
| 4702 | instruction->GetFieldIndex(), |
| 4703 | instruction->GetDexPc(), |
| 4704 | calling_convention); |
| 4705 | } |
| 4706 | |
| 4707 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4708 | HUnresolvedStaticFieldGet* instruction) { |
| 4709 | FieldAccessCallingConventionARM calling_convention; |
| 4710 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4711 | instruction, instruction->GetFieldType(), calling_convention); |
| 4712 | } |
| 4713 | |
| 4714 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4715 | HUnresolvedStaticFieldGet* instruction) { |
| 4716 | FieldAccessCallingConventionARM calling_convention; |
| 4717 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4718 | instruction->GetFieldType(), |
| 4719 | instruction->GetFieldIndex(), |
| 4720 | instruction->GetDexPc(), |
| 4721 | calling_convention); |
| 4722 | } |
| 4723 | |
| 4724 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4725 | HUnresolvedStaticFieldSet* instruction) { |
| 4726 | FieldAccessCallingConventionARM calling_convention; |
| 4727 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4728 | instruction, instruction->GetFieldType(), calling_convention); |
| 4729 | } |
| 4730 | |
| 4731 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4732 | HUnresolvedStaticFieldSet* instruction) { |
| 4733 | FieldAccessCallingConventionARM calling_convention; |
| 4734 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4735 | instruction->GetFieldType(), |
| 4736 | instruction->GetFieldIndex(), |
| 4737 | instruction->GetDexPc(), |
| 4738 | calling_convention); |
| 4739 | } |
| 4740 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4741 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4742 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4743 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4744 | } |
| 4745 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4746 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4747 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4748 | return; |
| 4749 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4750 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4751 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4752 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4753 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4756 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4757 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4758 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4759 | |
| 4760 | LocationSummary* locations = instruction->GetLocations(); |
| 4761 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4762 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4763 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4764 | } |
| 4765 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4766 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4767 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4768 | } |
| 4769 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4770 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4771 | switch (type) { |
| 4772 | case Primitive::kPrimNot: |
| 4773 | return kLoadWord; |
| 4774 | case Primitive::kPrimBoolean: |
| 4775 | return kLoadUnsignedByte; |
| 4776 | case Primitive::kPrimByte: |
| 4777 | return kLoadSignedByte; |
| 4778 | case Primitive::kPrimChar: |
| 4779 | return kLoadUnsignedHalfword; |
| 4780 | case Primitive::kPrimShort: |
| 4781 | return kLoadSignedHalfword; |
| 4782 | case Primitive::kPrimInt: |
| 4783 | return kLoadWord; |
| 4784 | case Primitive::kPrimLong: |
| 4785 | return kLoadWordPair; |
| 4786 | case Primitive::kPrimFloat: |
| 4787 | return kLoadSWord; |
| 4788 | case Primitive::kPrimDouble: |
| 4789 | return kLoadDWord; |
| 4790 | default: |
| 4791 | LOG(FATAL) << "Unreachable type " << type; |
| 4792 | UNREACHABLE(); |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4797 | switch (type) { |
| 4798 | case Primitive::kPrimNot: |
| 4799 | return kStoreWord; |
| 4800 | case Primitive::kPrimBoolean: |
| 4801 | case Primitive::kPrimByte: |
| 4802 | return kStoreByte; |
| 4803 | case Primitive::kPrimChar: |
| 4804 | case Primitive::kPrimShort: |
| 4805 | return kStoreHalfword; |
| 4806 | case Primitive::kPrimInt: |
| 4807 | return kStoreWord; |
| 4808 | case Primitive::kPrimLong: |
| 4809 | return kStoreWordPair; |
| 4810 | case Primitive::kPrimFloat: |
| 4811 | return kStoreSWord; |
| 4812 | case Primitive::kPrimDouble: |
| 4813 | return kStoreDWord; |
| 4814 | default: |
| 4815 | LOG(FATAL) << "Unreachable type " << type; |
| 4816 | UNREACHABLE(); |
| 4817 | } |
| 4818 | } |
| 4819 | |
| 4820 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4821 | Location out_loc, |
| 4822 | Register base, |
| 4823 | Register reg_offset, |
| 4824 | Condition cond) { |
| 4825 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4826 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4827 | |
| 4828 | switch (type) { |
| 4829 | case Primitive::kPrimByte: |
| 4830 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4831 | break; |
| 4832 | case Primitive::kPrimBoolean: |
| 4833 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4834 | break; |
| 4835 | case Primitive::kPrimShort: |
| 4836 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4837 | break; |
| 4838 | case Primitive::kPrimChar: |
| 4839 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4840 | break; |
| 4841 | case Primitive::kPrimNot: |
| 4842 | case Primitive::kPrimInt: |
| 4843 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4844 | break; |
| 4845 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4846 | case Primitive::kPrimLong: |
| 4847 | case Primitive::kPrimFloat: |
| 4848 | case Primitive::kPrimDouble: |
| 4849 | default: |
| 4850 | LOG(FATAL) << "Unreachable type " << type; |
| 4851 | UNREACHABLE(); |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4856 | Location loc, |
| 4857 | Register base, |
| 4858 | Register reg_offset, |
| 4859 | Condition cond) { |
| 4860 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4861 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4862 | |
| 4863 | switch (type) { |
| 4864 | case Primitive::kPrimByte: |
| 4865 | case Primitive::kPrimBoolean: |
| 4866 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4867 | break; |
| 4868 | case Primitive::kPrimShort: |
| 4869 | case Primitive::kPrimChar: |
| 4870 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4871 | break; |
| 4872 | case Primitive::kPrimNot: |
| 4873 | case Primitive::kPrimInt: |
| 4874 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4875 | break; |
| 4876 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4877 | case Primitive::kPrimLong: |
| 4878 | case Primitive::kPrimFloat: |
| 4879 | case Primitive::kPrimDouble: |
| 4880 | default: |
| 4881 | LOG(FATAL) << "Unreachable type " << type; |
| 4882 | UNREACHABLE(); |
| 4883 | } |
| 4884 | } |
| 4885 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4886 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4887 | bool object_array_get_with_read_barrier = |
| 4888 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4889 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4890 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4891 | object_array_get_with_read_barrier ? |
| 4892 | LocationSummary::kCallOnSlowPath : |
| 4893 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4894 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4895 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4896 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4898 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4899 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4900 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4901 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4902 | // The output overlaps in the case of an object array get with |
| 4903 | // read barriers enabled: we do not want the move to overwrite the |
| 4904 | // array's location, as we need it to emit the read barrier. |
| 4905 | locations->SetOut( |
| 4906 | Location::RequiresRegister(), |
| 4907 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4908 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4909 | // We need a temporary register for the read barrier marking slow |
| 4910 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4911 | // Also need for String compression feature. |
| 4912 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4913 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4914 | locations->AddTemp(Location::RequiresRegister()); |
| 4915 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4919 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4920 | Location obj_loc = locations->InAt(0); |
| 4921 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4922 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4923 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4924 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4925 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4926 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4927 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4928 | HInstruction* array_instr = instruction->GetArray(); |
| 4929 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4930 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4931 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4932 | case Primitive::kPrimBoolean: |
| 4933 | case Primitive::kPrimByte: |
| 4934 | case Primitive::kPrimShort: |
| 4935 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4936 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4937 | Register length; |
| 4938 | if (maybe_compressed_char_at) { |
| 4939 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 4940 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4941 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4942 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4943 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4944 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4945 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4946 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4947 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4948 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4949 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4950 | "Expecting 0=compressed, 1=uncompressed"); |
| 4951 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4952 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4953 | out_loc.AsRegister<Register>(), |
| 4954 | obj, |
| 4955 | data_offset + const_index); |
| 4956 | __ b(&done); |
| 4957 | __ Bind(&uncompressed_load); |
| 4958 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4959 | out_loc.AsRegister<Register>(), |
| 4960 | obj, |
| 4961 | data_offset + (const_index << 1)); |
| 4962 | __ Bind(&done); |
| 4963 | } else { |
| 4964 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4965 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4966 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4967 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4968 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4969 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4970 | Register temp = IP; |
| 4971 | |
| 4972 | if (has_intermediate_address) { |
| 4973 | // We do not need to compute the intermediate address from the array: the |
| 4974 | // input instruction has done it already. See the comment in |
| 4975 | // `TryExtractArrayAccessAddress()`. |
| 4976 | if (kIsDebugBuild) { |
| 4977 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4978 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4979 | } |
| 4980 | temp = obj; |
| 4981 | } else { |
| 4982 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4983 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4984 | if (maybe_compressed_char_at) { |
| 4985 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4986 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4987 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4988 | "Expecting 0=compressed, 1=uncompressed"); |
| 4989 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4990 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4991 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4992 | __ b(&done); |
| 4993 | __ Bind(&uncompressed_load); |
| 4994 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4995 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4996 | __ Bind(&done); |
| 4997 | } else { |
| 4998 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4999 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5000 | } |
| 5001 | break; |
| 5002 | } |
| 5003 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5004 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5005 | // The read barrier instrumentation of object ArrayGet |
| 5006 | // instructions does not support the HIntermediateAddress |
| 5007 | // instruction. |
| 5008 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5009 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5010 | static_assert( |
| 5011 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5012 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5013 | // /* HeapReference<Object> */ out = |
| 5014 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5015 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5016 | Location temp = locations->GetTemp(0); |
| 5017 | // Note that a potential implicit null check is handled in this |
| 5018 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 5019 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5020 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5021 | } else { |
| 5022 | Register out = out_loc.AsRegister<Register>(); |
| 5023 | if (index.IsConstant()) { |
| 5024 | size_t offset = |
| 5025 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5026 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5028 | // If read barriers are enabled, emit read barriers other than |
| 5029 | // Baker's using a slow path (and also unpoison the loaded |
| 5030 | // reference, if heap poisoning is enabled). |
| 5031 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5032 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5033 | Register temp = IP; |
| 5034 | |
| 5035 | if (has_intermediate_address) { |
| 5036 | // We do not need to compute the intermediate address from the array: the |
| 5037 | // input instruction has done it already. See the comment in |
| 5038 | // `TryExtractArrayAccessAddress()`. |
| 5039 | if (kIsDebugBuild) { |
| 5040 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5041 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5042 | } |
| 5043 | temp = obj; |
| 5044 | } else { |
| 5045 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5046 | } |
| 5047 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5048 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5049 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5050 | // If read barriers are enabled, emit read barriers other than |
| 5051 | // Baker's using a slow path (and also unpoison the loaded |
| 5052 | // reference, if heap poisoning is enabled). |
| 5053 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5054 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5055 | } |
| 5056 | } |
| 5057 | break; |
| 5058 | } |
| 5059 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5061 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5062 | size_t offset = |
| 5063 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5064 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5065 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5066 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5067 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | } |
| 5069 | break; |
| 5070 | } |
| 5071 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5072 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5073 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5074 | if (index.IsConstant()) { |
| 5075 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5076 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5077 | } else { |
| 5078 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5079 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5080 | } |
| 5081 | break; |
| 5082 | } |
| 5083 | |
| 5084 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5085 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5086 | if (index.IsConstant()) { |
| 5087 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5088 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5089 | } else { |
| 5090 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5091 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5092 | } |
| 5093 | break; |
| 5094 | } |
| 5095 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5096 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5097 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5098 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5099 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5100 | |
| 5101 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5102 | // Potential implicit null checks, in the case of reference |
| 5103 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5104 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5105 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5106 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5110 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5111 | |
| 5112 | bool needs_write_barrier = |
| 5113 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5114 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5115 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5116 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5117 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5118 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5119 | LocationSummary::kCallOnSlowPath : |
| 5120 | LocationSummary::kNoCall); |
| 5121 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5123 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5124 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5125 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5126 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5127 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5128 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5129 | if (needs_write_barrier) { |
| 5130 | // Temporary registers for the write barrier. |
| 5131 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5132 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5137 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5138 | Location array_loc = locations->InAt(0); |
| 5139 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5140 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5141 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5142 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5143 | bool needs_write_barrier = |
| 5144 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5145 | uint32_t data_offset = |
| 5146 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5147 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5148 | HInstruction* array_instr = instruction->GetArray(); |
| 5149 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5150 | |
| 5151 | switch (value_type) { |
| 5152 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5153 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5154 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5155 | case Primitive::kPrimChar: |
| 5156 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5158 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5159 | uint32_t full_offset = |
| 5160 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5161 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5162 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5164 | Register temp = IP; |
| 5165 | |
| 5166 | if (has_intermediate_address) { |
| 5167 | // We do not need to compute the intermediate address from the array: the |
| 5168 | // input instruction has done it already. See the comment in |
| 5169 | // `TryExtractArrayAccessAddress()`. |
| 5170 | if (kIsDebugBuild) { |
| 5171 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5172 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5173 | } |
| 5174 | temp = array; |
| 5175 | } else { |
| 5176 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5177 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5178 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5179 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5180 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5181 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5182 | } |
| 5183 | break; |
| 5184 | } |
| 5185 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5186 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5187 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5188 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5189 | // See the comment in instruction_simplifier_shared.cc. |
| 5190 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5191 | |
| 5192 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5193 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5194 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5195 | size_t offset = |
| 5196 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5197 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5198 | } else { |
| 5199 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5200 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5201 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5202 | value_loc, |
| 5203 | IP, |
| 5204 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5205 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5206 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5207 | DCHECK(!needs_write_barrier); |
| 5208 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5209 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5210 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5211 | |
| 5212 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5213 | Location temp1_loc = locations->GetTemp(0); |
| 5214 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5215 | Location temp2_loc = locations->GetTemp(1); |
| 5216 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5217 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5218 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5219 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5220 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5221 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5222 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5223 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5224 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5225 | codegen_->AddSlowPath(slow_path); |
| 5226 | if (instruction->GetValueCanBeNull()) { |
| 5227 | Label non_zero; |
| 5228 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5229 | if (index.IsConstant()) { |
| 5230 | size_t offset = |
| 5231 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5232 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5233 | } else { |
| 5234 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5235 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5236 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5237 | value_loc, |
| 5238 | IP, |
| 5239 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5240 | } |
| 5241 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5242 | __ b(&done); |
| 5243 | __ Bind(&non_zero); |
| 5244 | } |
| 5245 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5246 | // Note that when read barriers are enabled, the type checks |
| 5247 | // are performed without read barriers. This is fine, even in |
| 5248 | // the case where a class object is in the from-space after |
| 5249 | // the flip, as a comparison involving such a type would not |
| 5250 | // produce a false positive; it may of course produce a false |
| 5251 | // negative, in which case we would take the ArraySet slow |
| 5252 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5253 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5254 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5255 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5256 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5257 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5258 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5259 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5260 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5261 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5262 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5263 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5264 | // nor `temp2`, as we are comparing two poisoned references. |
| 5265 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5266 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5267 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5268 | Label do_put; |
| 5269 | __ b(&do_put, EQ); |
| 5270 | // If heap poisoning is enabled, the `temp1` reference has |
| 5271 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5272 | __ MaybeUnpoisonHeapReference(temp1); |
| 5273 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5274 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5275 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5276 | // If heap poisoning is enabled, no need to unpoison |
| 5277 | // `temp1`, as we are comparing against null below. |
| 5278 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5279 | __ Bind(&do_put); |
| 5280 | } else { |
| 5281 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5282 | } |
| 5283 | } |
| 5284 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5285 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5286 | if (kPoisonHeapReferences) { |
| 5287 | // Note that in the case where `value` is a null reference, |
| 5288 | // we do not enter this block, as a null reference does not |
| 5289 | // need poisoning. |
| 5290 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5291 | __ Mov(temp1, value); |
| 5292 | __ PoisonHeapReference(temp1); |
| 5293 | source = temp1; |
| 5294 | } |
| 5295 | |
| 5296 | if (index.IsConstant()) { |
| 5297 | size_t offset = |
| 5298 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5299 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5300 | } else { |
| 5301 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5302 | |
| 5303 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5304 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5305 | Location::RegisterLocation(source), |
| 5306 | IP, |
| 5307 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5310 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5311 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5312 | } |
| 5313 | |
| 5314 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5315 | |
| 5316 | if (done.IsLinked()) { |
| 5317 | __ Bind(&done); |
| 5318 | } |
| 5319 | |
| 5320 | if (slow_path != nullptr) { |
| 5321 | __ Bind(slow_path->GetExitLabel()); |
| 5322 | } |
| 5323 | |
| 5324 | break; |
| 5325 | } |
| 5326 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5327 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5328 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5329 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5330 | size_t offset = |
| 5331 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5332 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5333 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5334 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5335 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5336 | } |
| 5337 | break; |
| 5338 | } |
| 5339 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5340 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5341 | Location value = locations->InAt(2); |
| 5342 | DCHECK(value.IsFpuRegister()); |
| 5343 | if (index.IsConstant()) { |
| 5344 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5345 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5346 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5347 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5348 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5349 | } |
| 5350 | break; |
| 5351 | } |
| 5352 | |
| 5353 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5354 | Location value = locations->InAt(2); |
| 5355 | DCHECK(value.IsFpuRegisterPair()); |
| 5356 | if (index.IsConstant()) { |
| 5357 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5358 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5359 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5360 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5361 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5362 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5363 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5364 | break; |
| 5365 | } |
| 5366 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5368 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5369 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5370 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5371 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5372 | // Objects are handled in the switch. |
| 5373 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5374 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5375 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5379 | LocationSummary* locations = |
| 5380 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5381 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5386 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5387 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5388 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5389 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5390 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5391 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5392 | // Mask out compression flag from String's array length. |
| 5393 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5394 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5395 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5396 | } |
| 5397 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5398 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5399 | LocationSummary* locations = |
| 5400 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5401 | |
| 5402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5403 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5404 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5405 | } |
| 5406 | |
| 5407 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5408 | LocationSummary* locations = instruction->GetLocations(); |
| 5409 | Location out = locations->Out(); |
| 5410 | Location first = locations->InAt(0); |
| 5411 | Location second = locations->InAt(1); |
| 5412 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5413 | if (second.IsRegister()) { |
| 5414 | __ add(out.AsRegister<Register>(), |
| 5415 | first.AsRegister<Register>(), |
| 5416 | ShifterOperand(second.AsRegister<Register>())); |
| 5417 | } else { |
| 5418 | __ AddConstant(out.AsRegister<Register>(), |
| 5419 | first.AsRegister<Register>(), |
| 5420 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5421 | } |
| 5422 | } |
| 5423 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5425 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5426 | InvokeRuntimeCallingConvention calling_convention; |
| 5427 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5428 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5429 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5431 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5435 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5436 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5437 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5438 | codegen_->AddSlowPath(slow_path); |
| 5439 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5440 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5441 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5442 | |
| 5443 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5444 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5445 | } |
| 5446 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5447 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5448 | Register card, |
| 5449 | Register object, |
| 5450 | Register value, |
| 5451 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5452 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5453 | if (can_be_null) { |
| 5454 | __ CompareAndBranchIfZero(value, &is_null); |
| 5455 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5456 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5457 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5458 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5459 | if (can_be_null) { |
| 5460 | __ Bind(&is_null); |
| 5461 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5462 | } |
| 5463 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5464 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5465 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5469 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5470 | } |
| 5471 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5472 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5473 | LocationSummary* locations = |
| 5474 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5475 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5479 | HBasicBlock* block = instruction->GetBlock(); |
| 5480 | if (block->GetLoopInformation() != nullptr) { |
| 5481 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5482 | // The back edge will generate the suspend check. |
| 5483 | return; |
| 5484 | } |
| 5485 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5486 | // The goto will generate the suspend check. |
| 5487 | return; |
| 5488 | } |
| 5489 | GenerateSuspendCheck(instruction, nullptr); |
| 5490 | } |
| 5491 | |
| 5492 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5493 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5494 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5495 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5496 | if (slow_path == nullptr) { |
| 5497 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5498 | instruction->SetSlowPath(slow_path); |
| 5499 | codegen_->AddSlowPath(slow_path); |
| 5500 | if (successor != nullptr) { |
| 5501 | DCHECK(successor->IsLoopHeader()); |
| 5502 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5503 | } |
| 5504 | } else { |
| 5505 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5506 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5507 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5508 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5509 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5510 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5511 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5512 | __ Bind(slow_path->GetReturnLabel()); |
| 5513 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5514 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5515 | __ b(slow_path->GetEntryLabel()); |
| 5516 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5519 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5520 | return codegen_->GetAssembler(); |
| 5521 | } |
| 5522 | |
| 5523 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5524 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5525 | Location source = move->GetSource(); |
| 5526 | Location destination = move->GetDestination(); |
| 5527 | |
| 5528 | if (source.IsRegister()) { |
| 5529 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5530 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5531 | } else if (destination.IsFpuRegister()) { |
| 5532 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5533 | } else { |
| 5534 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5535 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5536 | SP, destination.GetStackIndex()); |
| 5537 | } |
| 5538 | } else if (source.IsStackSlot()) { |
| 5539 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5540 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5541 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5542 | } else if (destination.IsFpuRegister()) { |
| 5543 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5544 | } else { |
| 5545 | DCHECK(destination.IsStackSlot()); |
| 5546 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5547 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5548 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5549 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5550 | if (destination.IsRegister()) { |
| 5551 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5552 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5553 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5554 | } else { |
| 5555 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5556 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5557 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5558 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5559 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5560 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5561 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5562 | } else if (destination.IsRegisterPair()) { |
| 5563 | DCHECK(ExpectedPairLayout(destination)); |
| 5564 | __ LoadFromOffset( |
| 5565 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5566 | } else { |
| 5567 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5568 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5569 | SP, |
| 5570 | source.GetStackIndex()); |
| 5571 | } |
| 5572 | } else if (source.IsRegisterPair()) { |
| 5573 | if (destination.IsRegisterPair()) { |
| 5574 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5575 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5576 | } else if (destination.IsFpuRegisterPair()) { |
| 5577 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5578 | source.AsRegisterPairLow<Register>(), |
| 5579 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5580 | } else { |
| 5581 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5582 | DCHECK(ExpectedPairLayout(source)); |
| 5583 | __ StoreToOffset( |
| 5584 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5585 | } |
| 5586 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5587 | if (destination.IsRegisterPair()) { |
| 5588 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5589 | destination.AsRegisterPairHigh<Register>(), |
| 5590 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5591 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5592 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5593 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5594 | } else { |
| 5595 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5596 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5597 | SP, |
| 5598 | destination.GetStackIndex()); |
| 5599 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5600 | } else { |
| 5601 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5602 | HConstant* constant = source.GetConstant(); |
| 5603 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5604 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5605 | if (destination.IsRegister()) { |
| 5606 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5607 | } else { |
| 5608 | DCHECK(destination.IsStackSlot()); |
| 5609 | __ LoadImmediate(IP, value); |
| 5610 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5611 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5612 | } else if (constant->IsLongConstant()) { |
| 5613 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5614 | if (destination.IsRegisterPair()) { |
| 5615 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5616 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5617 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5618 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5619 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5620 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5621 | __ LoadImmediate(IP, High32Bits(value)); |
| 5622 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5623 | } |
| 5624 | } else if (constant->IsDoubleConstant()) { |
| 5625 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5626 | if (destination.IsFpuRegisterPair()) { |
| 5627 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5628 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5629 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5630 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5631 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5632 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5633 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5634 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5635 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5636 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5637 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5638 | float value = constant->AsFloatConstant()->GetValue(); |
| 5639 | if (destination.IsFpuRegister()) { |
| 5640 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5641 | } else { |
| 5642 | DCHECK(destination.IsStackSlot()); |
| 5643 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5644 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5645 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5646 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5651 | __ Mov(IP, reg); |
| 5652 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5653 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5654 | } |
| 5655 | |
| 5656 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5657 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5658 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5659 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5660 | SP, mem1 + stack_offset); |
| 5661 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5662 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5663 | SP, mem2 + stack_offset); |
| 5664 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5665 | } |
| 5666 | |
| 5667 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5668 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5669 | Location source = move->GetSource(); |
| 5670 | Location destination = move->GetDestination(); |
| 5671 | |
| 5672 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5673 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5674 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5675 | __ Mov(IP, source.AsRegister<Register>()); |
| 5676 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5677 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5678 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5679 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5680 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5681 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5682 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5683 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5684 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5685 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5686 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5687 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5688 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5689 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5690 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5691 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5692 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5693 | destination.AsRegisterPairHigh<Register>(), |
| 5694 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5695 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5696 | Register low_reg = source.IsRegisterPair() |
| 5697 | ? source.AsRegisterPairLow<Register>() |
| 5698 | : destination.AsRegisterPairLow<Register>(); |
| 5699 | int mem = source.IsRegisterPair() |
| 5700 | ? destination.GetStackIndex() |
| 5701 | : source.GetStackIndex(); |
| 5702 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5703 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5704 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5705 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5706 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5707 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5708 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5709 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5710 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5711 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5712 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5713 | DRegister reg = source.IsFpuRegisterPair() |
| 5714 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5715 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5716 | int mem = source.IsFpuRegisterPair() |
| 5717 | ? destination.GetStackIndex() |
| 5718 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5719 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5720 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5721 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5722 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5723 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5724 | : destination.AsFpuRegister<SRegister>(); |
| 5725 | int mem = source.IsFpuRegister() |
| 5726 | ? destination.GetStackIndex() |
| 5727 | : source.GetStackIndex(); |
| 5728 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5729 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5730 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5731 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5732 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5733 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5734 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5735 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5736 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5741 | __ Push(static_cast<Register>(reg)); |
| 5742 | } |
| 5743 | |
| 5744 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5745 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5746 | } |
| 5747 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5748 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5749 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5750 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5751 | case HLoadClass::LoadKind::kInvalid: |
| 5752 | LOG(FATAL) << "UNREACHABLE"; |
| 5753 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5754 | case HLoadClass::LoadKind::kReferrersClass: |
| 5755 | break; |
| 5756 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5757 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5758 | break; |
| 5759 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5760 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5761 | break; |
| 5762 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5763 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5764 | case HLoadClass::LoadKind::kBssEntry: |
| 5765 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5766 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5767 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5768 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5769 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5770 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5771 | break; |
| 5772 | } |
| 5773 | return desired_class_load_kind; |
| 5774 | } |
| 5775 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5776 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5777 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5778 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5779 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5780 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5781 | cls, |
| 5782 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5783 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5784 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5785 | return; |
| 5786 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5787 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5788 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5789 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5790 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5791 | ? LocationSummary::kCallOnSlowPath |
| 5792 | : LocationSummary::kNoCall; |
| 5793 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5794 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5795 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5796 | } |
| 5797 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5798 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5799 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5800 | } |
| 5801 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5802 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5803 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5804 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 5805 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 5806 | // to the custom calling convention) or by marking, so we request a different temp. |
| 5807 | locations->AddTemp(Location::RequiresRegister()); |
| 5808 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5809 | InvokeRuntimeCallingConvention calling_convention; |
| 5810 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5811 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5812 | // that the the kPrimNot result register is the same as the first argument register. |
| 5813 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5814 | } else { |
| 5815 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5816 | } |
| 5817 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5818 | } |
| 5819 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5820 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5821 | // move. |
| 5822 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5823 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5824 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5825 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5826 | return; |
| 5827 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5828 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5829 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5830 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5831 | Location out_loc = locations->Out(); |
| 5832 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5833 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5834 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5835 | ? kWithoutReadBarrier |
| 5836 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5837 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5838 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5839 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5840 | DCHECK(!cls->CanCallRuntime()); |
| 5841 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5842 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5843 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5844 | GenerateGcRootFieldLoad(cls, |
| 5845 | out_loc, |
| 5846 | current_method, |
| 5847 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5848 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5849 | break; |
| 5850 | } |
| 5851 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5852 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5853 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5854 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5855 | cls->GetTypeIndex())); |
| 5856 | break; |
| 5857 | } |
| 5858 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5859 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5860 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5861 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5862 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5863 | __ BindTrackedLabel(&labels->movw_label); |
| 5864 | __ movw(out, /* placeholder */ 0u); |
| 5865 | __ BindTrackedLabel(&labels->movt_label); |
| 5866 | __ movt(out, /* placeholder */ 0u); |
| 5867 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5868 | __ add(out, out, ShifterOperand(PC)); |
| 5869 | break; |
| 5870 | } |
| 5871 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5872 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5873 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5874 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5875 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5876 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5877 | break; |
| 5878 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5879 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5880 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 5881 | ? locations->GetTemp(0).AsRegister<Register>() |
| 5882 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5883 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5884 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5885 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5886 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5887 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5888 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5889 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5890 | __ add(temp, temp, ShifterOperand(PC)); |
| 5891 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5892 | generate_null_check = true; |
| 5893 | break; |
| 5894 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5895 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5896 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5897 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5898 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5899 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5900 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5901 | break; |
| 5902 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5903 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5904 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5905 | LOG(FATAL) << "UNREACHABLE"; |
| 5906 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5907 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5908 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5909 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5910 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5911 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5912 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5913 | codegen_->AddSlowPath(slow_path); |
| 5914 | if (generate_null_check) { |
| 5915 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5916 | } |
| 5917 | if (cls->MustGenerateClinitCheck()) { |
| 5918 | GenerateClassInitializationCheck(slow_path, out); |
| 5919 | } else { |
| 5920 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5921 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5926 | LocationSummary* locations = |
| 5927 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5929 | if (check->HasUses()) { |
| 5930 | locations->SetOut(Location::SameAsFirstInput()); |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5935 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5936 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5937 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5938 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5939 | GenerateClassInitializationCheck(slow_path, |
| 5940 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5941 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5942 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5943 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5944 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5945 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5946 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5947 | __ b(slow_path->GetEntryLabel(), LT); |
| 5948 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5949 | // properly. Therefore, we do a memory fence. |
| 5950 | __ dmb(ISH); |
| 5951 | __ Bind(slow_path->GetExitLabel()); |
| 5952 | } |
| 5953 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5954 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5955 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5956 | switch (desired_string_load_kind) { |
| 5957 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5958 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5959 | break; |
| 5960 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5961 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5962 | break; |
| 5963 | case HLoadString::LoadKind::kBootImageAddress: |
| 5964 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5965 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5966 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5967 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5968 | case HLoadString::LoadKind::kJitTableAddress: |
| 5969 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5970 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5971 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5972 | break; |
| 5973 | } |
| 5974 | return desired_string_load_kind; |
| 5975 | } |
| 5976 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5977 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5978 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5979 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5980 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5981 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5982 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5983 | } else { |
| 5984 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5985 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5986 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5987 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 5988 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 5989 | // to the custom calling convention) or by marking, so we request a different temp. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5990 | locations->AddTemp(Location::RequiresRegister()); |
| 5991 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5992 | InvokeRuntimeCallingConvention calling_convention; |
| 5993 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5994 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5995 | // that the the kPrimNot result register is the same as the first argument register. |
| 5996 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5997 | } else { |
| 5998 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5999 | } |
| 6000 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6001 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6004 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6005 | // move. |
| 6006 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6007 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6008 | Location out_loc = locations->Out(); |
| 6009 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6010 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6011 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6012 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6013 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6014 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6015 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6016 | load->GetStringIndex())); |
| 6017 | return; // No dex cache slow path. |
| 6018 | } |
| 6019 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6020 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6021 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6022 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6023 | __ BindTrackedLabel(&labels->movw_label); |
| 6024 | __ movw(out, /* placeholder */ 0u); |
| 6025 | __ BindTrackedLabel(&labels->movt_label); |
| 6026 | __ movt(out, /* placeholder */ 0u); |
| 6027 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6028 | __ add(out, out, ShifterOperand(PC)); |
| 6029 | return; // No dex cache slow path. |
| 6030 | } |
| 6031 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6032 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6033 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6034 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6035 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6036 | return; // No dex cache slow path. |
| 6037 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6038 | case HLoadString::LoadKind::kBssEntry: { |
| 6039 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6040 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6041 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6042 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6043 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6044 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6045 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6046 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6047 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6048 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6049 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6050 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6051 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6052 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 6053 | codegen_->AddSlowPath(slow_path); |
| 6054 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6055 | __ Bind(slow_path->GetExitLabel()); |
| 6056 | return; |
| 6057 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6058 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6059 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6060 | load->GetStringIndex(), |
| 6061 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6062 | // /* GcRoot<mirror::String> */ out = *out |
| 6063 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6064 | return; |
| 6065 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6066 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6067 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6068 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6069 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6070 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6071 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6072 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6073 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6074 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6075 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6076 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6079 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6080 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6081 | } |
| 6082 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6083 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6084 | LocationSummary* locations = |
| 6085 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6086 | locations->SetOut(Location::RequiresRegister()); |
| 6087 | } |
| 6088 | |
| 6089 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6090 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6091 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6092 | } |
| 6093 | |
| 6094 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6095 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6096 | } |
| 6097 | |
| 6098 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6099 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6100 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6104 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6105 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6106 | InvokeRuntimeCallingConvention calling_convention; |
| 6107 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6108 | } |
| 6109 | |
| 6110 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6111 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6112 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6113 | } |
| 6114 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6115 | // Temp is used for read barrier. |
| 6116 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6117 | if (kEmitCompilerReadBarrier && |
| 6118 | (kUseBakerReadBarrier || |
| 6119 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6120 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6121 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6122 | return 1; |
| 6123 | } |
| 6124 | return 0; |
| 6125 | } |
| 6126 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6127 | // 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] | 6128 | // interface pointer, one for loading the current interface. |
| 6129 | // The other checks have one temp for loading the object's class. |
| 6130 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6131 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6132 | return 3; |
| 6133 | } |
| 6134 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6135 | } |
| 6136 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6137 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6138 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6139 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6140 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6141 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6142 | case TypeCheckKind::kExactCheck: |
| 6143 | case TypeCheckKind::kAbstractClassCheck: |
| 6144 | case TypeCheckKind::kClassHierarchyCheck: |
| 6145 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6146 | call_kind = |
| 6147 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6148 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6149 | break; |
| 6150 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6151 | case TypeCheckKind::kUnresolvedCheck: |
| 6152 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6153 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6154 | break; |
| 6155 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6156 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6157 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6158 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6159 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6160 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6161 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6162 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6163 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6164 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6165 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6166 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6167 | } |
| 6168 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6169 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6170 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6171 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6172 | Location obj_loc = locations->InAt(0); |
| 6173 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6174 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6175 | Location out_loc = locations->Out(); |
| 6176 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6177 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6178 | DCHECK_LE(num_temps, 1u); |
| 6179 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6180 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6182 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6183 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6184 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6185 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6186 | |
| 6187 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6188 | // avoid null check if we know obj is not null. |
| 6189 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6190 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6191 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6192 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6193 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6194 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6195 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6196 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6197 | out_loc, |
| 6198 | obj_loc, |
| 6199 | class_offset, |
| 6200 | maybe_temp_loc, |
| 6201 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6202 | __ cmp(out, ShifterOperand(cls)); |
| 6203 | // Classes must be equal for the instanceof to succeed. |
| 6204 | __ b(&zero, NE); |
| 6205 | __ LoadImmediate(out, 1); |
| 6206 | __ b(&done); |
| 6207 | break; |
| 6208 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6209 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6211 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6212 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6213 | out_loc, |
| 6214 | obj_loc, |
| 6215 | class_offset, |
| 6216 | maybe_temp_loc, |
| 6217 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6218 | // If the class is abstract, we eagerly fetch the super class of the |
| 6219 | // object to avoid doing a comparison we know will fail. |
| 6220 | Label loop; |
| 6221 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6222 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6223 | GenerateReferenceLoadOneRegister(instruction, |
| 6224 | out_loc, |
| 6225 | super_offset, |
| 6226 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6227 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6228 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6229 | __ CompareAndBranchIfZero(out, &done); |
| 6230 | __ cmp(out, ShifterOperand(cls)); |
| 6231 | __ b(&loop, NE); |
| 6232 | __ LoadImmediate(out, 1); |
| 6233 | if (zero.IsLinked()) { |
| 6234 | __ b(&done); |
| 6235 | } |
| 6236 | break; |
| 6237 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6238 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6240 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6241 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6242 | out_loc, |
| 6243 | obj_loc, |
| 6244 | class_offset, |
| 6245 | maybe_temp_loc, |
| 6246 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6247 | // Walk over the class hierarchy to find a match. |
| 6248 | Label loop, success; |
| 6249 | __ Bind(&loop); |
| 6250 | __ cmp(out, ShifterOperand(cls)); |
| 6251 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6252 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6253 | GenerateReferenceLoadOneRegister(instruction, |
| 6254 | out_loc, |
| 6255 | super_offset, |
| 6256 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6257 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6258 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6259 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6260 | __ b(&done); |
| 6261 | __ Bind(&success); |
| 6262 | __ LoadImmediate(out, 1); |
| 6263 | if (zero.IsLinked()) { |
| 6264 | __ b(&done); |
| 6265 | } |
| 6266 | break; |
| 6267 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6268 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6269 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6270 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6271 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6272 | out_loc, |
| 6273 | obj_loc, |
| 6274 | class_offset, |
| 6275 | maybe_temp_loc, |
| 6276 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6277 | // Do an exact check. |
| 6278 | Label exact_check; |
| 6279 | __ cmp(out, ShifterOperand(cls)); |
| 6280 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6281 | // 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] | 6282 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6283 | GenerateReferenceLoadOneRegister(instruction, |
| 6284 | out_loc, |
| 6285 | component_offset, |
| 6286 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6287 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6289 | __ CompareAndBranchIfZero(out, &done); |
| 6290 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6291 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6292 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6293 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6294 | __ LoadImmediate(out, 1); |
| 6295 | __ b(&done); |
| 6296 | break; |
| 6297 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6298 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6299 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6300 | // No read barrier since the slow path will retry upon failure. |
| 6301 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6302 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6303 | out_loc, |
| 6304 | obj_loc, |
| 6305 | class_offset, |
| 6306 | maybe_temp_loc, |
| 6307 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6308 | __ cmp(out, ShifterOperand(cls)); |
| 6309 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6310 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6311 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | codegen_->AddSlowPath(slow_path); |
| 6313 | __ b(slow_path->GetEntryLabel(), NE); |
| 6314 | __ LoadImmediate(out, 1); |
| 6315 | if (zero.IsLinked()) { |
| 6316 | __ b(&done); |
| 6317 | } |
| 6318 | break; |
| 6319 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6320 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6321 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6322 | case TypeCheckKind::kInterfaceCheck: { |
| 6323 | // 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] | 6324 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6325 | // cases. |
| 6326 | // |
| 6327 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6328 | // entry point without resorting to a type checking slow path |
| 6329 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6330 | // require to assign fixed registers for the inputs of this |
| 6331 | // HInstanceOf instruction (following the runtime calling |
| 6332 | // convention), which might be cluttered by the potential first |
| 6333 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6334 | // |
| 6335 | // TODO: Introduce a new runtime entry point taking the object |
| 6336 | // to test (instead of its class) as argument, and let it deal |
| 6337 | // with the read barrier issues. This will let us refactor this |
| 6338 | // case of the `switch` code as it was previously (with a direct |
| 6339 | // call to the runtime not using a type checking slow path). |
| 6340 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6341 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6342 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6343 | /* is_fatal */ false); |
| 6344 | codegen_->AddSlowPath(slow_path); |
| 6345 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6346 | if (zero.IsLinked()) { |
| 6347 | __ b(&done); |
| 6348 | } |
| 6349 | break; |
| 6350 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6351 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6352 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6353 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6354 | __ Bind(&zero); |
| 6355 | __ LoadImmediate(out, 0); |
| 6356 | } |
| 6357 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6358 | if (done.IsLinked()) { |
| 6359 | __ Bind(&done); |
| 6360 | } |
| 6361 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6362 | if (slow_path != nullptr) { |
| 6363 | __ Bind(slow_path->GetExitLabel()); |
| 6364 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6367 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6368 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6369 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6370 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6371 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6372 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6373 | case TypeCheckKind::kExactCheck: |
| 6374 | case TypeCheckKind::kAbstractClassCheck: |
| 6375 | case TypeCheckKind::kClassHierarchyCheck: |
| 6376 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6377 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6378 | LocationSummary::kCallOnSlowPath : |
| 6379 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6380 | break; |
| 6381 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6382 | case TypeCheckKind::kUnresolvedCheck: |
| 6383 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6384 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6385 | break; |
| 6386 | } |
| 6387 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6388 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6390 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6391 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6395 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6396 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6397 | Location obj_loc = locations->InAt(0); |
| 6398 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6399 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6400 | Location temp_loc = locations->GetTemp(0); |
| 6401 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6402 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6403 | DCHECK_LE(num_temps, 3u); |
| 6404 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6405 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6406 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6407 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6408 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6409 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6410 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6411 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6412 | const uint32_t object_array_data_offset = |
| 6413 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6414 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6415 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6416 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6417 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6418 | bool is_type_check_slow_path_fatal = false; |
| 6419 | if (!kEmitCompilerReadBarrier) { |
| 6420 | is_type_check_slow_path_fatal = |
| 6421 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6422 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6423 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6424 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6425 | !instruction->CanThrowIntoCatchBlock(); |
| 6426 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6427 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6428 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6429 | is_type_check_slow_path_fatal); |
| 6430 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | |
| 6432 | Label done; |
| 6433 | // Avoid null check if we know obj is not null. |
| 6434 | if (instruction->MustDoNullCheck()) { |
| 6435 | __ CompareAndBranchIfZero(obj, &done); |
| 6436 | } |
| 6437 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6438 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6439 | case TypeCheckKind::kExactCheck: |
| 6440 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6441 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6442 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6443 | temp_loc, |
| 6444 | obj_loc, |
| 6445 | class_offset, |
| 6446 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6447 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6448 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6449 | __ cmp(temp, ShifterOperand(cls)); |
| 6450 | // Jump to slow path for throwing the exception or doing a |
| 6451 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6452 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6453 | break; |
| 6454 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6455 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6456 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6457 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6458 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6459 | temp_loc, |
| 6460 | obj_loc, |
| 6461 | class_offset, |
| 6462 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6463 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6464 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6465 | // If the class is abstract, we eagerly fetch the super class of the |
| 6466 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6467 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6468 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6469 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6470 | GenerateReferenceLoadOneRegister(instruction, |
| 6471 | temp_loc, |
| 6472 | super_offset, |
| 6473 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6474 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6475 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6476 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6477 | // exception. |
| 6478 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6479 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6480 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6481 | __ cmp(temp, ShifterOperand(cls)); |
| 6482 | __ b(&loop, NE); |
| 6483 | break; |
| 6484 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6485 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6486 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6487 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6488 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6489 | temp_loc, |
| 6490 | obj_loc, |
| 6491 | class_offset, |
| 6492 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6493 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6494 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6495 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6496 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6497 | __ Bind(&loop); |
| 6498 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6499 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6500 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6501 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6502 | GenerateReferenceLoadOneRegister(instruction, |
| 6503 | temp_loc, |
| 6504 | super_offset, |
| 6505 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6506 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6507 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6508 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6509 | // exception. |
| 6510 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6511 | // Otherwise, jump to the beginning of the loop. |
| 6512 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6513 | break; |
| 6514 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6515 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6516 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6517 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6518 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6519 | temp_loc, |
| 6520 | obj_loc, |
| 6521 | class_offset, |
| 6522 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6523 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6524 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6525 | // Do an exact check. |
| 6526 | __ cmp(temp, ShifterOperand(cls)); |
| 6527 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6528 | |
| 6529 | // 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] | 6530 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6531 | GenerateReferenceLoadOneRegister(instruction, |
| 6532 | temp_loc, |
| 6533 | component_offset, |
| 6534 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6535 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6536 | // If the component type is null, jump to the slow path to throw the exception. |
| 6537 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6538 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6539 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6540 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6541 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6542 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6543 | break; |
| 6544 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6545 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6546 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6547 | // 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] | 6548 | // We cannot directly call the CheckCast runtime entry point |
| 6549 | // without resorting to a type checking slow path here (i.e. by |
| 6550 | // calling InvokeRuntime directly), as it would require to |
| 6551 | // assign fixed registers for the inputs of this HInstanceOf |
| 6552 | // instruction (following the runtime calling convention), which |
| 6553 | // might be cluttered by the potential first read barrier |
| 6554 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6555 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6556 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6557 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6558 | |
| 6559 | case TypeCheckKind::kInterfaceCheck: { |
| 6560 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6561 | // positives by doing this. |
| 6562 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6563 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6564 | temp_loc, |
| 6565 | obj_loc, |
| 6566 | class_offset, |
| 6567 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6568 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6569 | |
| 6570 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6571 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6572 | temp_loc, |
| 6573 | temp_loc, |
| 6574 | iftable_offset, |
| 6575 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6576 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6577 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6578 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6579 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6580 | Label start_loop; |
| 6581 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6582 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 6583 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6584 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6585 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6586 | // Go to next interface. |
| 6587 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 6588 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 6589 | maybe_temp2_loc.AsRegister<Register>(), |
| 6590 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6591 | // Compare the classes and continue the loop if they do not match. |
| 6592 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 6593 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6594 | break; |
| 6595 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6596 | } |
| 6597 | __ Bind(&done); |
| 6598 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6599 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6600 | } |
| 6601 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6602 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6603 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6604 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6605 | InvokeRuntimeCallingConvention calling_convention; |
| 6606 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6607 | } |
| 6608 | |
| 6609 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6610 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6611 | instruction, |
| 6612 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6613 | if (instruction->IsEnter()) { |
| 6614 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6615 | } else { |
| 6616 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6617 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6618 | } |
| 6619 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6620 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6621 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6622 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6623 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6624 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6625 | LocationSummary* locations = |
| 6626 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6627 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6628 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6629 | // 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] | 6630 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6631 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6632 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6636 | HandleBitwiseOperation(instruction); |
| 6637 | } |
| 6638 | |
| 6639 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6640 | HandleBitwiseOperation(instruction); |
| 6641 | } |
| 6642 | |
| 6643 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6644 | HandleBitwiseOperation(instruction); |
| 6645 | } |
| 6646 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6647 | |
| 6648 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6649 | LocationSummary* locations = |
| 6650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6651 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6652 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6653 | |
| 6654 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6655 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6656 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6657 | } |
| 6658 | |
| 6659 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6660 | LocationSummary* locations = instruction->GetLocations(); |
| 6661 | Location first = locations->InAt(0); |
| 6662 | Location second = locations->InAt(1); |
| 6663 | Location out = locations->Out(); |
| 6664 | |
| 6665 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6666 | Register first_reg = first.AsRegister<Register>(); |
| 6667 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6668 | Register out_reg = out.AsRegister<Register>(); |
| 6669 | |
| 6670 | switch (instruction->GetOpKind()) { |
| 6671 | case HInstruction::kAnd: |
| 6672 | __ bic(out_reg, first_reg, second_reg); |
| 6673 | break; |
| 6674 | case HInstruction::kOr: |
| 6675 | __ orn(out_reg, first_reg, second_reg); |
| 6676 | break; |
| 6677 | // There is no EON on arm. |
| 6678 | case HInstruction::kXor: |
| 6679 | default: |
| 6680 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6681 | UNREACHABLE(); |
| 6682 | } |
| 6683 | return; |
| 6684 | |
| 6685 | } else { |
| 6686 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6687 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6688 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6689 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6690 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6691 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6692 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6693 | |
| 6694 | switch (instruction->GetOpKind()) { |
| 6695 | case HInstruction::kAnd: |
| 6696 | __ bic(out_low, first_low, second_low); |
| 6697 | __ bic(out_high, first_high, second_high); |
| 6698 | break; |
| 6699 | case HInstruction::kOr: |
| 6700 | __ orn(out_low, first_low, second_low); |
| 6701 | __ orn(out_high, first_high, second_high); |
| 6702 | break; |
| 6703 | // There is no EON on arm. |
| 6704 | case HInstruction::kXor: |
| 6705 | default: |
| 6706 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6707 | UNREACHABLE(); |
| 6708 | } |
| 6709 | } |
| 6710 | } |
| 6711 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6712 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6713 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6714 | if (value == 0xffffffffu) { |
| 6715 | if (out != first) { |
| 6716 | __ mov(out, ShifterOperand(first)); |
| 6717 | } |
| 6718 | return; |
| 6719 | } |
| 6720 | if (value == 0u) { |
| 6721 | __ mov(out, ShifterOperand(0)); |
| 6722 | return; |
| 6723 | } |
| 6724 | ShifterOperand so; |
| 6725 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6726 | __ and_(out, first, so); |
| 6727 | } else { |
| 6728 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6729 | __ bic(out, first, ShifterOperand(~value)); |
| 6730 | } |
| 6731 | } |
| 6732 | |
| 6733 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6734 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6735 | if (value == 0u) { |
| 6736 | if (out != first) { |
| 6737 | __ mov(out, ShifterOperand(first)); |
| 6738 | } |
| 6739 | return; |
| 6740 | } |
| 6741 | if (value == 0xffffffffu) { |
| 6742 | __ mvn(out, ShifterOperand(0)); |
| 6743 | return; |
| 6744 | } |
| 6745 | ShifterOperand so; |
| 6746 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6747 | __ orr(out, first, so); |
| 6748 | } else { |
| 6749 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6750 | __ orn(out, first, ShifterOperand(~value)); |
| 6751 | } |
| 6752 | } |
| 6753 | |
| 6754 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6755 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6756 | if (value == 0u) { |
| 6757 | if (out != first) { |
| 6758 | __ mov(out, ShifterOperand(first)); |
| 6759 | } |
| 6760 | return; |
| 6761 | } |
| 6762 | __ eor(out, first, ShifterOperand(value)); |
| 6763 | } |
| 6764 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6765 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6766 | Location first, |
| 6767 | uint64_t value) { |
| 6768 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6769 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6770 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6771 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6772 | uint32_t value_low = Low32Bits(value); |
| 6773 | uint32_t value_high = High32Bits(value); |
| 6774 | if (value_low == 0u) { |
| 6775 | if (out_low != first_low) { |
| 6776 | __ mov(out_low, ShifterOperand(first_low)); |
| 6777 | } |
| 6778 | __ AddConstant(out_high, first_high, value_high); |
| 6779 | return; |
| 6780 | } |
| 6781 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6782 | ShifterOperand so; |
| 6783 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6784 | __ adc(out_high, first_high, so); |
| 6785 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6786 | __ sbc(out_high, first_high, so); |
| 6787 | } else { |
| 6788 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6789 | UNREACHABLE(); |
| 6790 | } |
| 6791 | } |
| 6792 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6793 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6794 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6795 | Location first = locations->InAt(0); |
| 6796 | Location second = locations->InAt(1); |
| 6797 | Location out = locations->Out(); |
| 6798 | |
| 6799 | if (second.IsConstant()) { |
| 6800 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6801 | uint32_t value_low = Low32Bits(value); |
| 6802 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6803 | Register first_reg = first.AsRegister<Register>(); |
| 6804 | Register out_reg = out.AsRegister<Register>(); |
| 6805 | if (instruction->IsAnd()) { |
| 6806 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6807 | } else if (instruction->IsOr()) { |
| 6808 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6809 | } else { |
| 6810 | DCHECK(instruction->IsXor()); |
| 6811 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6812 | } |
| 6813 | } else { |
| 6814 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6815 | uint32_t value_high = High32Bits(value); |
| 6816 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6817 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6818 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6819 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6820 | if (instruction->IsAnd()) { |
| 6821 | GenerateAndConst(out_low, first_low, value_low); |
| 6822 | GenerateAndConst(out_high, first_high, value_high); |
| 6823 | } else if (instruction->IsOr()) { |
| 6824 | GenerateOrrConst(out_low, first_low, value_low); |
| 6825 | GenerateOrrConst(out_high, first_high, value_high); |
| 6826 | } else { |
| 6827 | DCHECK(instruction->IsXor()); |
| 6828 | GenerateEorConst(out_low, first_low, value_low); |
| 6829 | GenerateEorConst(out_high, first_high, value_high); |
| 6830 | } |
| 6831 | } |
| 6832 | return; |
| 6833 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6834 | |
| 6835 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6836 | Register first_reg = first.AsRegister<Register>(); |
| 6837 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6838 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6839 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6840 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6841 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6842 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6843 | } else { |
| 6844 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6845 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6846 | } |
| 6847 | } else { |
| 6848 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6849 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6850 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6851 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6852 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6853 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6854 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6855 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6856 | __ and_(out_low, first_low, second_low); |
| 6857 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6858 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6859 | __ orr(out_low, first_low, second_low); |
| 6860 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6861 | } else { |
| 6862 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6863 | __ eor(out_low, first_low, second_low); |
| 6864 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6869 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 6870 | HInstruction* instruction, |
| 6871 | Location out, |
| 6872 | uint32_t offset, |
| 6873 | Location maybe_temp, |
| 6874 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6875 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6876 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6877 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6878 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6879 | if (kUseBakerReadBarrier) { |
| 6880 | // Load with fast path based Baker's read barrier. |
| 6881 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6882 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6883 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6884 | } else { |
| 6885 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6886 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6887 | // in the following move operation, as we will need it for the |
| 6888 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6889 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6890 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6891 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6892 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6893 | } |
| 6894 | } else { |
| 6895 | // Plain load with no read barrier. |
| 6896 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6897 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6898 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6899 | } |
| 6900 | } |
| 6901 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6902 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 6903 | HInstruction* instruction, |
| 6904 | Location out, |
| 6905 | Location obj, |
| 6906 | uint32_t offset, |
| 6907 | Location maybe_temp, |
| 6908 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6909 | Register out_reg = out.AsRegister<Register>(); |
| 6910 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6911 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6912 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6913 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6914 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6915 | // Load with fast path based Baker's read barrier. |
| 6916 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6917 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6918 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6919 | } else { |
| 6920 | // Load with slow path based read barrier. |
| 6921 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6922 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6923 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6924 | } |
| 6925 | } else { |
| 6926 | // Plain load with no read barrier. |
| 6927 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6928 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6929 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6930 | } |
| 6931 | } |
| 6932 | |
| 6933 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6934 | Location root, |
| 6935 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6936 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6937 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6938 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6939 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6940 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6941 | if (kUseBakerReadBarrier) { |
| 6942 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6943 | // Baker's read barrier are used: |
| 6944 | // |
| 6945 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6946 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6947 | // if (temp != null) { |
| 6948 | // root = temp(root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6949 | // } |
| 6950 | |
| 6951 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6952 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6953 | static_assert( |
| 6954 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6955 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6956 | "have different sizes."); |
| 6957 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6958 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6959 | "have different sizes."); |
| 6960 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6961 | // Slow path marking the GC root `root`. |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6962 | Location temp = Location::RegisterLocation(LR); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6963 | SlowPathCodeARM* slow_path = |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6964 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 6965 | instruction, |
| 6966 | root, |
| 6967 | /*entrypoint*/ temp); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6968 | codegen_->AddSlowPath(slow_path); |
| 6969 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6970 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6971 | const int32_t entry_point_offset = |
| 6972 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 6973 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6974 | // threads are suspended or running a checkpoint. |
| 6975 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6976 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6977 | // checking GetIsGcMarking. |
| 6978 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6979 | __ Bind(slow_path->GetExitLabel()); |
| 6980 | } else { |
| 6981 | // GC root loaded through a slow path for read barriers other |
| 6982 | // than Baker's. |
| 6983 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6984 | __ AddConstant(root_reg, obj, offset); |
| 6985 | // /* mirror::Object* */ root = root->Read() |
| 6986 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6987 | } |
| 6988 | } else { |
| 6989 | // Plain GC root load with no read barrier. |
| 6990 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6991 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6992 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6993 | // do not have to unpoison `root_reg` here. |
| 6994 | } |
| 6995 | } |
| 6996 | |
| 6997 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6998 | Location ref, |
| 6999 | Register obj, |
| 7000 | uint32_t offset, |
| 7001 | Location temp, |
| 7002 | bool needs_null_check) { |
| 7003 | DCHECK(kEmitCompilerReadBarrier); |
| 7004 | DCHECK(kUseBakerReadBarrier); |
| 7005 | |
| 7006 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7007 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7008 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7009 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7010 | 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] | 7011 | } |
| 7012 | |
| 7013 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7014 | Location ref, |
| 7015 | Register obj, |
| 7016 | uint32_t data_offset, |
| 7017 | Location index, |
| 7018 | Location temp, |
| 7019 | bool needs_null_check) { |
| 7020 | DCHECK(kEmitCompilerReadBarrier); |
| 7021 | DCHECK(kUseBakerReadBarrier); |
| 7022 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7023 | static_assert( |
| 7024 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7025 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7026 | // /* HeapReference<Object> */ ref = |
| 7027 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7028 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7029 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7030 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7034 | Location ref, |
| 7035 | Register obj, |
| 7036 | uint32_t offset, |
| 7037 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7038 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7039 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7040 | bool needs_null_check, |
| 7041 | bool always_update_field, |
| 7042 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7043 | DCHECK(kEmitCompilerReadBarrier); |
| 7044 | DCHECK(kUseBakerReadBarrier); |
| 7045 | |
| 7046 | // In slow path based read barriers, the read barrier call is |
| 7047 | // inserted after the original load. However, in fast path based |
| 7048 | // Baker's read barriers, we need to perform the load of |
| 7049 | // mirror::Object::monitor_ *before* the original reference load. |
| 7050 | // This load-load ordering is required by the read barrier. |
| 7051 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7052 | // |
| 7053 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7054 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7055 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7056 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7057 | // if (is_gray) { |
| 7058 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7059 | // } |
| 7060 | // |
| 7061 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7062 | // slightly more complex as it performs additional checks that we do |
| 7063 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7064 | |
| 7065 | Register ref_reg = ref.AsRegister<Register>(); |
| 7066 | Register temp_reg = temp.AsRegister<Register>(); |
| 7067 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7068 | |
| 7069 | // /* int32_t */ monitor = obj->monitor_ |
| 7070 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7071 | if (needs_null_check) { |
| 7072 | MaybeRecordImplicitNullCheck(instruction); |
| 7073 | } |
| 7074 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7075 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7076 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7077 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7078 | // Introduce a dependency on the lock_word including the rb_state, |
| 7079 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7080 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 7081 | // `obj` is unchanged by this operation, but its value now depends |
| 7082 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7083 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7084 | |
| 7085 | // The actual reference load. |
| 7086 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7087 | // Load types involving an "index": ArrayGet, |
| 7088 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7089 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7090 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7091 | if (index.IsConstant()) { |
| 7092 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7093 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7094 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7095 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7096 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7097 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7098 | // intrinsics, which use a register pair as index ("long |
| 7099 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7100 | Register index_reg = index.IsRegisterPair() |
| 7101 | ? index.AsRegisterPairLow<Register>() |
| 7102 | : index.AsRegister<Register>(); |
| 7103 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7104 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7105 | } |
| 7106 | } else { |
| 7107 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7108 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7109 | } |
| 7110 | |
| 7111 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7112 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7113 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7114 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7115 | SlowPathCodeARM* slow_path; |
| 7116 | if (always_update_field) { |
| 7117 | DCHECK(temp2 != nullptr); |
| 7118 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 7119 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7120 | // `field_offset` is a register pair (of which only the lower half |
| 7121 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7122 | // to be null in this code path. |
| 7123 | DCHECK_EQ(offset, 0u); |
| 7124 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7125 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 7126 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7127 | } else { |
| 7128 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 7129 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7130 | AddSlowPath(slow_path); |
| 7131 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7132 | // if (rb_state == ReadBarrier::GrayState()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7133 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7134 | // Given the numeric representation, it's enough to check the low bit of the |
| 7135 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7136 | // which can be a 16-bit instruction unlike the TST immediate. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7137 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7138 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7139 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7140 | __ 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] | 7141 | __ Bind(slow_path->GetExitLabel()); |
| 7142 | } |
| 7143 | |
| 7144 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7145 | Location out, |
| 7146 | Location ref, |
| 7147 | Location obj, |
| 7148 | uint32_t offset, |
| 7149 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7150 | DCHECK(kEmitCompilerReadBarrier); |
| 7151 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7152 | // Insert a slow path based read barrier *after* the reference load. |
| 7153 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7154 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7155 | // reference will be carried out by the runtime within the slow |
| 7156 | // path. |
| 7157 | // |
| 7158 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7159 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7160 | // not used by the artReadBarrierSlow entry point. |
| 7161 | // |
| 7162 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7163 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7164 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7165 | AddSlowPath(slow_path); |
| 7166 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7167 | __ b(slow_path->GetEntryLabel()); |
| 7168 | __ Bind(slow_path->GetExitLabel()); |
| 7169 | } |
| 7170 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7171 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7172 | Location out, |
| 7173 | Location ref, |
| 7174 | Location obj, |
| 7175 | uint32_t offset, |
| 7176 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7177 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7178 | // Baker's read barriers shall be handled by the fast path |
| 7179 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7180 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7181 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7182 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7183 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7184 | } else if (kPoisonHeapReferences) { |
| 7185 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7186 | } |
| 7187 | } |
| 7188 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7189 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7190 | Location out, |
| 7191 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7192 | DCHECK(kEmitCompilerReadBarrier); |
| 7193 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7194 | // Insert a slow path based read barrier *after* the GC root load. |
| 7195 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7196 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7197 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7198 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7199 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7200 | AddSlowPath(slow_path); |
| 7201 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7202 | __ b(slow_path->GetEntryLabel()); |
| 7203 | __ Bind(slow_path->GetExitLabel()); |
| 7204 | } |
| 7205 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7206 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7207 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7208 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 7209 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7210 | } |
| 7211 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7212 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7213 | Register temp) { |
| 7214 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7215 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7216 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7217 | return location.AsRegister<Register>(); |
| 7218 | } |
| 7219 | // For intrinsics we allow any location, so it may be on the stack. |
| 7220 | if (!location.IsRegister()) { |
| 7221 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7222 | return temp; |
| 7223 | } |
| 7224 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7225 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7226 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7227 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7228 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7229 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7230 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7231 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7232 | return temp; |
| 7233 | } |
| 7234 | return location.AsRegister<Register>(); |
| 7235 | } |
| 7236 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7237 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 7238 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7239 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7240 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7241 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7242 | uint32_t offset = |
| 7243 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7244 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7245 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7246 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7247 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7248 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7249 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7250 | break; |
| 7251 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7252 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7253 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7254 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7255 | HArmDexCacheArraysBase* base = |
| 7256 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7257 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7258 | temp.AsRegister<Register>()); |
| 7259 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7260 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7261 | break; |
| 7262 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7263 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7264 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7265 | Register method_reg; |
| 7266 | Register reg = temp.AsRegister<Register>(); |
| 7267 | if (current_method.IsRegister()) { |
| 7268 | method_reg = current_method.AsRegister<Register>(); |
| 7269 | } else { |
| 7270 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7271 | DCHECK(!current_method.IsValid()); |
| 7272 | method_reg = reg; |
| 7273 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7274 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7275 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7276 | __ LoadFromOffset(kLoadWord, |
| 7277 | reg, |
| 7278 | method_reg, |
| 7279 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7280 | // temp = temp[index_in_cache]; |
| 7281 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7282 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7283 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7284 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7285 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7286 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7287 | return callee_method; |
| 7288 | } |
| 7289 | |
| 7290 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 7291 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7292 | |
| 7293 | switch (invoke->GetCodePtrLocation()) { |
| 7294 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7295 | __ bl(GetFrameEntryLabel()); |
| 7296 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7297 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7298 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7299 | __ LoadFromOffset( |
| 7300 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7301 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7302 | // LR() |
| 7303 | __ blx(LR); |
| 7304 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7305 | } |
| 7306 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7307 | DCHECK(!IsLeafMethod()); |
| 7308 | } |
| 7309 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7310 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7311 | Register temp = temp_location.AsRegister<Register>(); |
| 7312 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7313 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7314 | |
| 7315 | // Use the calling convention instead of the location of the receiver, as |
| 7316 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7317 | // slow path, the arguments have been moved to the right place, so here we are |
| 7318 | // guaranteed that the receiver is the first register of the calling convention. |
| 7319 | InvokeDexCallingConvention calling_convention; |
| 7320 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7321 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7322 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7323 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7324 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7325 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7326 | // emit a read barrier for the previous class reference load. |
| 7327 | // However this is not required in practice, as this is an |
| 7328 | // intermediate/temporary reference and because the current |
| 7329 | // concurrent copying collector keeps the from-space memory |
| 7330 | // intact/accessible until the end of the marking phase (the |
| 7331 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7332 | __ MaybeUnpoisonHeapReference(temp); |
| 7333 | // temp = temp->GetMethodAt(method_offset); |
| 7334 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7335 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7336 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7337 | // LR = temp->GetEntryPoint(); |
| 7338 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7339 | // LR(); |
| 7340 | __ blx(LR); |
| 7341 | } |
| 7342 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7343 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7344 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7345 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7348 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7349 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7350 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7351 | } |
| 7352 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7353 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 7354 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7355 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7356 | } |
| 7357 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7358 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7359 | const DexFile& dex_file, uint32_t element_offset) { |
| 7360 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7361 | } |
| 7362 | |
| 7363 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7364 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7365 | patches->emplace_back(dex_file, offset_or_index); |
| 7366 | return &patches->back(); |
| 7367 | } |
| 7368 | |
| 7369 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7370 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7371 | return boot_image_string_patches_.GetOrCreate( |
| 7372 | StringReference(&dex_file, string_index), |
| 7373 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7374 | } |
| 7375 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7376 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7377 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7378 | return boot_image_type_patches_.GetOrCreate( |
| 7379 | TypeReference(&dex_file, type_index), |
| 7380 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7381 | } |
| 7382 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7383 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7384 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7385 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7386 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7387 | } |
| 7388 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7389 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7390 | dex::StringIndex string_index, |
| 7391 | Handle<mirror::String> handle) { |
| 7392 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7393 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7394 | return jit_string_patches_.GetOrCreate( |
| 7395 | StringReference(&dex_file, string_index), |
| 7396 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7397 | } |
| 7398 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7399 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7400 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7401 | Handle<mirror::Class> handle) { |
| 7402 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 7403 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7404 | return jit_class_patches_.GetOrCreate( |
| 7405 | TypeReference(&dex_file, type_index), |
| 7406 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7407 | } |
| 7408 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7409 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7410 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7411 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7412 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7413 | for (const PcRelativePatchInfo& info : infos) { |
| 7414 | const DexFile& dex_file = info.target_dex_file; |
| 7415 | size_t offset_or_index = info.offset_or_index; |
| 7416 | DCHECK(info.add_pc_label.IsBound()); |
| 7417 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7418 | // Add MOVW patch. |
| 7419 | DCHECK(info.movw_label.IsBound()); |
| 7420 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7421 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7422 | // Add MOVT patch. |
| 7423 | DCHECK(info.movt_label.IsBound()); |
| 7424 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7425 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7426 | } |
| 7427 | } |
| 7428 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7429 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7430 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7431 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7432 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7433 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7434 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7435 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7436 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7437 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7438 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7439 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7440 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7441 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7442 | for (const auto& entry : boot_image_string_patches_) { |
| 7443 | const StringReference& target_string = entry.first; |
| 7444 | Literal* literal = entry.second; |
| 7445 | DCHECK(literal->GetLabel()->IsBound()); |
| 7446 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7447 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7448 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7449 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7450 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7451 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7452 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7453 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7454 | linker_patches); |
| 7455 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7456 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7457 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7458 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7459 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7460 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7461 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7462 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7463 | for (const auto& entry : boot_image_type_patches_) { |
| 7464 | const TypeReference& target_type = entry.first; |
| 7465 | Literal* literal = entry.second; |
| 7466 | DCHECK(literal->GetLabel()->IsBound()); |
| 7467 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7468 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7469 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7470 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7471 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7472 | for (const auto& entry : boot_image_address_patches_) { |
| 7473 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7474 | Literal* literal = entry.second; |
| 7475 | DCHECK(literal->GetLabel()->IsBound()); |
| 7476 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7477 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7478 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7479 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7480 | } |
| 7481 | |
| 7482 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7483 | return map->GetOrCreate( |
| 7484 | value, |
| 7485 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7489 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7490 | return map->GetOrCreate( |
| 7491 | target_method, |
| 7492 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7493 | } |
| 7494 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7495 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7496 | LocationSummary* locations = |
| 7497 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7498 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7499 | Location::RequiresRegister()); |
| 7500 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7501 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7502 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7503 | } |
| 7504 | |
| 7505 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7506 | LocationSummary* locations = instr->GetLocations(); |
| 7507 | Register res = locations->Out().AsRegister<Register>(); |
| 7508 | Register accumulator = |
| 7509 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7510 | Register mul_left = |
| 7511 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7512 | Register mul_right = |
| 7513 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7514 | |
| 7515 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7516 | __ mla(res, mul_left, mul_right, accumulator); |
| 7517 | } else { |
| 7518 | __ mls(res, mul_left, mul_right, accumulator); |
| 7519 | } |
| 7520 | } |
| 7521 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7522 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7523 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7524 | LOG(FATAL) << "Unreachable"; |
| 7525 | } |
| 7526 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7527 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7528 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7529 | LOG(FATAL) << "Unreachable"; |
| 7530 | } |
| 7531 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7532 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7533 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7534 | LocationSummary* locations = |
| 7535 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7536 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7537 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7538 | codegen_->GetAssembler()->IsThumb()) { |
| 7539 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7540 | if (switch_instr->GetStartValue() != 0) { |
| 7541 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7542 | } |
| 7543 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7547 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7548 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7549 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7550 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7551 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7552 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7553 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7554 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7555 | Register temp_reg = IP; |
| 7556 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7557 | // the immediate, because IP is used as the destination register. For the other |
| 7558 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7559 | // and they can be encoded in the instruction without making use of IP register. |
| 7560 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7561 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7562 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7563 | // Jump to successors[0] if value == lower_bound. |
| 7564 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7565 | int32_t last_index = 0; |
| 7566 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7567 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7568 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7569 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7570 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7571 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7572 | } |
| 7573 | if (num_entries - last_index == 2) { |
| 7574 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7575 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7576 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7577 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7578 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7579 | // And the default for any other value. |
| 7580 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7581 | __ b(codegen_->GetLabelOf(default_block)); |
| 7582 | } |
| 7583 | } else { |
| 7584 | // Create a table lookup. |
| 7585 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7586 | |
| 7587 | // Materialize a pointer to the switch table |
| 7588 | std::vector<Label*> labels(num_entries); |
| 7589 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7590 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7591 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7592 | } |
| 7593 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7594 | |
| 7595 | // Remove the bias. |
| 7596 | Register key_reg; |
| 7597 | if (lower_bound != 0) { |
| 7598 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7599 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7600 | } else { |
| 7601 | key_reg = value_reg; |
| 7602 | } |
| 7603 | |
| 7604 | // Check whether the value is in the table, jump to default block if not. |
| 7605 | __ CmpConstant(key_reg, num_entries - 1); |
| 7606 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7607 | |
| 7608 | // Load the displacement from the table. |
| 7609 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7610 | |
| 7611 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7612 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7613 | } |
| 7614 | } |
| 7615 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7616 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7617 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7618 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7622 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7623 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7624 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7625 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7626 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7627 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7628 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7629 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7630 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7631 | } |
| 7632 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7633 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7634 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7635 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7636 | return; |
| 7637 | } |
| 7638 | |
| 7639 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7640 | |
| 7641 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7642 | if (return_loc.Equals(trg)) { |
| 7643 | return; |
| 7644 | } |
| 7645 | |
| 7646 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7647 | // with the last branch. |
| 7648 | if (type == Primitive::kPrimLong) { |
| 7649 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7650 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7651 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7652 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7653 | } else if (type == Primitive::kPrimDouble) { |
| 7654 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7655 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7656 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7657 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7658 | } else { |
| 7659 | // Let the parallel move resolver take care of all of this. |
| 7660 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7661 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7662 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7663 | } |
| 7664 | } |
| 7665 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7666 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7667 | LocationSummary* locations = |
| 7668 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7670 | locations->SetOut(Location::RequiresRegister()); |
| 7671 | } |
| 7672 | |
| 7673 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7674 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7675 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7676 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7677 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7678 | __ LoadFromOffset(kLoadWord, |
| 7679 | locations->Out().AsRegister<Register>(), |
| 7680 | locations->InAt(0).AsRegister<Register>(), |
| 7681 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7682 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7683 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7684 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7685 | __ LoadFromOffset(kLoadWord, |
| 7686 | locations->Out().AsRegister<Register>(), |
| 7687 | locations->InAt(0).AsRegister<Register>(), |
| 7688 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7689 | __ LoadFromOffset(kLoadWord, |
| 7690 | locations->Out().AsRegister<Register>(), |
| 7691 | locations->Out().AsRegister<Register>(), |
| 7692 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7693 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7694 | } |
| 7695 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7696 | static void PatchJitRootUse(uint8_t* code, |
| 7697 | const uint8_t* roots_data, |
| 7698 | Literal* literal, |
| 7699 | uint64_t index_in_table) { |
| 7700 | DCHECK(literal->GetLabel()->IsBound()); |
| 7701 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7702 | uintptr_t address = |
| 7703 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7704 | uint8_t* data = code + literal_offset; |
| 7705 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 7706 | } |
| 7707 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7708 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7709 | for (const auto& entry : jit_string_patches_) { |
| 7710 | const auto& it = jit_string_roots_.find(entry.first); |
| 7711 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7712 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 7713 | } |
| 7714 | for (const auto& entry : jit_class_patches_) { |
| 7715 | const auto& it = jit_class_roots_.find(entry.first); |
| 7716 | DCHECK(it != jit_class_roots_.end()); |
| 7717 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7718 | } |
| 7719 | } |
| 7720 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7721 | #undef __ |
| 7722 | #undef QUICK_ENTRY_POINT |
| 7723 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7724 | } // namespace arm |
| 7725 | } // namespace art |