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) { |
| 110 | __ StoreDToOffset(d_reg, SP, stack_offset); |
| 111 | } else if (number_of_d_regs > 1) { |
| 112 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 113 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 114 | } |
| 115 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 116 | } |
| 117 | |
| 118 | if (save_last) { |
| 119 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 120 | } |
| 121 | |
| 122 | return stack_offset; |
| 123 | } |
| 124 | |
| 125 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 126 | size_t last, |
| 127 | CodeGenerator* codegen, |
| 128 | size_t stack_offset) { |
| 129 | DCHECK_LE(first, last); |
| 130 | if ((first == last) && (first == 0)) { |
| 131 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 132 | return stack_offset; |
| 133 | } |
| 134 | if (first % 2 == 1) { |
| 135 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 136 | } |
| 137 | |
| 138 | bool restore_last = false; |
| 139 | if (last % 2 == 0) { |
| 140 | restore_last = true; |
| 141 | --last; |
| 142 | } |
| 143 | |
| 144 | if (first < last) { |
| 145 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 146 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 147 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 148 | if (number_of_d_regs == 1) { |
| 149 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 150 | } else if (number_of_d_regs > 1) { |
| 151 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 152 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 153 | } |
| 154 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 155 | } |
| 156 | |
| 157 | if (restore_last) { |
| 158 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 159 | } |
| 160 | |
| 161 | return stack_offset; |
| 162 | } |
| 163 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 164 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 165 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 166 | size_t orig_offset = stack_offset; |
| 167 | |
| 168 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 169 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 170 | // If the register holds an object, update the stack mask. |
| 171 | if (locations->RegisterContainsObject(i)) { |
| 172 | locations->SetStackBit(stack_offset / kVRegSize); |
| 173 | } |
| 174 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 175 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 176 | saved_core_stack_offsets_[i] = stack_offset; |
| 177 | stack_offset += kArmWordSize; |
| 178 | } |
| 179 | |
| 180 | int reg_num = POPCOUNT(core_spills); |
| 181 | if (reg_num != 0) { |
| 182 | if (reg_num > kRegListThreshold) { |
| 183 | __ StoreList(RegList(core_spills), orig_offset); |
| 184 | } else { |
| 185 | stack_offset = orig_offset; |
| 186 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 187 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 192 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 193 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 197 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 199 | |
| 200 | stack_offset = orig_offset; |
| 201 | while (fp_spills != 0u) { |
| 202 | uint32_t begin = CTZ(fp_spills); |
| 203 | uint32_t tmp = fp_spills + (1u << begin); |
| 204 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 205 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 206 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 207 | } |
| 208 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 212 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 213 | size_t orig_offset = stack_offset; |
| 214 | |
| 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 218 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 219 | stack_offset += kArmWordSize; |
| 220 | } |
| 221 | |
| 222 | int reg_num = POPCOUNT(core_spills); |
| 223 | if (reg_num != 0) { |
| 224 | if (reg_num > kRegListThreshold) { |
| 225 | __ LoadList(RegList(core_spills), orig_offset); |
| 226 | } else { |
| 227 | stack_offset = orig_offset; |
| 228 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 229 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 234 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 235 | while (fp_spills != 0u) { |
| 236 | uint32_t begin = CTZ(fp_spills); |
| 237 | uint32_t tmp = fp_spills + (1u << begin); |
| 238 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 239 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 240 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 241 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 246 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 251 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 252 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 253 | // Live registers will be restored in the catch block if caught. |
| 254 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 255 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 257 | instruction_, |
| 258 | instruction_->GetDexPc(), |
| 259 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 260 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 263 | bool IsFatal() const OVERRIDE { return true; } |
| 264 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 265 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 266 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 267 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 269 | }; |
| 270 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 271 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 272 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 273 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 276 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 277 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 278 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 282 | bool IsFatal() const OVERRIDE { return true; } |
| 283 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 285 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 286 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 288 | }; |
| 289 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 290 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 291 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 293 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 296 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 297 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 298 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 300 | if (successor_ == nullptr) { |
| 301 | __ b(GetReturnLabel()); |
| 302 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 303 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 304 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 307 | Label* GetReturnLabel() { |
| 308 | DCHECK(successor_ == nullptr); |
| 309 | return &return_label_; |
| 310 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 311 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 312 | HBasicBlock* GetSuccessor() const { |
| 313 | return successor_; |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 317 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 318 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 319 | // If not null, the block to branch to after the suspend check. |
| 320 | HBasicBlock* const successor_; |
| 321 | |
| 322 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 323 | Label return_label_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 329 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 330 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | LocationSummary* locations = instruction_->GetLocations(); |
| 336 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 337 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 338 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 339 | // Live registers will be restored in the catch block if caught. |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 341 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 342 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 343 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 344 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 346 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 351 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 352 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 353 | ? kQuickThrowStringBounds |
| 354 | : kQuickThrowArrayBounds; |
| 355 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return true; } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 364 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 366 | }; |
| 367 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 368 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 369 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 370 | LoadClassSlowPathARM(HLoadClass* cls, |
| 371 | HInstruction* at, |
| 372 | uint32_t dex_pc, |
| 373 | bool do_clinit) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 374 | : SlowPathCodeARM(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 375 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 376 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 377 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 378 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 379 | LocationSummary* locations = at_->GetLocations(); |
| 380 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 381 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 382 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 383 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 385 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 386 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 387 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 388 | : kQuickInitializeType; |
| 389 | arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 390 | if (do_clinit_) { |
| 391 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 392 | } else { |
| 393 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 394 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 395 | |
| 396 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 397 | Location out = locations->Out(); |
| 398 | if (out.IsValid()) { |
| 399 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 400 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 401 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 402 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 403 | __ b(GetExitLabel()); |
| 404 | } |
| 405 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 406 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 407 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 408 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 409 | // The class this slow path will load. |
| 410 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 411 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 412 | // The instruction where this slow path is happening. |
| 413 | // (Might be the load class or an initialization check). |
| 414 | HInstruction* const at_; |
| 415 | |
| 416 | // The dex PC of `at_`. |
| 417 | const uint32_t dex_pc_; |
| 418 | |
| 419 | // Whether to initialize the class. |
| 420 | const bool do_clinit_; |
| 421 | |
| 422 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 423 | }; |
| 424 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 425 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 426 | public: |
| 427 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 428 | |
| 429 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 430 | LocationSummary* locations = instruction_->GetLocations(); |
| 431 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 432 | HLoadString* load = instruction_->AsLoadString(); |
| 433 | const uint32_t string_index = load->GetStringIndex(); |
| 434 | Register out = locations->Out().AsRegister<Register>(); |
| 435 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 436 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 437 | |
| 438 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 439 | __ Bind(GetEntryLabel()); |
| 440 | SaveLiveRegisters(codegen, locations); |
| 441 | |
| 442 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 443 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 444 | // the kSaveEverything call (or use `out` for the address after non-kSaveEverything call). |
| 445 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 446 | Register entry_address = temp_is_r0 ? out : temp; |
| 447 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 448 | if (call_saves_everything_except_r0 && temp_is_r0) { |
| 449 | __ mov(entry_address, ShifterOperand(temp)); |
| 450 | } |
| 451 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 452 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
| 453 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 454 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 455 | |
| 456 | // Store the resolved String to the .bss entry. |
| 457 | if (call_saves_everything_except_r0) { |
| 458 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 459 | __ str(R0, Address(entry_address)); |
| 460 | } else { |
| 461 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 462 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 463 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 464 | __ BindTrackedLabel(&labels->movw_label); |
| 465 | __ movw(entry_address, /* placeholder */ 0u); |
| 466 | __ BindTrackedLabel(&labels->movt_label); |
| 467 | __ movt(entry_address, /* placeholder */ 0u); |
| 468 | __ BindTrackedLabel(&labels->add_pc_label); |
| 469 | __ add(entry_address, entry_address, ShifterOperand(PC)); |
| 470 | __ str(R0, Address(entry_address)); |
| 471 | } |
| 472 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 473 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 474 | RestoreLiveRegisters(codegen, locations); |
| 475 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 476 | __ b(GetExitLabel()); |
| 477 | } |
| 478 | |
| 479 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 480 | |
| 481 | private: |
| 482 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 483 | }; |
| 484 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 485 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 486 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 487 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 488 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 489 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 490 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 491 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 492 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 493 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 494 | DCHECK(instruction_->IsCheckCast() |
| 495 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 496 | |
| 497 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 498 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 500 | if (!is_fatal_) { |
| 501 | SaveLiveRegisters(codegen, locations); |
| 502 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 503 | |
| 504 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 505 | // move resolver. |
| 506 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 507 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 508 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 509 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 510 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 511 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 512 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 513 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 514 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 515 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 516 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 517 | instruction_, |
| 518 | instruction_->GetDexPc(), |
| 519 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 520 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 521 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 522 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 523 | } else { |
| 524 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 525 | arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 526 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 527 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 528 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 529 | if (!is_fatal_) { |
| 530 | RestoreLiveRegisters(codegen, locations); |
| 531 | __ b(GetExitLabel()); |
| 532 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 535 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 536 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 537 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 538 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 539 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 540 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 541 | |
| 542 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 543 | }; |
| 544 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 545 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 546 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 547 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 548 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 549 | |
| 550 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 551 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 552 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 553 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 554 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 557 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 558 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 559 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 560 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 561 | }; |
| 562 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 563 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 564 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 565 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 566 | |
| 567 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 568 | LocationSummary* locations = instruction_->GetLocations(); |
| 569 | __ Bind(GetEntryLabel()); |
| 570 | SaveLiveRegisters(codegen, locations); |
| 571 | |
| 572 | InvokeRuntimeCallingConvention calling_convention; |
| 573 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 574 | parallel_move.AddMove( |
| 575 | locations->InAt(0), |
| 576 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 577 | Primitive::kPrimNot, |
| 578 | nullptr); |
| 579 | parallel_move.AddMove( |
| 580 | locations->InAt(1), |
| 581 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 582 | Primitive::kPrimInt, |
| 583 | nullptr); |
| 584 | parallel_move.AddMove( |
| 585 | locations->InAt(2), |
| 586 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 587 | Primitive::kPrimNot, |
| 588 | nullptr); |
| 589 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 590 | |
| 591 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 592 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 593 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 594 | RestoreLiveRegisters(codegen, locations); |
| 595 | __ b(GetExitLabel()); |
| 596 | } |
| 597 | |
| 598 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 599 | |
| 600 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 601 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 602 | }; |
| 603 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 604 | // Slow path marking an object during a read barrier. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 605 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 606 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 607 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 608 | : SlowPathCodeARM(instruction), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 609 | DCHECK(kEmitCompilerReadBarrier); |
| 610 | } |
| 611 | |
| 612 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 613 | |
| 614 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 615 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 616 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 617 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 618 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 619 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 620 | instruction_->IsStaticFieldGet() || |
| 621 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 622 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 623 | instruction_->IsLoadClass() || |
| 624 | instruction_->IsLoadString() || |
| 625 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 626 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 627 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 628 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 629 | << "Unexpected instruction in read barrier marking slow path: " |
| 630 | << instruction_->DebugName(); |
| 631 | |
| 632 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 633 | // No need to save live registers; it's taken care of by the |
| 634 | // entrypoint. Also, there is no need to update the stack mask, |
| 635 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 636 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 637 | DCHECK_NE(reg, SP); |
| 638 | DCHECK_NE(reg, LR); |
| 639 | DCHECK_NE(reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 640 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 641 | // as a temporary, it cannot be the entry point's input/output. |
| 642 | DCHECK_NE(reg, IP); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 643 | DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg; |
| 644 | // "Compact" slow path, saving two moves. |
| 645 | // |
| 646 | // Instead of using the standard runtime calling convention (input |
| 647 | // and output in R0): |
| 648 | // |
| 649 | // R0 <- obj |
| 650 | // R0 <- ReadBarrierMark(R0) |
| 651 | // obj <- R0 |
| 652 | // |
| 653 | // we just use rX (the register holding `obj`) as input and output |
| 654 | // of a dedicated entrypoint: |
| 655 | // |
| 656 | // rX <- ReadBarrierMarkRegX(rX) |
| 657 | // |
| 658 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 659 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 660 | // This runtime call does not require a stack map. |
| 661 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 662 | __ b(GetExitLabel()); |
| 663 | } |
| 664 | |
| 665 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 666 | const Location obj_; |
| 667 | |
| 668 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 669 | }; |
| 670 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 671 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 672 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 673 | public: |
| 674 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 675 | Location out, |
| 676 | Location ref, |
| 677 | Location obj, |
| 678 | uint32_t offset, |
| 679 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 680 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 681 | out_(out), |
| 682 | ref_(ref), |
| 683 | obj_(obj), |
| 684 | offset_(offset), |
| 685 | index_(index) { |
| 686 | DCHECK(kEmitCompilerReadBarrier); |
| 687 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 688 | // has been overwritten by (or after) the heap object reference load |
| 689 | // to be instrumented, e.g.: |
| 690 | // |
| 691 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 692 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 693 | // |
| 694 | // In that case, we have lost the information about the original |
| 695 | // object, and the emitted read barrier cannot work properly. |
| 696 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 697 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 698 | } |
| 699 | |
| 700 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 701 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 702 | LocationSummary* locations = instruction_->GetLocations(); |
| 703 | Register reg_out = out_.AsRegister<Register>(); |
| 704 | DCHECK(locations->CanCall()); |
| 705 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 706 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 707 | instruction_->IsStaticFieldGet() || |
| 708 | instruction_->IsArrayGet() || |
| 709 | instruction_->IsInstanceOf() || |
| 710 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 711 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 712 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 713 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 714 | |
| 715 | __ Bind(GetEntryLabel()); |
| 716 | SaveLiveRegisters(codegen, locations); |
| 717 | |
| 718 | // We may have to change the index's value, but as `index_` is a |
| 719 | // constant member (like other "inputs" of this slow path), |
| 720 | // introduce a copy of it, `index`. |
| 721 | Location index = index_; |
| 722 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 723 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 724 | if (instruction_->IsArrayGet()) { |
| 725 | // Compute the actual memory offset and store it in `index`. |
| 726 | Register index_reg = index_.AsRegister<Register>(); |
| 727 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 728 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 729 | // We are about to change the value of `index_reg` (see the |
| 730 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 731 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 732 | // not been saved by the previous call to |
| 733 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 734 | // callee-save register -- |
| 735 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 736 | // callee-save registers, as it has been designed with the |
| 737 | // assumption that callee-save registers are supposed to be |
| 738 | // handled by the called function. So, as a callee-save |
| 739 | // register, `index_reg` _would_ eventually be saved onto |
| 740 | // the stack, but it would be too late: we would have |
| 741 | // changed its value earlier. Therefore, we manually save |
| 742 | // it here into another freely available register, |
| 743 | // `free_reg`, chosen of course among the caller-save |
| 744 | // registers (as a callee-save `free_reg` register would |
| 745 | // exhibit the same problem). |
| 746 | // |
| 747 | // Note we could have requested a temporary register from |
| 748 | // the register allocator instead; but we prefer not to, as |
| 749 | // this is a slow path, and we know we can find a |
| 750 | // caller-save register that is available. |
| 751 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 752 | __ Mov(free_reg, index_reg); |
| 753 | index_reg = free_reg; |
| 754 | index = Location::RegisterLocation(index_reg); |
| 755 | } else { |
| 756 | // The initial register stored in `index_` has already been |
| 757 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 758 | // (as it is not a callee-save register), so we can freely |
| 759 | // use it. |
| 760 | } |
| 761 | // Shifting the index value contained in `index_reg` by the scale |
| 762 | // factor (2) cannot overflow in practice, as the runtime is |
| 763 | // unable to allocate object arrays with a size larger than |
| 764 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 765 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 766 | static_assert( |
| 767 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 768 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 769 | __ AddConstant(index_reg, index_reg, offset_); |
| 770 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 771 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 772 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 773 | // (as in the case of ArrayGet), as it is actually an offset |
| 774 | // to an object field within an object. |
| 775 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 776 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 777 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 778 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 779 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 780 | DCHECK_EQ(offset_, 0U); |
| 781 | DCHECK(index_.IsRegisterPair()); |
| 782 | // UnsafeGet's offset location is a register pair, the low |
| 783 | // part contains the correct offset. |
| 784 | index = index_.ToLow(); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | // We're moving two or three locations to locations that could |
| 789 | // overlap, so we need a parallel move resolver. |
| 790 | InvokeRuntimeCallingConvention calling_convention; |
| 791 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 792 | parallel_move.AddMove(ref_, |
| 793 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 794 | Primitive::kPrimNot, |
| 795 | nullptr); |
| 796 | parallel_move.AddMove(obj_, |
| 797 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 798 | Primitive::kPrimNot, |
| 799 | nullptr); |
| 800 | if (index.IsValid()) { |
| 801 | parallel_move.AddMove(index, |
| 802 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 803 | Primitive::kPrimInt, |
| 804 | nullptr); |
| 805 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 806 | } else { |
| 807 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 808 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 809 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 810 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 811 | CheckEntrypointTypes< |
| 812 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 813 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 814 | |
| 815 | RestoreLiveRegisters(codegen, locations); |
| 816 | __ b(GetExitLabel()); |
| 817 | } |
| 818 | |
| 819 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 820 | |
| 821 | private: |
| 822 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 823 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 824 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 825 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 826 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 827 | return static_cast<Register>(i); |
| 828 | } |
| 829 | } |
| 830 | // We shall never fail to find a free caller-save register, as |
| 831 | // there are more than two core caller-save registers on ARM |
| 832 | // (meaning it is possible to find one which is different from |
| 833 | // `ref` and `obj`). |
| 834 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 835 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 836 | UNREACHABLE(); |
| 837 | } |
| 838 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 839 | const Location out_; |
| 840 | const Location ref_; |
| 841 | const Location obj_; |
| 842 | const uint32_t offset_; |
| 843 | // An additional location containing an index to an array. |
| 844 | // Only used for HArrayGet and the UnsafeGetObject & |
| 845 | // UnsafeGetObjectVolatile intrinsics. |
| 846 | const Location index_; |
| 847 | |
| 848 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 849 | }; |
| 850 | |
| 851 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 852 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 853 | public: |
| 854 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 855 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 856 | DCHECK(kEmitCompilerReadBarrier); |
| 857 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 858 | |
| 859 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 860 | LocationSummary* locations = instruction_->GetLocations(); |
| 861 | Register reg_out = out_.AsRegister<Register>(); |
| 862 | DCHECK(locations->CanCall()); |
| 863 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 864 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 865 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 866 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 867 | |
| 868 | __ Bind(GetEntryLabel()); |
| 869 | SaveLiveRegisters(codegen, locations); |
| 870 | |
| 871 | InvokeRuntimeCallingConvention calling_convention; |
| 872 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 873 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 874 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 875 | instruction_, |
| 876 | instruction_->GetDexPc(), |
| 877 | this); |
| 878 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 879 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 880 | |
| 881 | RestoreLiveRegisters(codegen, locations); |
| 882 | __ b(GetExitLabel()); |
| 883 | } |
| 884 | |
| 885 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 886 | |
| 887 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 888 | const Location out_; |
| 889 | const Location root_; |
| 890 | |
| 891 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 892 | }; |
| 893 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 894 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 895 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 896 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 897 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 898 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 899 | switch (cond) { |
| 900 | case kCondEQ: return EQ; |
| 901 | case kCondNE: return NE; |
| 902 | case kCondLT: return LT; |
| 903 | case kCondLE: return LE; |
| 904 | case kCondGT: return GT; |
| 905 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 906 | case kCondB: return LO; |
| 907 | case kCondBE: return LS; |
| 908 | case kCondA: return HI; |
| 909 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 910 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 911 | LOG(FATAL) << "Unreachable"; |
| 912 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 915 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 916 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 917 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 918 | case kCondEQ: return EQ; |
| 919 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 920 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 921 | case kCondLT: return LO; |
| 922 | case kCondLE: return LS; |
| 923 | case kCondGT: return HI; |
| 924 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 925 | // Unsigned remain unchanged. |
| 926 | case kCondB: return LO; |
| 927 | case kCondBE: return LS; |
| 928 | case kCondA: return HI; |
| 929 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 930 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 931 | LOG(FATAL) << "Unreachable"; |
| 932 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 935 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 936 | // The ARM condition codes can express all the necessary branches, see the |
| 937 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 938 | // There is no dex instruction or HIR that would need the missing conditions |
| 939 | // "equal or unordered" or "not equal". |
| 940 | switch (cond) { |
| 941 | case kCondEQ: return EQ; |
| 942 | case kCondNE: return NE /* unordered */; |
| 943 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 944 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 945 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 946 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 947 | default: |
| 948 | LOG(FATAL) << "UNREACHABLE"; |
| 949 | UNREACHABLE(); |
| 950 | } |
| 951 | } |
| 952 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 953 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 954 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 958 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 959 | } |
| 960 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 961 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 962 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 963 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 964 | } |
| 965 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 966 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 967 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 968 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 969 | } |
| 970 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 971 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 972 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 973 | return kArmWordSize; |
| 974 | } |
| 975 | |
| 976 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 977 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 978 | return kArmWordSize; |
| 979 | } |
| 980 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 981 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 982 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 983 | const CompilerOptions& compiler_options, |
| 984 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 985 | : CodeGenerator(graph, |
| 986 | kNumberOfCoreRegisters, |
| 987 | kNumberOfSRegisters, |
| 988 | kNumberOfRegisterPairs, |
| 989 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 990 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 991 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 992 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 993 | compiler_options, |
| 994 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 995 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 996 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 997 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 998 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 999 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1000 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1001 | uint32_literals_(std::less<uint32_t>(), |
| 1002 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1003 | method_patches_(MethodReferenceComparator(), |
| 1004 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1005 | call_patches_(MethodReferenceComparator(), |
| 1006 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1007 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1008 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1009 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1010 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1011 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1012 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1013 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1014 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1015 | boot_image_address_patches_(std::less<uint32_t>(), |
| 1016 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1017 | // Always save the LR register to mimic Quick. |
| 1018 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1021 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1022 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1023 | __ FinalizeCode(); |
| 1024 | |
| 1025 | // Adjust native pc offsets in stack maps. |
| 1026 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 1027 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 1028 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1029 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1030 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1031 | // Adjust pc offsets for the disassembly information. |
| 1032 | if (disasm_info_ != nullptr) { |
| 1033 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1034 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1035 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1036 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1037 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1038 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1039 | } |
| 1040 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1041 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1042 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1043 | } |
| 1044 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1045 | |
| 1046 | CodeGenerator::Finalize(allocator); |
| 1047 | } |
| 1048 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1049 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1050 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1051 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1052 | |
| 1053 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1054 | blocked_core_registers_[SP] = true; |
| 1055 | blocked_core_registers_[LR] = true; |
| 1056 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1057 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1058 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1059 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1060 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1061 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1062 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1063 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1064 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1065 | // Stubs do not save callee-save floating point registers. If the graph |
| 1066 | // is debuggable, we need to deal with these registers differently. For |
| 1067 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1068 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1069 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1070 | } |
| 1071 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1072 | |
| 1073 | UpdateBlockedPairRegisters(); |
| 1074 | } |
| 1075 | |
| 1076 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 1077 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1078 | ArmManagedRegister current = |
| 1079 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1080 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 1081 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 1082 | blocked_register_pairs_[i] = true; |
| 1083 | } |
| 1084 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1087 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1088 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1089 | assembler_(codegen->GetAssembler()), |
| 1090 | codegen_(codegen) {} |
| 1091 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1092 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1093 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1094 | 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] | 1095 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1096 | // restore another arbitrary register. |
| 1097 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1098 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1099 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1100 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1101 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1102 | // but in the range. |
| 1103 | if (fpu_spill_mask_ != 0) { |
| 1104 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1105 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1106 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1107 | fpu_spill_mask_ |= (1 << i); |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1112 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1113 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1117 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1120 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1121 | bool skip_overflow_check = |
| 1122 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1123 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1124 | __ Bind(&frame_entry_label_); |
| 1125 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1126 | if (HasEmptyFrame()) { |
| 1127 | return; |
| 1128 | } |
| 1129 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1130 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1131 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1132 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1133 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1136 | __ PushList(core_spill_mask_); |
| 1137 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1138 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1139 | if (fpu_spill_mask_ != 0) { |
| 1140 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1141 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1142 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1143 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1144 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1145 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1146 | __ AddConstant(SP, -adjust); |
| 1147 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1148 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1152 | if (HasEmptyFrame()) { |
| 1153 | __ bx(LR); |
| 1154 | return; |
| 1155 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1156 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1157 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1158 | __ AddConstant(SP, adjust); |
| 1159 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1160 | if (fpu_spill_mask_ != 0) { |
| 1161 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1162 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1163 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1164 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1165 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1166 | // Pop LR into PC to return. |
| 1167 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1168 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1169 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1170 | __ cfi().RestoreState(); |
| 1171 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1174 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1175 | Label* label = GetLabelOf(block); |
| 1176 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1179 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | switch (type) { |
| 1181 | case Primitive::kPrimBoolean: |
| 1182 | case Primitive::kPrimByte: |
| 1183 | case Primitive::kPrimChar: |
| 1184 | case Primitive::kPrimShort: |
| 1185 | case Primitive::kPrimInt: |
| 1186 | case Primitive::kPrimNot: { |
| 1187 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1188 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1190 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1191 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1192 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1193 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1194 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1195 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1196 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1197 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1198 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1199 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1200 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1201 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1202 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1203 | // Skip R1, and use R2_R3 instead. |
| 1204 | gp_index_++; |
| 1205 | index++; |
| 1206 | } |
| 1207 | } |
| 1208 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1209 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1210 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1211 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1212 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1213 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1214 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1215 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | case Primitive::kPrimFloat: { |
| 1220 | uint32_t stack_index = stack_index_++; |
| 1221 | if (float_index_ % 2 == 0) { |
| 1222 | float_index_ = std::max(double_index_, float_index_); |
| 1223 | } |
| 1224 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1225 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1226 | } else { |
| 1227 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | case Primitive::kPrimDouble: { |
| 1232 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1233 | uint32_t stack_index = stack_index_; |
| 1234 | stack_index_ += 2; |
| 1235 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1236 | uint32_t index = double_index_; |
| 1237 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1238 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1239 | calling_convention.GetFpuRegisterAt(index), |
| 1240 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1241 | DCHECK(ExpectedPairLayout(result)); |
| 1242 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1243 | } else { |
| 1244 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1248 | case Primitive::kPrimVoid: |
| 1249 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1250 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1251 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1252 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1253 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1254 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1255 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1256 | switch (type) { |
| 1257 | case Primitive::kPrimBoolean: |
| 1258 | case Primitive::kPrimByte: |
| 1259 | case Primitive::kPrimChar: |
| 1260 | case Primitive::kPrimShort: |
| 1261 | case Primitive::kPrimInt: |
| 1262 | case Primitive::kPrimNot: { |
| 1263 | return Location::RegisterLocation(R0); |
| 1264 | } |
| 1265 | |
| 1266 | case Primitive::kPrimFloat: { |
| 1267 | return Location::FpuRegisterLocation(S0); |
| 1268 | } |
| 1269 | |
| 1270 | case Primitive::kPrimLong: { |
| 1271 | return Location::RegisterPairLocation(R0, R1); |
| 1272 | } |
| 1273 | |
| 1274 | case Primitive::kPrimDouble: { |
| 1275 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1276 | } |
| 1277 | |
| 1278 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1279 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1280 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1281 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1282 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1285 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1286 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1287 | } |
| 1288 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1289 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1290 | if (source.Equals(destination)) { |
| 1291 | return; |
| 1292 | } |
| 1293 | if (destination.IsRegister()) { |
| 1294 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1295 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1296 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1297 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1298 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1299 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1300 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1301 | } else if (destination.IsFpuRegister()) { |
| 1302 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1303 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1304 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1305 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1306 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1307 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1308 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1309 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1310 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1311 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1312 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1313 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1314 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1315 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1316 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1317 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1318 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1324 | if (source.Equals(destination)) { |
| 1325 | return; |
| 1326 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1327 | if (destination.IsRegisterPair()) { |
| 1328 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1329 | EmitParallelMoves( |
| 1330 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1331 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1332 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1333 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1334 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1335 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1336 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1337 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1338 | } else if (source.IsFpuRegisterPair()) { |
| 1339 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1340 | destination.AsRegisterPairHigh<Register>(), |
| 1341 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1342 | } else { |
| 1343 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1344 | DCHECK(ExpectedPairLayout(destination)); |
| 1345 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1346 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1347 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1348 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1349 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1350 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1351 | SP, |
| 1352 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1353 | } else if (source.IsRegisterPair()) { |
| 1354 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1355 | source.AsRegisterPairLow<Register>(), |
| 1356 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1357 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1358 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1359 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1360 | } else { |
| 1361 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1362 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1363 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1364 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1365 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1366 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1367 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1368 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1369 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1370 | SP, destination.GetStackIndex()); |
| 1371 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1372 | } else if (source.IsFpuRegisterPair()) { |
| 1373 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1374 | SP, |
| 1375 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1376 | } else { |
| 1377 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1378 | EmitParallelMoves( |
| 1379 | Location::StackSlot(source.GetStackIndex()), |
| 1380 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1381 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1382 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1383 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1384 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1389 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1390 | DCHECK(location.IsRegister()); |
| 1391 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1392 | } |
| 1393 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1394 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1395 | HParallelMove move(GetGraph()->GetArena()); |
| 1396 | move.AddMove(src, dst, dst_type, nullptr); |
| 1397 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1401 | if (location.IsRegister()) { |
| 1402 | locations->AddTemp(location); |
| 1403 | } else if (location.IsRegisterPair()) { |
| 1404 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1405 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1406 | } else { |
| 1407 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1408 | } |
| 1409 | } |
| 1410 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1411 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1412 | HInstruction* instruction, |
| 1413 | uint32_t dex_pc, |
| 1414 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1415 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1416 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1417 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1418 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1419 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1420 | } |
| 1421 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1422 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1423 | HInstruction* instruction, |
| 1424 | SlowPathCode* slow_path) { |
| 1425 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1426 | GenerateInvokeRuntime(entry_point_offset); |
| 1427 | } |
| 1428 | |
| 1429 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1430 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1431 | __ blx(LR); |
| 1432 | } |
| 1433 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1434 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1435 | DCHECK(!successor->IsExitBlock()); |
| 1436 | |
| 1437 | HBasicBlock* block = got->GetBlock(); |
| 1438 | HInstruction* previous = got->GetPrevious(); |
| 1439 | |
| 1440 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1441 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1442 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1443 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1448 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1449 | } |
| 1450 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1451 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1455 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1456 | got->SetLocations(nullptr); |
| 1457 | } |
| 1458 | |
| 1459 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1460 | HandleGoto(got, got->GetSuccessor()); |
| 1461 | } |
| 1462 | |
| 1463 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1464 | try_boundary->SetLocations(nullptr); |
| 1465 | } |
| 1466 | |
| 1467 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1468 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1469 | if (!successor->IsExitBlock()) { |
| 1470 | HandleGoto(try_boundary, successor); |
| 1471 | } |
| 1472 | } |
| 1473 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1474 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1475 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1478 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1481 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1482 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1483 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1484 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1485 | if (rhs_loc.IsConstant()) { |
| 1486 | // 0.0 is the only immediate that can be encoded directly in |
| 1487 | // a VCMP instruction. |
| 1488 | // |
| 1489 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1490 | // specify that in a floating-point comparison, positive zero |
| 1491 | // and negative zero are considered equal, so we can use the |
| 1492 | // literal 0.0 for both cases here. |
| 1493 | // |
| 1494 | // Note however that some methods (Float.equal, Float.compare, |
| 1495 | // Float.compareTo, Double.equal, Double.compare, |
| 1496 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1497 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1498 | // -0.0. So if we ever translate calls to these methods into a |
| 1499 | // HCompare instruction, we must handle the -0.0 case with |
| 1500 | // care here. |
| 1501 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1502 | if (type == Primitive::kPrimFloat) { |
| 1503 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1504 | } else { |
| 1505 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1506 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1507 | } |
| 1508 | } else { |
| 1509 | if (type == Primitive::kPrimFloat) { |
| 1510 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1511 | } else { |
| 1512 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1513 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1514 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1519 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1520 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1521 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1522 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1523 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1527 | Label* true_label, |
| 1528 | Label* false_label) { |
| 1529 | LocationSummary* locations = cond->GetLocations(); |
| 1530 | Location left = locations->InAt(0); |
| 1531 | Location right = locations->InAt(1); |
| 1532 | IfCondition if_cond = cond->GetCondition(); |
| 1533 | |
| 1534 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1535 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1536 | IfCondition true_high_cond = if_cond; |
| 1537 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1538 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1539 | |
| 1540 | // Set the conditions for the test, remembering that == needs to be |
| 1541 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1542 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1543 | switch (if_cond) { |
| 1544 | case kCondEQ: |
| 1545 | case kCondNE: |
| 1546 | // Nothing to do. |
| 1547 | break; |
| 1548 | case kCondLT: |
| 1549 | false_high_cond = kCondGT; |
| 1550 | break; |
| 1551 | case kCondLE: |
| 1552 | true_high_cond = kCondLT; |
| 1553 | break; |
| 1554 | case kCondGT: |
| 1555 | false_high_cond = kCondLT; |
| 1556 | break; |
| 1557 | case kCondGE: |
| 1558 | true_high_cond = kCondGT; |
| 1559 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1560 | case kCondB: |
| 1561 | false_high_cond = kCondA; |
| 1562 | break; |
| 1563 | case kCondBE: |
| 1564 | true_high_cond = kCondB; |
| 1565 | break; |
| 1566 | case kCondA: |
| 1567 | false_high_cond = kCondB; |
| 1568 | break; |
| 1569 | case kCondAE: |
| 1570 | true_high_cond = kCondA; |
| 1571 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1572 | } |
| 1573 | if (right.IsConstant()) { |
| 1574 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1575 | int32_t val_low = Low32Bits(value); |
| 1576 | int32_t val_high = High32Bits(value); |
| 1577 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1578 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1579 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1580 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1581 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1582 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1583 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1584 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1585 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1586 | } |
| 1587 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1588 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1589 | } else { |
| 1590 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1591 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1592 | |
| 1593 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1594 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1595 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1596 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1597 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1598 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1599 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1600 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1601 | } |
| 1602 | // Must be equal high, so compare the lows. |
| 1603 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1604 | } |
| 1605 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1606 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1607 | __ b(true_label, final_condition); |
| 1608 | } |
| 1609 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1610 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1611 | Label* true_target_in, |
| 1612 | Label* false_target_in) { |
| 1613 | // Generated branching requires both targets to be explicit. If either of the |
| 1614 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1615 | Label fallthrough_target; |
| 1616 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1617 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1618 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1619 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1620 | switch (type) { |
| 1621 | case Primitive::kPrimLong: |
| 1622 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1623 | break; |
| 1624 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1625 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1626 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1627 | GenerateFPJumps(condition, true_target, false_target); |
| 1628 | break; |
| 1629 | default: |
| 1630 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1631 | } |
| 1632 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1633 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1634 | __ b(false_target); |
| 1635 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1636 | |
| 1637 | if (fallthrough_target.IsLinked()) { |
| 1638 | __ Bind(&fallthrough_target); |
| 1639 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1642 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1643 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1644 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1645 | Label* false_target) { |
| 1646 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1647 | |
| 1648 | if (true_target == nullptr && false_target == nullptr) { |
| 1649 | // Nothing to do. The code always falls through. |
| 1650 | return; |
| 1651 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1652 | // Constant condition, statically compared against "true" (integer value 1). |
| 1653 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1654 | if (true_target != nullptr) { |
| 1655 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1656 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1657 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1658 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1659 | if (false_target != nullptr) { |
| 1660 | __ b(false_target); |
| 1661 | } |
| 1662 | } |
| 1663 | return; |
| 1664 | } |
| 1665 | |
| 1666 | // The following code generates these patterns: |
| 1667 | // (1) true_target == nullptr && false_target != nullptr |
| 1668 | // - opposite condition true => branch to false_target |
| 1669 | // (2) true_target != nullptr && false_target == nullptr |
| 1670 | // - condition true => branch to true_target |
| 1671 | // (3) true_target != nullptr && false_target != nullptr |
| 1672 | // - condition true => branch to true_target |
| 1673 | // - branch to false_target |
| 1674 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1675 | // Condition has been materialized, compare the output to 0. |
| 1676 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1677 | DCHECK(cond_val.IsRegister()); |
| 1678 | if (true_target == nullptr) { |
| 1679 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1680 | } else { |
| 1681 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1682 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1683 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1684 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1685 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1686 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | |
| 1688 | // If this is a long or FP comparison that has been folded into |
| 1689 | // the HCondition, generate the comparison directly. |
| 1690 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1691 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1692 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1693 | return; |
| 1694 | } |
| 1695 | |
| 1696 | LocationSummary* locations = cond->GetLocations(); |
| 1697 | DCHECK(locations->InAt(0).IsRegister()); |
| 1698 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1699 | Location right = locations->InAt(1); |
| 1700 | if (right.IsRegister()) { |
| 1701 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1702 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1703 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1704 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1705 | } |
| 1706 | if (true_target == nullptr) { |
| 1707 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1708 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1709 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1710 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1711 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1712 | |
| 1713 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1714 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1715 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1716 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1720 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1721 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1722 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1728 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1729 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1730 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1731 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1732 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1733 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1734 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1738 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1739 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1740 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1741 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1747 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1748 | GenerateTestAndBranch(deoptimize, |
| 1749 | /* condition_input_index */ 0, |
| 1750 | slow_path->GetEntryLabel(), |
| 1751 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1752 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1753 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1754 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1755 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1756 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1757 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1758 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1759 | } else { |
| 1760 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1761 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1762 | } |
| 1763 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1764 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1765 | } |
| 1766 | locations->SetOut(Location::SameAsFirstInput()); |
| 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1770 | LocationSummary* locations = select->GetLocations(); |
| 1771 | Label false_target; |
| 1772 | GenerateTestAndBranch(select, |
| 1773 | /* condition_input_index */ 2, |
| 1774 | /* true_target */ nullptr, |
| 1775 | &false_target); |
| 1776 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1777 | __ Bind(&false_target); |
| 1778 | } |
| 1779 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1780 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1781 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1782 | } |
| 1783 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1784 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1785 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void CodeGeneratorARM::GenerateNop() { |
| 1789 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1793 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1794 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1795 | // Handle the long/FP comparisons made in instruction simplification. |
| 1796 | switch (cond->InputAt(0)->GetType()) { |
| 1797 | case Primitive::kPrimLong: |
| 1798 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1799 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1800 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1801 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1802 | } |
| 1803 | break; |
| 1804 | |
| 1805 | case Primitive::kPrimFloat: |
| 1806 | case Primitive::kPrimDouble: |
| 1807 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1808 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1809 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1810 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1811 | } |
| 1812 | break; |
| 1813 | |
| 1814 | default: |
| 1815 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1816 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1817 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1818 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1819 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1820 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1823 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1824 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1825 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1826 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1827 | |
| 1828 | LocationSummary* locations = cond->GetLocations(); |
| 1829 | Location left = locations->InAt(0); |
| 1830 | Location right = locations->InAt(1); |
| 1831 | Register out = locations->Out().AsRegister<Register>(); |
| 1832 | Label true_label, false_label; |
| 1833 | |
| 1834 | switch (cond->InputAt(0)->GetType()) { |
| 1835 | default: { |
| 1836 | // Integer case. |
| 1837 | if (right.IsRegister()) { |
| 1838 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1839 | } else { |
| 1840 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1841 | __ CmpConstant(left.AsRegister<Register>(), |
| 1842 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1843 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1844 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1845 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1846 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1847 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1848 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1849 | return; |
| 1850 | } |
| 1851 | case Primitive::kPrimLong: |
| 1852 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1853 | break; |
| 1854 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1855 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1856 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1857 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1858 | break; |
| 1859 | } |
| 1860 | |
| 1861 | // Convert the jumps into the result. |
| 1862 | Label done_label; |
| 1863 | |
| 1864 | // False case: result = 0. |
| 1865 | __ Bind(&false_label); |
| 1866 | __ LoadImmediate(out, 0); |
| 1867 | __ b(&done_label); |
| 1868 | |
| 1869 | // True case: result = 1. |
| 1870 | __ Bind(&true_label); |
| 1871 | __ LoadImmediate(out, 1); |
| 1872 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1876 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1880 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1884 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1888 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1892 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1896 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1900 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1904 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1908 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1912 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1916 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1920 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1923 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1924 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1928 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1932 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1936 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1940 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1944 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1948 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1952 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1955 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1956 | LocationSummary* locations = |
| 1957 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1958 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1961 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1962 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1965 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1966 | LocationSummary* locations = |
| 1967 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1968 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1969 | } |
| 1970 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1971 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1972 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1975 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1976 | LocationSummary* locations = |
| 1977 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1978 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1979 | } |
| 1980 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1981 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1982 | // Will be generated at use site. |
| 1983 | } |
| 1984 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1985 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1986 | LocationSummary* locations = |
| 1987 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1988 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1989 | } |
| 1990 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1991 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1992 | // Will be generated at use site. |
| 1993 | } |
| 1994 | |
| 1995 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1996 | LocationSummary* locations = |
| 1997 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1998 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1999 | } |
| 2000 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2001 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2002 | // Will be generated at use site. |
| 2003 | } |
| 2004 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2005 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2006 | memory_barrier->SetLocations(nullptr); |
| 2007 | } |
| 2008 | |
| 2009 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2010 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2011 | } |
| 2012 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2013 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2014 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2017 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2018 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2021 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2022 | LocationSummary* locations = |
| 2023 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2024 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2027 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2028 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2031 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2032 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2033 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2034 | // the method_idx. |
| 2035 | HandleInvoke(invoke); |
| 2036 | } |
| 2037 | |
| 2038 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2039 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2040 | } |
| 2041 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2042 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2043 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2044 | // art::PrepareForRegisterAllocation. |
| 2045 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2046 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2047 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2048 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2049 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2050 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2051 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2052 | return; |
| 2053 | } |
| 2054 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2055 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2056 | |
| 2057 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2058 | if (invoke->HasPcRelativeDexCache()) { |
| 2059 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2060 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2061 | } |
| 2062 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2063 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2064 | if (invoke->GetLocations()->Intrinsified()) { |
| 2065 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2066 | intrinsic.Dispatch(invoke); |
| 2067 | return true; |
| 2068 | } |
| 2069 | return false; |
| 2070 | } |
| 2071 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2072 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2073 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2074 | // art::PrepareForRegisterAllocation. |
| 2075 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2076 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2077 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2078 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2079 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2080 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2081 | LocationSummary* locations = invoke->GetLocations(); |
| 2082 | codegen_->GenerateStaticOrDirectCall( |
| 2083 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2084 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2087 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2088 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2089 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2092 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2093 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2094 | if (intrinsic.TryDispatch(invoke)) { |
| 2095 | return; |
| 2096 | } |
| 2097 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2098 | HandleInvoke(invoke); |
| 2099 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2100 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2101 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2102 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2103 | return; |
| 2104 | } |
| 2105 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2106 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2107 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2108 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2111 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2112 | HandleInvoke(invoke); |
| 2113 | // Add the hidden argument. |
| 2114 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2115 | } |
| 2116 | |
| 2117 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2118 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2119 | LocationSummary* locations = invoke->GetLocations(); |
| 2120 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2121 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2122 | Location receiver = locations->InAt(0); |
| 2123 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2124 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2125 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2126 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2127 | DCHECK_EQ(R12, hidden_reg); |
| 2128 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2129 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2130 | if (receiver.IsStackSlot()) { |
| 2131 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2132 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2133 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2134 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2135 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2136 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2137 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2138 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2139 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2140 | // emit a read barrier for the previous class reference load. |
| 2141 | // However this is not required in practice, as this is an |
| 2142 | // intermediate/temporary reference and because the current |
| 2143 | // concurrent copying collector keeps the from-space memory |
| 2144 | // intact/accessible until the end of the marking phase (the |
| 2145 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2146 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2147 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2148 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2149 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2150 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2151 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2152 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2153 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2154 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2155 | // LR = temp->GetEntryPoint(); |
| 2156 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2157 | // LR(); |
| 2158 | __ blx(LR); |
| 2159 | DCHECK(!codegen_->IsLeafMethod()); |
| 2160 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2161 | } |
| 2162 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2163 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2164 | LocationSummary* locations = |
| 2165 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2166 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2167 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2168 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2169 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2170 | break; |
| 2171 | } |
| 2172 | case Primitive::kPrimLong: { |
| 2173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2174 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2175 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2176 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2177 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2178 | case Primitive::kPrimFloat: |
| 2179 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2180 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2181 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2182 | break; |
| 2183 | |
| 2184 | default: |
| 2185 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2190 | LocationSummary* locations = neg->GetLocations(); |
| 2191 | Location out = locations->Out(); |
| 2192 | Location in = locations->InAt(0); |
| 2193 | switch (neg->GetResultType()) { |
| 2194 | case Primitive::kPrimInt: |
| 2195 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2196 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2197 | break; |
| 2198 | |
| 2199 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2200 | DCHECK(in.IsRegisterPair()); |
| 2201 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2202 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2203 | in.AsRegisterPairLow<Register>(), |
| 2204 | ShifterOperand(0)); |
| 2205 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2206 | // instruction here, as it does not exist in the Thumb-2 |
| 2207 | // instruction set. We use the following approach |
| 2208 | // using SBC and SUB instead. |
| 2209 | // |
| 2210 | // out.hi = -C |
| 2211 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2212 | out.AsRegisterPairHigh<Register>(), |
| 2213 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2214 | // out.hi = out.hi - in.hi |
| 2215 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2216 | out.AsRegisterPairHigh<Register>(), |
| 2217 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2218 | break; |
| 2219 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2220 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2221 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2222 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2223 | break; |
| 2224 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2225 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2226 | DCHECK(in.IsFpuRegisterPair()); |
| 2227 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2228 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2229 | break; |
| 2230 | |
| 2231 | default: |
| 2232 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2233 | } |
| 2234 | } |
| 2235 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2236 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2237 | Primitive::Type result_type = conversion->GetResultType(); |
| 2238 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2239 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2240 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2241 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2242 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2243 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2244 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2245 | && result_type == Primitive::kPrimLong) |
| 2246 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2247 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2248 | : LocationSummary::kNoCall; |
| 2249 | LocationSummary* locations = |
| 2250 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2251 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2252 | // The Java language does not allow treating boolean as an integral type but |
| 2253 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2254 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2255 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2256 | case Primitive::kPrimByte: |
| 2257 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2258 | case Primitive::kPrimLong: |
| 2259 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2260 | case Primitive::kPrimBoolean: |
| 2261 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2262 | case Primitive::kPrimShort: |
| 2263 | case Primitive::kPrimInt: |
| 2264 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2265 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2266 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2267 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2268 | break; |
| 2269 | |
| 2270 | default: |
| 2271 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2272 | << " to " << result_type; |
| 2273 | } |
| 2274 | break; |
| 2275 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimShort: |
| 2277 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimLong: |
| 2279 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimBoolean: |
| 2281 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2282 | case Primitive::kPrimByte: |
| 2283 | case Primitive::kPrimInt: |
| 2284 | case Primitive::kPrimChar: |
| 2285 | // Processing a Dex `int-to-short' instruction. |
| 2286 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2288 | break; |
| 2289 | |
| 2290 | default: |
| 2291 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2292 | << " to " << result_type; |
| 2293 | } |
| 2294 | break; |
| 2295 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2296 | case Primitive::kPrimInt: |
| 2297 | switch (input_type) { |
| 2298 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2299 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2300 | locations->SetInAt(0, Location::Any()); |
| 2301 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2302 | break; |
| 2303 | |
| 2304 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2305 | // Processing a Dex `float-to-int' instruction. |
| 2306 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2307 | locations->SetOut(Location::RequiresRegister()); |
| 2308 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2309 | break; |
| 2310 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2312 | // Processing a Dex `double-to-int' instruction. |
| 2313 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2314 | locations->SetOut(Location::RequiresRegister()); |
| 2315 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2316 | break; |
| 2317 | |
| 2318 | default: |
| 2319 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2320 | << " to " << result_type; |
| 2321 | } |
| 2322 | break; |
| 2323 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2324 | case Primitive::kPrimLong: |
| 2325 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimBoolean: |
| 2327 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | case Primitive::kPrimByte: |
| 2329 | case Primitive::kPrimShort: |
| 2330 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2332 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2334 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2335 | break; |
| 2336 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2337 | case Primitive::kPrimFloat: { |
| 2338 | // Processing a Dex `float-to-long' instruction. |
| 2339 | InvokeRuntimeCallingConvention calling_convention; |
| 2340 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2341 | calling_convention.GetFpuRegisterAt(0))); |
| 2342 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2343 | break; |
| 2344 | } |
| 2345 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2346 | case Primitive::kPrimDouble: { |
| 2347 | // Processing a Dex `double-to-long' instruction. |
| 2348 | InvokeRuntimeCallingConvention calling_convention; |
| 2349 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2350 | calling_convention.GetFpuRegisterAt(0), |
| 2351 | calling_convention.GetFpuRegisterAt(1))); |
| 2352 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2353 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2354 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2355 | |
| 2356 | default: |
| 2357 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2358 | << " to " << result_type; |
| 2359 | } |
| 2360 | break; |
| 2361 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2362 | case Primitive::kPrimChar: |
| 2363 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimLong: |
| 2365 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2366 | case Primitive::kPrimBoolean: |
| 2367 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimByte: |
| 2369 | case Primitive::kPrimShort: |
| 2370 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2371 | // Processing a Dex `int-to-char' instruction. |
| 2372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2373 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2374 | break; |
| 2375 | |
| 2376 | default: |
| 2377 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2378 | << " to " << result_type; |
| 2379 | } |
| 2380 | break; |
| 2381 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2383 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2384 | case Primitive::kPrimBoolean: |
| 2385 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2386 | case Primitive::kPrimByte: |
| 2387 | case Primitive::kPrimShort: |
| 2388 | case Primitive::kPrimInt: |
| 2389 | case Primitive::kPrimChar: |
| 2390 | // Processing a Dex `int-to-float' instruction. |
| 2391 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2392 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2393 | break; |
| 2394 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2395 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2396 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2397 | InvokeRuntimeCallingConvention calling_convention; |
| 2398 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2399 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2400 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2401 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2402 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2403 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2405 | // Processing a Dex `double-to-float' instruction. |
| 2406 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2407 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2408 | break; |
| 2409 | |
| 2410 | default: |
| 2411 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2412 | << " to " << result_type; |
| 2413 | }; |
| 2414 | break; |
| 2415 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2416 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2417 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimBoolean: |
| 2419 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2420 | case Primitive::kPrimByte: |
| 2421 | case Primitive::kPrimShort: |
| 2422 | case Primitive::kPrimInt: |
| 2423 | case Primitive::kPrimChar: |
| 2424 | // Processing a Dex `int-to-double' instruction. |
| 2425 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2426 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2427 | break; |
| 2428 | |
| 2429 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2430 | // Processing a Dex `long-to-double' instruction. |
| 2431 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2432 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2433 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2434 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2435 | break; |
| 2436 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2437 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2438 | // Processing a Dex `float-to-double' instruction. |
| 2439 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2440 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2445 | << " to " << result_type; |
| 2446 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2447 | break; |
| 2448 | |
| 2449 | default: |
| 2450 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2451 | << " to " << result_type; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2456 | LocationSummary* locations = conversion->GetLocations(); |
| 2457 | Location out = locations->Out(); |
| 2458 | Location in = locations->InAt(0); |
| 2459 | Primitive::Type result_type = conversion->GetResultType(); |
| 2460 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2461 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2462 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2463 | case Primitive::kPrimByte: |
| 2464 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimLong: |
| 2466 | // Type conversion from long to byte is a result of code transformations. |
| 2467 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2468 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2469 | case Primitive::kPrimBoolean: |
| 2470 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2471 | case Primitive::kPrimShort: |
| 2472 | case Primitive::kPrimInt: |
| 2473 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2474 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2475 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | |
| 2478 | default: |
| 2479 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2480 | << " to " << result_type; |
| 2481 | } |
| 2482 | break; |
| 2483 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2484 | case Primitive::kPrimShort: |
| 2485 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2486 | case Primitive::kPrimLong: |
| 2487 | // Type conversion from long to short is a result of code transformations. |
| 2488 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2489 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimBoolean: |
| 2491 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimByte: |
| 2493 | case Primitive::kPrimInt: |
| 2494 | case Primitive::kPrimChar: |
| 2495 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2496 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2497 | break; |
| 2498 | |
| 2499 | default: |
| 2500 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2501 | << " to " << result_type; |
| 2502 | } |
| 2503 | break; |
| 2504 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimInt: |
| 2506 | switch (input_type) { |
| 2507 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2508 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2509 | DCHECK(out.IsRegister()); |
| 2510 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2511 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2512 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2513 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2514 | } else { |
| 2515 | DCHECK(in.IsConstant()); |
| 2516 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2517 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2518 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2519 | } |
| 2520 | break; |
| 2521 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2522 | case Primitive::kPrimFloat: { |
| 2523 | // Processing a Dex `float-to-int' instruction. |
| 2524 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2525 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2526 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2527 | break; |
| 2528 | } |
| 2529 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimDouble: { |
| 2531 | // Processing a Dex `double-to-int' instruction. |
| 2532 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2533 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2534 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2535 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2536 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2537 | |
| 2538 | default: |
| 2539 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2540 | << " to " << result_type; |
| 2541 | } |
| 2542 | break; |
| 2543 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimLong: |
| 2545 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimBoolean: |
| 2547 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2548 | case Primitive::kPrimByte: |
| 2549 | case Primitive::kPrimShort: |
| 2550 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2551 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2552 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2553 | DCHECK(out.IsRegisterPair()); |
| 2554 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2555 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2556 | // Sign extension. |
| 2557 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2558 | out.AsRegisterPairLow<Register>(), |
| 2559 | 31); |
| 2560 | break; |
| 2561 | |
| 2562 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2563 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2564 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2565 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2566 | break; |
| 2567 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2568 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2569 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2570 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2571 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2572 | break; |
| 2573 | |
| 2574 | default: |
| 2575 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2576 | << " to " << result_type; |
| 2577 | } |
| 2578 | break; |
| 2579 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2580 | case Primitive::kPrimChar: |
| 2581 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2582 | case Primitive::kPrimLong: |
| 2583 | // Type conversion from long to char is a result of code transformations. |
| 2584 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2585 | break; |
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 | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimByte: |
| 2589 | case Primitive::kPrimShort: |
| 2590 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2591 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2592 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | |
| 2595 | default: |
| 2596 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2597 | << " to " << result_type; |
| 2598 | } |
| 2599 | break; |
| 2600 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2602 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2603 | case Primitive::kPrimBoolean: |
| 2604 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimByte: |
| 2606 | case Primitive::kPrimShort: |
| 2607 | case Primitive::kPrimInt: |
| 2608 | case Primitive::kPrimChar: { |
| 2609 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2610 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2611 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | } |
| 2614 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2615 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2616 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2617 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2618 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2619 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2620 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2621 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2622 | // Processing a Dex `double-to-float' instruction. |
| 2623 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2624 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2625 | break; |
| 2626 | |
| 2627 | default: |
| 2628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2629 | << " to " << result_type; |
| 2630 | }; |
| 2631 | break; |
| 2632 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2634 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2635 | case Primitive::kPrimBoolean: |
| 2636 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimByte: |
| 2638 | case Primitive::kPrimShort: |
| 2639 | case Primitive::kPrimInt: |
| 2640 | case Primitive::kPrimChar: { |
| 2641 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2642 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2643 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2644 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2645 | break; |
| 2646 | } |
| 2647 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2648 | case Primitive::kPrimLong: { |
| 2649 | // Processing a Dex `long-to-double' instruction. |
| 2650 | Register low = in.AsRegisterPairLow<Register>(); |
| 2651 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2652 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2653 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2654 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2655 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2656 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2657 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2658 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2659 | // temp_d = int-to-double(high) |
| 2660 | __ vmovsr(temp_s, high); |
| 2661 | __ vcvtdi(temp_d, temp_s); |
| 2662 | // constant_d = k2Pow32EncodingForDouble |
| 2663 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2664 | // out_d = unsigned-to-double(low) |
| 2665 | __ vmovsr(out_s, low); |
| 2666 | __ vcvtdu(out_d, out_s); |
| 2667 | // out_d += temp_d * constant_d |
| 2668 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2669 | break; |
| 2670 | } |
| 2671 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2672 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2673 | // Processing a Dex `float-to-double' instruction. |
| 2674 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2675 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 | break; |
| 2677 | |
| 2678 | default: |
| 2679 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2680 | << " to " << result_type; |
| 2681 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2682 | break; |
| 2683 | |
| 2684 | default: |
| 2685 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2686 | << " to " << result_type; |
| 2687 | } |
| 2688 | } |
| 2689 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2690 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2691 | LocationSummary* locations = |
| 2692 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2693 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2694 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2695 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2696 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2697 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2698 | break; |
| 2699 | } |
| 2700 | |
| 2701 | case Primitive::kPrimLong: { |
| 2702 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2703 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2704 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2705 | break; |
| 2706 | } |
| 2707 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2708 | case Primitive::kPrimFloat: |
| 2709 | case Primitive::kPrimDouble: { |
| 2710 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2711 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2712 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2713 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2714 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2715 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2716 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2717 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2718 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2722 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2723 | Location out = locations->Out(); |
| 2724 | Location first = locations->InAt(0); |
| 2725 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2726 | switch (add->GetResultType()) { |
| 2727 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2728 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2729 | __ add(out.AsRegister<Register>(), |
| 2730 | first.AsRegister<Register>(), |
| 2731 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2732 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2733 | __ AddConstant(out.AsRegister<Register>(), |
| 2734 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2735 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2736 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2737 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2738 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2739 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2740 | if (second.IsConstant()) { |
| 2741 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2742 | GenerateAddLongConst(out, first, value); |
| 2743 | } else { |
| 2744 | DCHECK(second.IsRegisterPair()); |
| 2745 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2746 | first.AsRegisterPairLow<Register>(), |
| 2747 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2748 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2749 | first.AsRegisterPairHigh<Register>(), |
| 2750 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2751 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2752 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2753 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2754 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2755 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2756 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2757 | first.AsFpuRegister<SRegister>(), |
| 2758 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2759 | break; |
| 2760 | |
| 2761 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2762 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2763 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2764 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2765 | break; |
| 2766 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2767 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2768 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2772 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2773 | LocationSummary* locations = |
| 2774 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2775 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2776 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2777 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2778 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2779 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2780 | break; |
| 2781 | } |
| 2782 | |
| 2783 | case Primitive::kPrimLong: { |
| 2784 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2785 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2786 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2787 | break; |
| 2788 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2789 | case Primitive::kPrimFloat: |
| 2790 | case Primitive::kPrimDouble: { |
| 2791 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2792 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2793 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2794 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2795 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2796 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2797 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2798 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2802 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2803 | Location out = locations->Out(); |
| 2804 | Location first = locations->InAt(0); |
| 2805 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2806 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2807 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2808 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2809 | __ sub(out.AsRegister<Register>(), |
| 2810 | first.AsRegister<Register>(), |
| 2811 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2812 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2813 | __ AddConstant(out.AsRegister<Register>(), |
| 2814 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2815 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2816 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2817 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2818 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2819 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2820 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2821 | if (second.IsConstant()) { |
| 2822 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2823 | GenerateAddLongConst(out, first, -value); |
| 2824 | } else { |
| 2825 | DCHECK(second.IsRegisterPair()); |
| 2826 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2827 | first.AsRegisterPairLow<Register>(), |
| 2828 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2829 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2830 | first.AsRegisterPairHigh<Register>(), |
| 2831 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2832 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2833 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2834 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2835 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2836 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2837 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2838 | first.AsFpuRegister<SRegister>(), |
| 2839 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2840 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2844 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2845 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2846 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2847 | break; |
| 2848 | } |
| 2849 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2850 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2851 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2852 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2853 | } |
| 2854 | } |
| 2855 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2856 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2857 | LocationSummary* locations = |
| 2858 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2859 | switch (mul->GetResultType()) { |
| 2860 | case Primitive::kPrimInt: |
| 2861 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2862 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2863 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2864 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2865 | break; |
| 2866 | } |
| 2867 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2868 | case Primitive::kPrimFloat: |
| 2869 | case Primitive::kPrimDouble: { |
| 2870 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2871 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2872 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2873 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2874 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2875 | |
| 2876 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2877 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2882 | LocationSummary* locations = mul->GetLocations(); |
| 2883 | Location out = locations->Out(); |
| 2884 | Location first = locations->InAt(0); |
| 2885 | Location second = locations->InAt(1); |
| 2886 | switch (mul->GetResultType()) { |
| 2887 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2888 | __ mul(out.AsRegister<Register>(), |
| 2889 | first.AsRegister<Register>(), |
| 2890 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2891 | break; |
| 2892 | } |
| 2893 | case Primitive::kPrimLong: { |
| 2894 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2895 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2896 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2897 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2898 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2899 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2900 | |
| 2901 | // Extra checks to protect caused by the existence of R1_R2. |
| 2902 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2903 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2904 | DCHECK_NE(out_hi, in1_lo); |
| 2905 | DCHECK_NE(out_hi, in2_lo); |
| 2906 | |
| 2907 | // input: in1 - 64 bits, in2 - 64 bits |
| 2908 | // output: out |
| 2909 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2910 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2911 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2912 | |
| 2913 | // IP <- in1.lo * in2.hi |
| 2914 | __ mul(IP, in1_lo, in2_hi); |
| 2915 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2916 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2917 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2918 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2919 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2920 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2921 | break; |
| 2922 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2923 | |
| 2924 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2925 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2926 | first.AsFpuRegister<SRegister>(), |
| 2927 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2928 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2932 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2933 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2934 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2935 | break; |
| 2936 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2937 | |
| 2938 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2939 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2943 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2944 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2945 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2946 | |
| 2947 | LocationSummary* locations = instruction->GetLocations(); |
| 2948 | Location second = locations->InAt(1); |
| 2949 | DCHECK(second.IsConstant()); |
| 2950 | |
| 2951 | Register out = locations->Out().AsRegister<Register>(); |
| 2952 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2953 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2954 | DCHECK(imm == 1 || imm == -1); |
| 2955 | |
| 2956 | if (instruction->IsRem()) { |
| 2957 | __ LoadImmediate(out, 0); |
| 2958 | } else { |
| 2959 | if (imm == 1) { |
| 2960 | __ Mov(out, dividend); |
| 2961 | } else { |
| 2962 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2963 | } |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2968 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2969 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2970 | |
| 2971 | LocationSummary* locations = instruction->GetLocations(); |
| 2972 | Location second = locations->InAt(1); |
| 2973 | DCHECK(second.IsConstant()); |
| 2974 | |
| 2975 | Register out = locations->Out().AsRegister<Register>(); |
| 2976 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2977 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2978 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2979 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2980 | int ctz_imm = CTZ(abs_imm); |
| 2981 | |
| 2982 | if (ctz_imm == 1) { |
| 2983 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2984 | } else { |
| 2985 | __ Asr(temp, dividend, 31); |
| 2986 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2987 | } |
| 2988 | __ add(out, temp, ShifterOperand(dividend)); |
| 2989 | |
| 2990 | if (instruction->IsDiv()) { |
| 2991 | __ Asr(out, out, ctz_imm); |
| 2992 | if (imm < 0) { |
| 2993 | __ rsb(out, out, ShifterOperand(0)); |
| 2994 | } |
| 2995 | } else { |
| 2996 | __ ubfx(out, out, 0, ctz_imm); |
| 2997 | __ sub(out, out, ShifterOperand(temp)); |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3002 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3003 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3004 | |
| 3005 | LocationSummary* locations = instruction->GetLocations(); |
| 3006 | Location second = locations->InAt(1); |
| 3007 | DCHECK(second.IsConstant()); |
| 3008 | |
| 3009 | Register out = locations->Out().AsRegister<Register>(); |
| 3010 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3011 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3012 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3013 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3014 | |
| 3015 | int64_t magic; |
| 3016 | int shift; |
| 3017 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3018 | |
| 3019 | __ LoadImmediate(temp1, magic); |
| 3020 | __ smull(temp2, temp1, dividend, temp1); |
| 3021 | |
| 3022 | if (imm > 0 && magic < 0) { |
| 3023 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3024 | } else if (imm < 0 && magic > 0) { |
| 3025 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3026 | } |
| 3027 | |
| 3028 | if (shift != 0) { |
| 3029 | __ Asr(temp1, temp1, shift); |
| 3030 | } |
| 3031 | |
| 3032 | if (instruction->IsDiv()) { |
| 3033 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3034 | } else { |
| 3035 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3036 | // TODO: Strength reduction for mls. |
| 3037 | __ LoadImmediate(temp2, imm); |
| 3038 | __ mls(out, temp1, temp2, dividend); |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3043 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3044 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3045 | |
| 3046 | LocationSummary* locations = instruction->GetLocations(); |
| 3047 | Location second = locations->InAt(1); |
| 3048 | DCHECK(second.IsConstant()); |
| 3049 | |
| 3050 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3051 | if (imm == 0) { |
| 3052 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3053 | } else if (imm == 1 || imm == -1) { |
| 3054 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3055 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3056 | DivRemByPowerOfTwo(instruction); |
| 3057 | } else { |
| 3058 | DCHECK(imm <= -2 || imm >= 2); |
| 3059 | GenerateDivRemWithAnyConstant(instruction); |
| 3060 | } |
| 3061 | } |
| 3062 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3063 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3064 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3065 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3066 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3067 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3068 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3069 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3070 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3071 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3072 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3073 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3076 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3077 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3078 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3079 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3080 | if (div->InputAt(1)->IsConstant()) { |
| 3081 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3082 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3083 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3084 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3085 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3086 | // No temp register required. |
| 3087 | } else { |
| 3088 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3089 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3090 | locations->AddTemp(Location::RequiresRegister()); |
| 3091 | } |
| 3092 | } |
| 3093 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3094 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3095 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3096 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3097 | } else { |
| 3098 | InvokeRuntimeCallingConvention calling_convention; |
| 3099 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3100 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3101 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3102 | // we only need the former. |
| 3103 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3104 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3105 | break; |
| 3106 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3107 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3108 | InvokeRuntimeCallingConvention calling_convention; |
| 3109 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3110 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3111 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3112 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3113 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3114 | break; |
| 3115 | } |
| 3116 | case Primitive::kPrimFloat: |
| 3117 | case Primitive::kPrimDouble: { |
| 3118 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3119 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3120 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3121 | break; |
| 3122 | } |
| 3123 | |
| 3124 | default: |
| 3125 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3130 | LocationSummary* locations = div->GetLocations(); |
| 3131 | Location out = locations->Out(); |
| 3132 | Location first = locations->InAt(0); |
| 3133 | Location second = locations->InAt(1); |
| 3134 | |
| 3135 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3136 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3137 | if (second.IsConstant()) { |
| 3138 | GenerateDivRemConstantIntegral(div); |
| 3139 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3140 | __ sdiv(out.AsRegister<Register>(), |
| 3141 | first.AsRegister<Register>(), |
| 3142 | second.AsRegister<Register>()); |
| 3143 | } else { |
| 3144 | InvokeRuntimeCallingConvention calling_convention; |
| 3145 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3146 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3147 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3148 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3149 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3150 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3151 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3155 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3156 | InvokeRuntimeCallingConvention calling_convention; |
| 3157 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3158 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3159 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3160 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3161 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3162 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3163 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3164 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3165 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3166 | break; |
| 3167 | } |
| 3168 | |
| 3169 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3170 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3171 | first.AsFpuRegister<SRegister>(), |
| 3172 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3173 | break; |
| 3174 | } |
| 3175 | |
| 3176 | case Primitive::kPrimDouble: { |
| 3177 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3178 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3179 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3180 | break; |
| 3181 | } |
| 3182 | |
| 3183 | default: |
| 3184 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3185 | } |
| 3186 | } |
| 3187 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3188 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3189 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3190 | |
| 3191 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3192 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3193 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3194 | // sdiv will be replaced by other instruction sequence. |
| 3195 | call_kind = LocationSummary::kNoCall; |
| 3196 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3197 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3198 | // Have hardware divide instruction for int, do it with three instructions. |
| 3199 | call_kind = LocationSummary::kNoCall; |
| 3200 | } |
| 3201 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3202 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3203 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3204 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3205 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3206 | if (rem->InputAt(1)->IsConstant()) { |
| 3207 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3208 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3209 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3210 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3211 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3212 | // No temp register required. |
| 3213 | } else { |
| 3214 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3215 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3216 | locations->AddTemp(Location::RequiresRegister()); |
| 3217 | } |
| 3218 | } |
| 3219 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3220 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3221 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3222 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3223 | locations->AddTemp(Location::RequiresRegister()); |
| 3224 | } else { |
| 3225 | InvokeRuntimeCallingConvention calling_convention; |
| 3226 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3227 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3228 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3229 | // we only need the latter. |
| 3230 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3231 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3232 | break; |
| 3233 | } |
| 3234 | case Primitive::kPrimLong: { |
| 3235 | InvokeRuntimeCallingConvention calling_convention; |
| 3236 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3237 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3238 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3239 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3240 | // The runtime helper puts the output in R2,R3. |
| 3241 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3242 | break; |
| 3243 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3244 | case Primitive::kPrimFloat: { |
| 3245 | InvokeRuntimeCallingConvention calling_convention; |
| 3246 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3247 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3248 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3249 | break; |
| 3250 | } |
| 3251 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3252 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3253 | InvokeRuntimeCallingConvention calling_convention; |
| 3254 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3255 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3256 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3257 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3258 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | } |
| 3261 | |
| 3262 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3263 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3268 | LocationSummary* locations = rem->GetLocations(); |
| 3269 | Location out = locations->Out(); |
| 3270 | Location first = locations->InAt(0); |
| 3271 | Location second = locations->InAt(1); |
| 3272 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3273 | Primitive::Type type = rem->GetResultType(); |
| 3274 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3275 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3276 | if (second.IsConstant()) { |
| 3277 | GenerateDivRemConstantIntegral(rem); |
| 3278 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3279 | Register reg1 = first.AsRegister<Register>(); |
| 3280 | Register reg2 = second.AsRegister<Register>(); |
| 3281 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3282 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3283 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3284 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3285 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3286 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3287 | } else { |
| 3288 | InvokeRuntimeCallingConvention calling_convention; |
| 3289 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3290 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3291 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3292 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3293 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3294 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3295 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3300 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3301 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3302 | break; |
| 3303 | } |
| 3304 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3305 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3306 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3307 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3308 | break; |
| 3309 | } |
| 3310 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3311 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3312 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3313 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3314 | break; |
| 3315 | } |
| 3316 | |
| 3317 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3318 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3319 | } |
| 3320 | } |
| 3321 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3322 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3323 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3324 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3328 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3329 | codegen_->AddSlowPath(slow_path); |
| 3330 | |
| 3331 | LocationSummary* locations = instruction->GetLocations(); |
| 3332 | Location value = locations->InAt(0); |
| 3333 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3334 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3335 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3336 | case Primitive::kPrimByte: |
| 3337 | case Primitive::kPrimChar: |
| 3338 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3339 | case Primitive::kPrimInt: { |
| 3340 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3341 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3342 | } else { |
| 3343 | DCHECK(value.IsConstant()) << value; |
| 3344 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3345 | __ b(slow_path->GetEntryLabel()); |
| 3346 | } |
| 3347 | } |
| 3348 | break; |
| 3349 | } |
| 3350 | case Primitive::kPrimLong: { |
| 3351 | if (value.IsRegisterPair()) { |
| 3352 | __ orrs(IP, |
| 3353 | value.AsRegisterPairLow<Register>(), |
| 3354 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3355 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3356 | } else { |
| 3357 | DCHECK(value.IsConstant()) << value; |
| 3358 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3359 | __ b(slow_path->GetEntryLabel()); |
| 3360 | } |
| 3361 | } |
| 3362 | break; |
| 3363 | default: |
| 3364 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3365 | } |
| 3366 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3369 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3370 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3371 | Location rhs = locations->InAt(1); |
| 3372 | Register out = locations->Out().AsRegister<Register>(); |
| 3373 | |
| 3374 | if (rhs.IsConstant()) { |
| 3375 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3376 | // so map all rotations to a +ve. equivalent in that range. |
| 3377 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3378 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3379 | if (rot) { |
| 3380 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3381 | // (e.g. left by 2 bits == right by 30.) |
| 3382 | __ Ror(out, in, rot); |
| 3383 | } else if (out != in) { |
| 3384 | __ Mov(out, in); |
| 3385 | } |
| 3386 | } else { |
| 3387 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3392 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3393 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3394 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3395 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3396 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3397 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3398 | Location rhs = locations->InAt(1); |
| 3399 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3400 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3401 | |
| 3402 | if (rhs.IsConstant()) { |
| 3403 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3404 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3405 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3406 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3407 | // logic below to a simple pair of binary orr. |
| 3408 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3409 | if (rot >= kArmBitsPerWord) { |
| 3410 | rot -= kArmBitsPerWord; |
| 3411 | std::swap(in_reg_hi, in_reg_lo); |
| 3412 | } |
| 3413 | // Rotate, or mov to out for zero or word size rotations. |
| 3414 | if (rot != 0u) { |
| 3415 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3416 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3417 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3418 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3419 | } else { |
| 3420 | __ Mov(out_reg_lo, in_reg_lo); |
| 3421 | __ Mov(out_reg_hi, in_reg_hi); |
| 3422 | } |
| 3423 | } else { |
| 3424 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3425 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3426 | Label end; |
| 3427 | Label shift_by_32_plus_shift_right; |
| 3428 | |
| 3429 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3430 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3431 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3432 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3433 | |
| 3434 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3435 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3436 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3437 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3438 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3439 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3440 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3441 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3442 | __ b(&end); |
| 3443 | |
| 3444 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3445 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3446 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3447 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3448 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3449 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3450 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3451 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3452 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3453 | |
| 3454 | __ Bind(&end); |
| 3455 | } |
| 3456 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3457 | |
| 3458 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3459 | LocationSummary* locations = |
| 3460 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3461 | switch (ror->GetResultType()) { |
| 3462 | case Primitive::kPrimInt: { |
| 3463 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3464 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3465 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3466 | break; |
| 3467 | } |
| 3468 | case Primitive::kPrimLong: { |
| 3469 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3470 | if (ror->InputAt(1)->IsConstant()) { |
| 3471 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3472 | } else { |
| 3473 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3474 | locations->AddTemp(Location::RequiresRegister()); |
| 3475 | locations->AddTemp(Location::RequiresRegister()); |
| 3476 | } |
| 3477 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3478 | break; |
| 3479 | } |
| 3480 | default: |
| 3481 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3482 | } |
| 3483 | } |
| 3484 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3485 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3486 | LocationSummary* locations = ror->GetLocations(); |
| 3487 | Primitive::Type type = ror->GetResultType(); |
| 3488 | switch (type) { |
| 3489 | case Primitive::kPrimInt: { |
| 3490 | HandleIntegerRotate(locations); |
| 3491 | break; |
| 3492 | } |
| 3493 | case Primitive::kPrimLong: { |
| 3494 | HandleLongRotate(locations); |
| 3495 | break; |
| 3496 | } |
| 3497 | default: |
| 3498 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3499 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3503 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3504 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3505 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3506 | LocationSummary* locations = |
| 3507 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3508 | |
| 3509 | switch (op->GetResultType()) { |
| 3510 | case Primitive::kPrimInt: { |
| 3511 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3512 | if (op->InputAt(1)->IsConstant()) { |
| 3513 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3514 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3515 | } else { |
| 3516 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3517 | // Make the output overlap, as it will be used to hold the masked |
| 3518 | // second input. |
| 3519 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3520 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3521 | break; |
| 3522 | } |
| 3523 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3524 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3525 | if (op->InputAt(1)->IsConstant()) { |
| 3526 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3527 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3528 | // don't clash with high registers which the register allocator currently guarantees. |
| 3529 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3530 | } else { |
| 3531 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3532 | locations->AddTemp(Location::RequiresRegister()); |
| 3533 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3534 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3535 | break; |
| 3536 | } |
| 3537 | default: |
| 3538 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3543 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3544 | |
| 3545 | LocationSummary* locations = op->GetLocations(); |
| 3546 | Location out = locations->Out(); |
| 3547 | Location first = locations->InAt(0); |
| 3548 | Location second = locations->InAt(1); |
| 3549 | |
| 3550 | Primitive::Type type = op->GetResultType(); |
| 3551 | switch (type) { |
| 3552 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3553 | Register out_reg = out.AsRegister<Register>(); |
| 3554 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3555 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3556 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3557 | // 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] | 3558 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3559 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3560 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3561 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3562 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3563 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3564 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3565 | } |
| 3566 | } else { |
| 3567 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3568 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3569 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3570 | __ Mov(out_reg, first_reg); |
| 3571 | } else if (op->IsShl()) { |
| 3572 | __ Lsl(out_reg, first_reg, shift_value); |
| 3573 | } else if (op->IsShr()) { |
| 3574 | __ Asr(out_reg, first_reg, shift_value); |
| 3575 | } else { |
| 3576 | __ Lsr(out_reg, first_reg, shift_value); |
| 3577 | } |
| 3578 | } |
| 3579 | break; |
| 3580 | } |
| 3581 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3582 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3583 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3584 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3585 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3586 | Register low = first.AsRegisterPairLow<Register>(); |
| 3587 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3588 | if (second.IsRegister()) { |
| 3589 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3590 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3591 | Register second_reg = second.AsRegister<Register>(); |
| 3592 | |
| 3593 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3594 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3595 | // Shift the high part |
| 3596 | __ Lsl(o_h, high, o_l); |
| 3597 | // Shift the low part and `or` what overflew on the high part |
| 3598 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3599 | __ Lsr(temp, low, temp); |
| 3600 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3601 | // If the shift is > 32 bits, override the high part |
| 3602 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3603 | __ it(PL); |
| 3604 | __ Lsl(o_h, low, temp, PL); |
| 3605 | // Shift the low part |
| 3606 | __ Lsl(o_l, low, o_l); |
| 3607 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3608 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3609 | // Shift the low part |
| 3610 | __ Lsr(o_l, low, o_h); |
| 3611 | // Shift the high part and `or` what underflew on the low part |
| 3612 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3613 | __ Lsl(temp, high, temp); |
| 3614 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3615 | // If the shift is > 32 bits, override the low part |
| 3616 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3617 | __ it(PL); |
| 3618 | __ Asr(o_l, high, temp, PL); |
| 3619 | // Shift the high part |
| 3620 | __ Asr(o_h, high, o_h); |
| 3621 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3622 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3623 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3624 | __ Lsr(o_l, low, o_h); |
| 3625 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3626 | __ Lsl(temp, high, temp); |
| 3627 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3628 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3629 | __ it(PL); |
| 3630 | __ Lsr(o_l, high, temp, PL); |
| 3631 | __ Lsr(o_h, high, o_h); |
| 3632 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3633 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3634 | // Register allocator doesn't create partial overlap. |
| 3635 | DCHECK_NE(o_l, high); |
| 3636 | DCHECK_NE(o_h, low); |
| 3637 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3638 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3639 | if (shift_value > 32) { |
| 3640 | if (op->IsShl()) { |
| 3641 | __ Lsl(o_h, low, shift_value - 32); |
| 3642 | __ LoadImmediate(o_l, 0); |
| 3643 | } else if (op->IsShr()) { |
| 3644 | __ Asr(o_l, high, shift_value - 32); |
| 3645 | __ Asr(o_h, high, 31); |
| 3646 | } else { |
| 3647 | __ Lsr(o_l, high, shift_value - 32); |
| 3648 | __ LoadImmediate(o_h, 0); |
| 3649 | } |
| 3650 | } else if (shift_value == 32) { |
| 3651 | if (op->IsShl()) { |
| 3652 | __ mov(o_h, ShifterOperand(low)); |
| 3653 | __ LoadImmediate(o_l, 0); |
| 3654 | } else if (op->IsShr()) { |
| 3655 | __ mov(o_l, ShifterOperand(high)); |
| 3656 | __ Asr(o_h, high, 31); |
| 3657 | } else { |
| 3658 | __ mov(o_l, ShifterOperand(high)); |
| 3659 | __ LoadImmediate(o_h, 0); |
| 3660 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3661 | } else if (shift_value == 1) { |
| 3662 | if (op->IsShl()) { |
| 3663 | __ Lsls(o_l, low, 1); |
| 3664 | __ adc(o_h, high, ShifterOperand(high)); |
| 3665 | } else if (op->IsShr()) { |
| 3666 | __ Asrs(o_h, high, 1); |
| 3667 | __ Rrx(o_l, low); |
| 3668 | } else { |
| 3669 | __ Lsrs(o_h, high, 1); |
| 3670 | __ Rrx(o_l, low); |
| 3671 | } |
| 3672 | } else { |
| 3673 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3674 | if (op->IsShl()) { |
| 3675 | __ Lsl(o_h, high, shift_value); |
| 3676 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3677 | __ Lsl(o_l, low, shift_value); |
| 3678 | } else if (op->IsShr()) { |
| 3679 | __ Lsr(o_l, low, shift_value); |
| 3680 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3681 | __ Asr(o_h, high, shift_value); |
| 3682 | } else { |
| 3683 | __ Lsr(o_l, low, shift_value); |
| 3684 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3685 | __ Lsr(o_h, high, shift_value); |
| 3686 | } |
| 3687 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3688 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | } |
| 3691 | default: |
| 3692 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3693 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3698 | HandleShift(shl); |
| 3699 | } |
| 3700 | |
| 3701 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3702 | HandleShift(shl); |
| 3703 | } |
| 3704 | |
| 3705 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3706 | HandleShift(shr); |
| 3707 | } |
| 3708 | |
| 3709 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3710 | HandleShift(shr); |
| 3711 | } |
| 3712 | |
| 3713 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3714 | HandleShift(ushr); |
| 3715 | } |
| 3716 | |
| 3717 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3718 | HandleShift(ushr); |
| 3719 | } |
| 3720 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3721 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3722 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3723 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3724 | if (instruction->IsStringAlloc()) { |
| 3725 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3726 | } else { |
| 3727 | InvokeRuntimeCallingConvention calling_convention; |
| 3728 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3729 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3730 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3731 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3735 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3736 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3737 | if (instruction->IsStringAlloc()) { |
| 3738 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3739 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3740 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3741 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3742 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3743 | __ blx(LR); |
| 3744 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3745 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3746 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3747 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3748 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3751 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3752 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3753 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3754 | InvokeRuntimeCallingConvention calling_convention; |
| 3755 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3756 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3757 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3758 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3762 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3763 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3764 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3765 | // of poisoning the reference. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3766 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3767 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3768 | } |
| 3769 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3770 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3771 | LocationSummary* locations = |
| 3772 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3773 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3774 | if (location.IsStackSlot()) { |
| 3775 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3776 | } else if (location.IsDoubleStackSlot()) { |
| 3777 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3778 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3779 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3780 | } |
| 3781 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3782 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3783 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3784 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3788 | LocationSummary* locations = |
| 3789 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3790 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3791 | } |
| 3792 | |
| 3793 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3794 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3795 | } |
| 3796 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3797 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3798 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3799 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3800 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3801 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3802 | } |
| 3803 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3804 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3805 | LocationSummary* locations = not_->GetLocations(); |
| 3806 | Location out = locations->Out(); |
| 3807 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3808 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3809 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3810 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3811 | break; |
| 3812 | |
| 3813 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3814 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3815 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3816 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3817 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3818 | break; |
| 3819 | |
| 3820 | default: |
| 3821 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3822 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3823 | } |
| 3824 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3825 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3826 | LocationSummary* locations = |
| 3827 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3828 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3829 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3830 | } |
| 3831 | |
| 3832 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3833 | LocationSummary* locations = bool_not->GetLocations(); |
| 3834 | Location out = locations->Out(); |
| 3835 | Location in = locations->InAt(0); |
| 3836 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3837 | } |
| 3838 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3839 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3840 | LocationSummary* locations = |
| 3841 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3842 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3843 | case Primitive::kPrimBoolean: |
| 3844 | case Primitive::kPrimByte: |
| 3845 | case Primitive::kPrimShort: |
| 3846 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3847 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3848 | case Primitive::kPrimLong: { |
| 3849 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3850 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3851 | // Output overlaps because it is written before doing the low comparison. |
| 3852 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3853 | break; |
| 3854 | } |
| 3855 | case Primitive::kPrimFloat: |
| 3856 | case Primitive::kPrimDouble: { |
| 3857 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3858 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3859 | locations->SetOut(Location::RequiresRegister()); |
| 3860 | break; |
| 3861 | } |
| 3862 | default: |
| 3863 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3864 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3868 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3869 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3870 | Location left = locations->InAt(0); |
| 3871 | Location right = locations->InAt(1); |
| 3872 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3873 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3874 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3875 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3876 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3877 | case Primitive::kPrimBoolean: |
| 3878 | case Primitive::kPrimByte: |
| 3879 | case Primitive::kPrimShort: |
| 3880 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3881 | case Primitive::kPrimInt: { |
| 3882 | __ LoadImmediate(out, 0); |
| 3883 | __ cmp(left.AsRegister<Register>(), |
| 3884 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3885 | less_cond = LT; |
| 3886 | break; |
| 3887 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3888 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3889 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3890 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3891 | __ b(&less, LT); |
| 3892 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3893 | // 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] | 3894 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3895 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3896 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3897 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3898 | break; |
| 3899 | } |
| 3900 | case Primitive::kPrimFloat: |
| 3901 | case Primitive::kPrimDouble: { |
| 3902 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3903 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3904 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3905 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3906 | break; |
| 3907 | } |
| 3908 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3909 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3910 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3911 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3912 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3913 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3914 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3915 | |
| 3916 | __ Bind(&greater); |
| 3917 | __ LoadImmediate(out, 1); |
| 3918 | __ b(&done); |
| 3919 | |
| 3920 | __ Bind(&less); |
| 3921 | __ LoadImmediate(out, -1); |
| 3922 | |
| 3923 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3924 | } |
| 3925 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3926 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3927 | LocationSummary* locations = |
| 3928 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3929 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3930 | locations->SetInAt(i, Location::Any()); |
| 3931 | } |
| 3932 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3933 | } |
| 3934 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3935 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3936 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3937 | } |
| 3938 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3939 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3940 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3941 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3942 | switch (kind) { |
| 3943 | case MemBarrierKind::kAnyStore: |
| 3944 | case MemBarrierKind::kLoadAny: |
| 3945 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3946 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3947 | break; |
| 3948 | } |
| 3949 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3950 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3951 | break; |
| 3952 | } |
| 3953 | default: |
| 3954 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3955 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3956 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3960 | uint32_t offset, |
| 3961 | Register out_lo, |
| 3962 | Register out_hi) { |
| 3963 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3964 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3965 | // `offset` into `out_lo` does not clutter `addr`. |
| 3966 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3967 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3968 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3969 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3970 | } |
| 3971 | __ ldrexd(out_lo, out_hi, addr); |
| 3972 | } |
| 3973 | |
| 3974 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3975 | uint32_t offset, |
| 3976 | Register value_lo, |
| 3977 | Register value_hi, |
| 3978 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3979 | Register temp2, |
| 3980 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3981 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3982 | if (offset != 0) { |
| 3983 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3984 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3985 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3986 | } |
| 3987 | __ Bind(&fail); |
| 3988 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3989 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3990 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3991 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3992 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3993 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3997 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3998 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3999 | LocationSummary* locations = |
| 4000 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4001 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4002 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4003 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4004 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4005 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4006 | } else { |
| 4007 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4008 | } |
| 4009 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4010 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4011 | bool generate_volatile = field_info.IsVolatile() |
| 4012 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4013 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4014 | bool needs_write_barrier = |
| 4015 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4016 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4017 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4018 | if (needs_write_barrier) { |
| 4019 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4020 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4021 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4022 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4023 | // - registers need to be consecutive |
| 4024 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4025 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4026 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4027 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4028 | |
| 4029 | locations->AddTemp(Location::RequiresRegister()); |
| 4030 | locations->AddTemp(Location::RequiresRegister()); |
| 4031 | if (field_type == Primitive::kPrimDouble) { |
| 4032 | // For doubles we need two more registers to copy the value. |
| 4033 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4034 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4035 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4036 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4037 | } |
| 4038 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4039 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4040 | const FieldInfo& field_info, |
| 4041 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4042 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4043 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4044 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4045 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4046 | Location value = locations->InAt(1); |
| 4047 | |
| 4048 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4049 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4050 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4051 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4052 | bool needs_write_barrier = |
| 4053 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4054 | |
| 4055 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4056 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4057 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4058 | |
| 4059 | switch (field_type) { |
| 4060 | case Primitive::kPrimBoolean: |
| 4061 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4062 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4063 | break; |
| 4064 | } |
| 4065 | |
| 4066 | case Primitive::kPrimShort: |
| 4067 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4068 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4069 | break; |
| 4070 | } |
| 4071 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4072 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4073 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4074 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4075 | // Note that in the case where `value` is a null reference, |
| 4076 | // we do not enter this block, as a null reference does not |
| 4077 | // need poisoning. |
| 4078 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4079 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4080 | __ Mov(temp, value.AsRegister<Register>()); |
| 4081 | __ PoisonHeapReference(temp); |
| 4082 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4083 | } else { |
| 4084 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4085 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4086 | break; |
| 4087 | } |
| 4088 | |
| 4089 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4090 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4091 | GenerateWideAtomicStore(base, offset, |
| 4092 | value.AsRegisterPairLow<Register>(), |
| 4093 | value.AsRegisterPairHigh<Register>(), |
| 4094 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4095 | locations->GetTemp(1).AsRegister<Register>(), |
| 4096 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4097 | } else { |
| 4098 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4099 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4100 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4101 | break; |
| 4102 | } |
| 4103 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4104 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4105 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4106 | break; |
| 4107 | } |
| 4108 | |
| 4109 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4110 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4111 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4112 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4113 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4114 | |
| 4115 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4116 | |
| 4117 | GenerateWideAtomicStore(base, offset, |
| 4118 | value_reg_lo, |
| 4119 | value_reg_hi, |
| 4120 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4121 | locations->GetTemp(3).AsRegister<Register>(), |
| 4122 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4123 | } else { |
| 4124 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4126 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4127 | break; |
| 4128 | } |
| 4129 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4130 | case Primitive::kPrimVoid: |
| 4131 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4132 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4133 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4134 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4135 | // Longs and doubles are handled in the switch. |
| 4136 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4137 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4138 | } |
| 4139 | |
| 4140 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4141 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4142 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4143 | codegen_->MarkGCCard( |
| 4144 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4147 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4148 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4149 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4150 | } |
| 4151 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4152 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4153 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4154 | |
| 4155 | bool object_field_get_with_read_barrier = |
| 4156 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4157 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4158 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4159 | object_field_get_with_read_barrier ? |
| 4160 | LocationSummary::kCallOnSlowPath : |
| 4161 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4162 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4163 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4164 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4165 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4166 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4167 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4168 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4169 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4170 | // The output overlaps in case of volatile long: we don't want the |
| 4171 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4172 | // object's location. Likewise, in the case of an object field get |
| 4173 | // with read barriers enabled, we do not want the load to overwrite |
| 4174 | // the object's location, as we need it to emit the read barrier. |
| 4175 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4176 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4177 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4178 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4179 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4180 | } else { |
| 4181 | locations->SetOut(Location::RequiresRegister(), |
| 4182 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4183 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4184 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4185 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4186 | // - registers need to be consecutive |
| 4187 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4188 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4189 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4190 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4191 | locations->AddTemp(Location::RequiresRegister()); |
| 4192 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4193 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4194 | // We need a temporary register for the read barrier marking slow |
| 4195 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4196 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4197 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4200 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4201 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4202 | << input->GetType(); |
| 4203 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4204 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4205 | return Location::ConstantLocation(input->AsConstant()); |
| 4206 | } else { |
| 4207 | return Location::RequiresFpuRegister(); |
| 4208 | } |
| 4209 | } |
| 4210 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4211 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4212 | Opcode opcode) { |
| 4213 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4214 | if (constant->IsConstant() && |
| 4215 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4216 | return Location::ConstantLocation(constant->AsConstant()); |
| 4217 | } |
| 4218 | return Location::RequiresRegister(); |
| 4219 | } |
| 4220 | |
| 4221 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4222 | Opcode opcode) { |
| 4223 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4224 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4225 | Opcode high_opcode = opcode; |
| 4226 | SetCc low_set_cc = kCcDontCare; |
| 4227 | switch (opcode) { |
| 4228 | case SUB: |
| 4229 | // Flip the operation to an ADD. |
| 4230 | value = -value; |
| 4231 | opcode = ADD; |
| 4232 | FALLTHROUGH_INTENDED; |
| 4233 | case ADD: |
| 4234 | if (Low32Bits(value) == 0u) { |
| 4235 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4236 | } |
| 4237 | high_opcode = ADC; |
| 4238 | low_set_cc = kCcSet; |
| 4239 | break; |
| 4240 | default: |
| 4241 | break; |
| 4242 | } |
| 4243 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4244 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4245 | } else { |
| 4246 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4247 | } |
| 4248 | } |
| 4249 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4250 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4251 | Opcode opcode, |
| 4252 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4253 | ShifterOperand so; |
| 4254 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4255 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4256 | return true; |
| 4257 | } |
| 4258 | Opcode neg_opcode = kNoOperand; |
| 4259 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4260 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4261 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4262 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4263 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4264 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4265 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4266 | default: |
| 4267 | return false; |
| 4268 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4269 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4272 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4273 | const FieldInfo& field_info) { |
| 4274 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4275 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4276 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4277 | Location base_loc = locations->InAt(0); |
| 4278 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4279 | Location out = locations->Out(); |
| 4280 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4281 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4283 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4284 | |
| 4285 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4286 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4287 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4288 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4289 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4290 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4291 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4292 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4293 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4294 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4295 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4296 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4297 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4298 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4299 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4300 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4301 | |
| 4302 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4303 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4304 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4305 | |
| 4306 | case Primitive::kPrimNot: { |
| 4307 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4308 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4309 | Location temp_loc = locations->GetTemp(0); |
| 4310 | // Note that a potential implicit null check is handled in this |
| 4311 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4312 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4313 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4314 | if (is_volatile) { |
| 4315 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4316 | } |
| 4317 | } else { |
| 4318 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4319 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4320 | if (is_volatile) { |
| 4321 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4322 | } |
| 4323 | // If read barriers are enabled, emit read barriers other than |
| 4324 | // Baker's using a slow path (and also unpoison the loaded |
| 4325 | // reference, if heap poisoning is enabled). |
| 4326 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4327 | } |
| 4328 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4329 | } |
| 4330 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4331 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4332 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4333 | GenerateWideAtomicLoad(base, offset, |
| 4334 | out.AsRegisterPairLow<Register>(), |
| 4335 | out.AsRegisterPairHigh<Register>()); |
| 4336 | } else { |
| 4337 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4338 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4339 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4340 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4341 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4342 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4343 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4344 | |
| 4345 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4346 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4347 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4348 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4349 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4350 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4351 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4352 | __ vmovdrr(out_reg, lo, hi); |
| 4353 | } else { |
| 4354 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4355 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4356 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4357 | break; |
| 4358 | } |
| 4359 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4360 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4361 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4362 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4363 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4364 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4365 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4366 | // Potential implicit null checks, in the case of reference or |
| 4367 | // double fields, are handled in the previous switch statement. |
| 4368 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4369 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4370 | } |
| 4371 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4372 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4373 | if (field_type == Primitive::kPrimNot) { |
| 4374 | // Memory barriers, in the case of references, are also handled |
| 4375 | // in the previous switch statement. |
| 4376 | } else { |
| 4377 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4378 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4379 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4383 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4384 | } |
| 4385 | |
| 4386 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4387 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4391 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4392 | } |
| 4393 | |
| 4394 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4395 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4396 | } |
| 4397 | |
| 4398 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4399 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4400 | } |
| 4401 | |
| 4402 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4403 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4404 | } |
| 4405 | |
| 4406 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4407 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4408 | } |
| 4409 | |
| 4410 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4411 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4414 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4415 | HUnresolvedInstanceFieldGet* instruction) { |
| 4416 | FieldAccessCallingConventionARM calling_convention; |
| 4417 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4418 | instruction, instruction->GetFieldType(), calling_convention); |
| 4419 | } |
| 4420 | |
| 4421 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4422 | HUnresolvedInstanceFieldGet* instruction) { |
| 4423 | FieldAccessCallingConventionARM calling_convention; |
| 4424 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4425 | instruction->GetFieldType(), |
| 4426 | instruction->GetFieldIndex(), |
| 4427 | instruction->GetDexPc(), |
| 4428 | calling_convention); |
| 4429 | } |
| 4430 | |
| 4431 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4432 | HUnresolvedInstanceFieldSet* instruction) { |
| 4433 | FieldAccessCallingConventionARM calling_convention; |
| 4434 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4435 | instruction, instruction->GetFieldType(), calling_convention); |
| 4436 | } |
| 4437 | |
| 4438 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4439 | HUnresolvedInstanceFieldSet* instruction) { |
| 4440 | FieldAccessCallingConventionARM calling_convention; |
| 4441 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4442 | instruction->GetFieldType(), |
| 4443 | instruction->GetFieldIndex(), |
| 4444 | instruction->GetDexPc(), |
| 4445 | calling_convention); |
| 4446 | } |
| 4447 | |
| 4448 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4449 | HUnresolvedStaticFieldGet* instruction) { |
| 4450 | FieldAccessCallingConventionARM calling_convention; |
| 4451 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4452 | instruction, instruction->GetFieldType(), calling_convention); |
| 4453 | } |
| 4454 | |
| 4455 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4456 | HUnresolvedStaticFieldGet* instruction) { |
| 4457 | FieldAccessCallingConventionARM calling_convention; |
| 4458 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4459 | instruction->GetFieldType(), |
| 4460 | instruction->GetFieldIndex(), |
| 4461 | instruction->GetDexPc(), |
| 4462 | calling_convention); |
| 4463 | } |
| 4464 | |
| 4465 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4466 | HUnresolvedStaticFieldSet* instruction) { |
| 4467 | FieldAccessCallingConventionARM calling_convention; |
| 4468 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4469 | instruction, instruction->GetFieldType(), calling_convention); |
| 4470 | } |
| 4471 | |
| 4472 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4473 | HUnresolvedStaticFieldSet* instruction) { |
| 4474 | FieldAccessCallingConventionARM calling_convention; |
| 4475 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4476 | instruction->GetFieldType(), |
| 4477 | instruction->GetFieldIndex(), |
| 4478 | instruction->GetDexPc(), |
| 4479 | calling_convention); |
| 4480 | } |
| 4481 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4482 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4483 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4484 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4487 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4488 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4489 | return; |
| 4490 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4491 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4492 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4493 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4494 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4497 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4498 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4499 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4500 | |
| 4501 | LocationSummary* locations = instruction->GetLocations(); |
| 4502 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4503 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4504 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4505 | } |
| 4506 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4507 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4508 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4509 | } |
| 4510 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4511 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4512 | switch (type) { |
| 4513 | case Primitive::kPrimNot: |
| 4514 | return kLoadWord; |
| 4515 | case Primitive::kPrimBoolean: |
| 4516 | return kLoadUnsignedByte; |
| 4517 | case Primitive::kPrimByte: |
| 4518 | return kLoadSignedByte; |
| 4519 | case Primitive::kPrimChar: |
| 4520 | return kLoadUnsignedHalfword; |
| 4521 | case Primitive::kPrimShort: |
| 4522 | return kLoadSignedHalfword; |
| 4523 | case Primitive::kPrimInt: |
| 4524 | return kLoadWord; |
| 4525 | case Primitive::kPrimLong: |
| 4526 | return kLoadWordPair; |
| 4527 | case Primitive::kPrimFloat: |
| 4528 | return kLoadSWord; |
| 4529 | case Primitive::kPrimDouble: |
| 4530 | return kLoadDWord; |
| 4531 | default: |
| 4532 | LOG(FATAL) << "Unreachable type " << type; |
| 4533 | UNREACHABLE(); |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4538 | switch (type) { |
| 4539 | case Primitive::kPrimNot: |
| 4540 | return kStoreWord; |
| 4541 | case Primitive::kPrimBoolean: |
| 4542 | case Primitive::kPrimByte: |
| 4543 | return kStoreByte; |
| 4544 | case Primitive::kPrimChar: |
| 4545 | case Primitive::kPrimShort: |
| 4546 | return kStoreHalfword; |
| 4547 | case Primitive::kPrimInt: |
| 4548 | return kStoreWord; |
| 4549 | case Primitive::kPrimLong: |
| 4550 | return kStoreWordPair; |
| 4551 | case Primitive::kPrimFloat: |
| 4552 | return kStoreSWord; |
| 4553 | case Primitive::kPrimDouble: |
| 4554 | return kStoreDWord; |
| 4555 | default: |
| 4556 | LOG(FATAL) << "Unreachable type " << type; |
| 4557 | UNREACHABLE(); |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4562 | Location out_loc, |
| 4563 | Register base, |
| 4564 | Register reg_offset, |
| 4565 | Condition cond) { |
| 4566 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4567 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4568 | |
| 4569 | switch (type) { |
| 4570 | case Primitive::kPrimByte: |
| 4571 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4572 | break; |
| 4573 | case Primitive::kPrimBoolean: |
| 4574 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4575 | break; |
| 4576 | case Primitive::kPrimShort: |
| 4577 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4578 | break; |
| 4579 | case Primitive::kPrimChar: |
| 4580 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4581 | break; |
| 4582 | case Primitive::kPrimNot: |
| 4583 | case Primitive::kPrimInt: |
| 4584 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4585 | break; |
| 4586 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4587 | case Primitive::kPrimLong: |
| 4588 | case Primitive::kPrimFloat: |
| 4589 | case Primitive::kPrimDouble: |
| 4590 | default: |
| 4591 | LOG(FATAL) << "Unreachable type " << type; |
| 4592 | UNREACHABLE(); |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4597 | Location loc, |
| 4598 | Register base, |
| 4599 | Register reg_offset, |
| 4600 | Condition cond) { |
| 4601 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4602 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4603 | |
| 4604 | switch (type) { |
| 4605 | case Primitive::kPrimByte: |
| 4606 | case Primitive::kPrimBoolean: |
| 4607 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4608 | break; |
| 4609 | case Primitive::kPrimShort: |
| 4610 | case Primitive::kPrimChar: |
| 4611 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4612 | break; |
| 4613 | case Primitive::kPrimNot: |
| 4614 | case Primitive::kPrimInt: |
| 4615 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4616 | break; |
| 4617 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4618 | case Primitive::kPrimLong: |
| 4619 | case Primitive::kPrimFloat: |
| 4620 | case Primitive::kPrimDouble: |
| 4621 | default: |
| 4622 | LOG(FATAL) << "Unreachable type " << type; |
| 4623 | UNREACHABLE(); |
| 4624 | } |
| 4625 | } |
| 4626 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4627 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4628 | bool object_array_get_with_read_barrier = |
| 4629 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4630 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4631 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4632 | object_array_get_with_read_barrier ? |
| 4633 | LocationSummary::kCallOnSlowPath : |
| 4634 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4635 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4636 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4637 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4639 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4640 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4641 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4642 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4643 | // The output overlaps in the case of an object array get with |
| 4644 | // read barriers enabled: we do not want the move to overwrite the |
| 4645 | // array's location, as we need it to emit the read barrier. |
| 4646 | locations->SetOut( |
| 4647 | Location::RequiresRegister(), |
| 4648 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4649 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4650 | // We need a temporary register for the read barrier marking slow |
| 4651 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4652 | // Also need for String compression feature. |
| 4653 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4654 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4655 | locations->AddTemp(Location::RequiresRegister()); |
| 4656 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4660 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4661 | Location obj_loc = locations->InAt(0); |
| 4662 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4663 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4664 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4665 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4666 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4667 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4668 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4669 | HInstruction* array_instr = instruction->GetArray(); |
| 4670 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4671 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4672 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4673 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4674 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4675 | case Primitive::kPrimBoolean: |
| 4676 | case Primitive::kPrimByte: |
| 4677 | case Primitive::kPrimShort: |
| 4678 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4679 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4680 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4681 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4682 | if (maybe_compressed_char_at) { |
| 4683 | Register length = IP; |
| 4684 | Label uncompressed_load, done; |
| 4685 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4686 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4687 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4688 | __ cmp(length, ShifterOperand(0)); |
| 4689 | __ b(&uncompressed_load, GE); |
| 4690 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4691 | out_loc.AsRegister<Register>(), |
| 4692 | obj, |
| 4693 | data_offset + const_index); |
| 4694 | __ b(&done); |
| 4695 | __ Bind(&uncompressed_load); |
| 4696 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4697 | out_loc.AsRegister<Register>(), |
| 4698 | obj, |
| 4699 | data_offset + (const_index << 1)); |
| 4700 | __ Bind(&done); |
| 4701 | } else { |
| 4702 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4703 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4704 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4705 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4706 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4707 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4708 | Register temp = IP; |
| 4709 | |
| 4710 | if (has_intermediate_address) { |
| 4711 | // We do not need to compute the intermediate address from the array: the |
| 4712 | // input instruction has done it already. See the comment in |
| 4713 | // `TryExtractArrayAccessAddress()`. |
| 4714 | if (kIsDebugBuild) { |
| 4715 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4716 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4717 | } |
| 4718 | temp = obj; |
| 4719 | } else { |
| 4720 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4721 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4722 | if (maybe_compressed_char_at) { |
| 4723 | Label uncompressed_load, done; |
| 4724 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4725 | Register length = locations->GetTemp(0).AsRegister<Register>(); |
| 4726 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4727 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4728 | __ cmp(length, ShifterOperand(0)); |
| 4729 | __ b(&uncompressed_load, GE); |
| 4730 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4731 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4732 | __ b(&done); |
| 4733 | __ Bind(&uncompressed_load); |
| 4734 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4735 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4736 | __ Bind(&done); |
| 4737 | } else { |
| 4738 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4739 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4740 | } |
| 4741 | break; |
| 4742 | } |
| 4743 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4744 | case Primitive::kPrimNot: { |
| 4745 | static_assert( |
| 4746 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4747 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4748 | // /* HeapReference<Object> */ out = |
| 4749 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4750 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4751 | Location temp = locations->GetTemp(0); |
| 4752 | // Note that a potential implicit null check is handled in this |
| 4753 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4754 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4755 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4756 | } else { |
| 4757 | Register out = out_loc.AsRegister<Register>(); |
| 4758 | if (index.IsConstant()) { |
| 4759 | size_t offset = |
| 4760 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4761 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4762 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4763 | // If read barriers are enabled, emit read barriers other than |
| 4764 | // Baker's using a slow path (and also unpoison the loaded |
| 4765 | // reference, if heap poisoning is enabled). |
| 4766 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4767 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4768 | Register temp = IP; |
| 4769 | |
| 4770 | if (has_intermediate_address) { |
| 4771 | // We do not need to compute the intermediate address from the array: the |
| 4772 | // input instruction has done it already. See the comment in |
| 4773 | // `TryExtractArrayAccessAddress()`. |
| 4774 | if (kIsDebugBuild) { |
| 4775 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4776 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4777 | } |
| 4778 | temp = obj; |
| 4779 | } else { |
| 4780 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4781 | } |
| 4782 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4783 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4784 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4785 | // If read barriers are enabled, emit read barriers other than |
| 4786 | // Baker's using a slow path (and also unpoison the loaded |
| 4787 | // reference, if heap poisoning is enabled). |
| 4788 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4789 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4790 | } |
| 4791 | } |
| 4792 | break; |
| 4793 | } |
| 4794 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4795 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4796 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4797 | size_t offset = |
| 4798 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4799 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4800 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4801 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4802 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4803 | } |
| 4804 | break; |
| 4805 | } |
| 4806 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4807 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4808 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4809 | if (index.IsConstant()) { |
| 4810 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4811 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4812 | } else { |
| 4813 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4814 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4815 | } |
| 4816 | break; |
| 4817 | } |
| 4818 | |
| 4819 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4820 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4821 | if (index.IsConstant()) { |
| 4822 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4823 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4824 | } else { |
| 4825 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4826 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4827 | } |
| 4828 | break; |
| 4829 | } |
| 4830 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4831 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4832 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4833 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4834 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4835 | |
| 4836 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4837 | // Potential implicit null checks, in the case of reference |
| 4838 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4839 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4840 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4841 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4845 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4846 | |
| 4847 | bool needs_write_barrier = |
| 4848 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4849 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4850 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4851 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4852 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4853 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4854 | LocationSummary::kCallOnSlowPath : |
| 4855 | LocationSummary::kNoCall); |
| 4856 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4857 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4858 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4859 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4860 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4861 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4862 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4863 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4864 | if (needs_write_barrier) { |
| 4865 | // Temporary registers for the write barrier. |
| 4866 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4867 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4868 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4872 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4873 | Location array_loc = locations->InAt(0); |
| 4874 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4875 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4876 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4877 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4878 | bool needs_write_barrier = |
| 4879 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4880 | uint32_t data_offset = |
| 4881 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 4882 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4883 | HInstruction* array_instr = instruction->GetArray(); |
| 4884 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4885 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4886 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4887 | |
| 4888 | switch (value_type) { |
| 4889 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4890 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4891 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4892 | case Primitive::kPrimChar: |
| 4893 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4894 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4895 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4896 | uint32_t full_offset = |
| 4897 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 4898 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 4899 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4900 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4901 | Register temp = IP; |
| 4902 | |
| 4903 | if (has_intermediate_address) { |
| 4904 | // We do not need to compute the intermediate address from the array: the |
| 4905 | // input instruction has done it already. See the comment in |
| 4906 | // `TryExtractArrayAccessAddress()`. |
| 4907 | if (kIsDebugBuild) { |
| 4908 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4909 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 4910 | } |
| 4911 | temp = array; |
| 4912 | } else { |
| 4913 | __ add(temp, array, ShifterOperand(data_offset)); |
| 4914 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4915 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4916 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4917 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4918 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4919 | } |
| 4920 | break; |
| 4921 | } |
| 4922 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4923 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4924 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4925 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 4926 | // See the comment in instruction_simplifier_shared.cc. |
| 4927 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4928 | |
| 4929 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4930 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4931 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4932 | size_t offset = |
| 4933 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4934 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4935 | } else { |
| 4936 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4937 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4938 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4939 | value_loc, |
| 4940 | IP, |
| 4941 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4942 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4943 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4944 | DCHECK(!needs_write_barrier); |
| 4945 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4946 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4947 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4948 | |
| 4949 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4950 | Location temp1_loc = locations->GetTemp(0); |
| 4951 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 4952 | Location temp2_loc = locations->GetTemp(1); |
| 4953 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4954 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4955 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4956 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4957 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4958 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4959 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4960 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4961 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4962 | codegen_->AddSlowPath(slow_path); |
| 4963 | if (instruction->GetValueCanBeNull()) { |
| 4964 | Label non_zero; |
| 4965 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4966 | if (index.IsConstant()) { |
| 4967 | size_t offset = |
| 4968 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4969 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4970 | } else { |
| 4971 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4972 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4973 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4974 | value_loc, |
| 4975 | IP, |
| 4976 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4977 | } |
| 4978 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4979 | __ b(&done); |
| 4980 | __ Bind(&non_zero); |
| 4981 | } |
| 4982 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4983 | // Note that when read barriers are enabled, the type checks |
| 4984 | // are performed without read barriers. This is fine, even in |
| 4985 | // the case where a class object is in the from-space after |
| 4986 | // the flip, as a comparison involving such a type would not |
| 4987 | // produce a false positive; it may of course produce a false |
| 4988 | // negative, in which case we would take the ArraySet slow |
| 4989 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4990 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4991 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4992 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4993 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4994 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4995 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4996 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4997 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4998 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4999 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5000 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5001 | // nor `temp2`, as we are comparing two poisoned references. |
| 5002 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5003 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5004 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5005 | Label do_put; |
| 5006 | __ b(&do_put, EQ); |
| 5007 | // If heap poisoning is enabled, the `temp1` reference has |
| 5008 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5009 | __ MaybeUnpoisonHeapReference(temp1); |
| 5010 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5011 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5012 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5013 | // If heap poisoning is enabled, no need to unpoison |
| 5014 | // `temp1`, as we are comparing against null below. |
| 5015 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5016 | __ Bind(&do_put); |
| 5017 | } else { |
| 5018 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5019 | } |
| 5020 | } |
| 5021 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5022 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5023 | if (kPoisonHeapReferences) { |
| 5024 | // Note that in the case where `value` is a null reference, |
| 5025 | // we do not enter this block, as a null reference does not |
| 5026 | // need poisoning. |
| 5027 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5028 | __ Mov(temp1, value); |
| 5029 | __ PoisonHeapReference(temp1); |
| 5030 | source = temp1; |
| 5031 | } |
| 5032 | |
| 5033 | if (index.IsConstant()) { |
| 5034 | size_t offset = |
| 5035 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5036 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5037 | } else { |
| 5038 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5039 | |
| 5040 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5041 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5042 | Location::RegisterLocation(source), |
| 5043 | IP, |
| 5044 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5047 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5048 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5049 | } |
| 5050 | |
| 5051 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5052 | |
| 5053 | if (done.IsLinked()) { |
| 5054 | __ Bind(&done); |
| 5055 | } |
| 5056 | |
| 5057 | if (slow_path != nullptr) { |
| 5058 | __ Bind(slow_path->GetExitLabel()); |
| 5059 | } |
| 5060 | |
| 5061 | break; |
| 5062 | } |
| 5063 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5064 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5065 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5067 | size_t offset = |
| 5068 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5069 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5070 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5071 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5072 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5073 | } |
| 5074 | break; |
| 5075 | } |
| 5076 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5077 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5078 | Location value = locations->InAt(2); |
| 5079 | DCHECK(value.IsFpuRegister()); |
| 5080 | if (index.IsConstant()) { |
| 5081 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5082 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5083 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5084 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5085 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5086 | } |
| 5087 | break; |
| 5088 | } |
| 5089 | |
| 5090 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5091 | Location value = locations->InAt(2); |
| 5092 | DCHECK(value.IsFpuRegisterPair()); |
| 5093 | if (index.IsConstant()) { |
| 5094 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5095 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5096 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5097 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5098 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5099 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5100 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5101 | break; |
| 5102 | } |
| 5103 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5105 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5106 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5107 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5108 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5109 | // Objects are handled in the switch. |
| 5110 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5111 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5112 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5116 | LocationSummary* locations = |
| 5117 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5118 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5119 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5123 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5124 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5125 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5126 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5128 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5129 | // Mask out compression flag from String's array length. |
| 5130 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5131 | __ bic(out, out, ShifterOperand(1u << 31)); |
| 5132 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | } |
| 5134 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5135 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5136 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5137 | DCHECK(!kEmitCompilerReadBarrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5138 | LocationSummary* locations = |
| 5139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5140 | |
| 5141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5142 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5143 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5144 | } |
| 5145 | |
| 5146 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5147 | LocationSummary* locations = instruction->GetLocations(); |
| 5148 | Location out = locations->Out(); |
| 5149 | Location first = locations->InAt(0); |
| 5150 | Location second = locations->InAt(1); |
| 5151 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5152 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5153 | DCHECK(!kEmitCompilerReadBarrier); |
| 5154 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5155 | if (second.IsRegister()) { |
| 5156 | __ add(out.AsRegister<Register>(), |
| 5157 | first.AsRegister<Register>(), |
| 5158 | ShifterOperand(second.AsRegister<Register>())); |
| 5159 | } else { |
| 5160 | __ AddConstant(out.AsRegister<Register>(), |
| 5161 | first.AsRegister<Register>(), |
| 5162 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5163 | } |
| 5164 | } |
| 5165 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5166 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5167 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5168 | InvokeRuntimeCallingConvention calling_convention; |
| 5169 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5170 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5171 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5172 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5173 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5177 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5178 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5179 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5180 | codegen_->AddSlowPath(slow_path); |
| 5181 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5182 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5183 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5184 | |
| 5185 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5186 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5187 | } |
| 5188 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5189 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5190 | Register card, |
| 5191 | Register object, |
| 5192 | Register value, |
| 5193 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5194 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5195 | if (can_be_null) { |
| 5196 | __ CompareAndBranchIfZero(value, &is_null); |
| 5197 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5198 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5199 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5200 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5201 | if (can_be_null) { |
| 5202 | __ Bind(&is_null); |
| 5203 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5204 | } |
| 5205 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5206 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5207 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5211 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5212 | } |
| 5213 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5214 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5215 | LocationSummary* locations = |
| 5216 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5217 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5221 | HBasicBlock* block = instruction->GetBlock(); |
| 5222 | if (block->GetLoopInformation() != nullptr) { |
| 5223 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5224 | // The back edge will generate the suspend check. |
| 5225 | return; |
| 5226 | } |
| 5227 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5228 | // The goto will generate the suspend check. |
| 5229 | return; |
| 5230 | } |
| 5231 | GenerateSuspendCheck(instruction, nullptr); |
| 5232 | } |
| 5233 | |
| 5234 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5235 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5236 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5237 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5238 | if (slow_path == nullptr) { |
| 5239 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5240 | instruction->SetSlowPath(slow_path); |
| 5241 | codegen_->AddSlowPath(slow_path); |
| 5242 | if (successor != nullptr) { |
| 5243 | DCHECK(successor->IsLoopHeader()); |
| 5244 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5245 | } |
| 5246 | } else { |
| 5247 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5248 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5249 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5250 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5251 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5252 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5253 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5254 | __ Bind(slow_path->GetReturnLabel()); |
| 5255 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5256 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5257 | __ b(slow_path->GetEntryLabel()); |
| 5258 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5259 | } |
| 5260 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5261 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5262 | return codegen_->GetAssembler(); |
| 5263 | } |
| 5264 | |
| 5265 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5266 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5267 | Location source = move->GetSource(); |
| 5268 | Location destination = move->GetDestination(); |
| 5269 | |
| 5270 | if (source.IsRegister()) { |
| 5271 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5272 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5273 | } else if (destination.IsFpuRegister()) { |
| 5274 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5275 | } else { |
| 5276 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5277 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5278 | SP, destination.GetStackIndex()); |
| 5279 | } |
| 5280 | } else if (source.IsStackSlot()) { |
| 5281 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5282 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5283 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5284 | } else if (destination.IsFpuRegister()) { |
| 5285 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5286 | } else { |
| 5287 | DCHECK(destination.IsStackSlot()); |
| 5288 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5289 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5290 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5291 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5292 | if (destination.IsRegister()) { |
| 5293 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5294 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5295 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5296 | } else { |
| 5297 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5298 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5299 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5300 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5301 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5302 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5303 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5304 | } else if (destination.IsRegisterPair()) { |
| 5305 | DCHECK(ExpectedPairLayout(destination)); |
| 5306 | __ LoadFromOffset( |
| 5307 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5308 | } else { |
| 5309 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5310 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5311 | SP, |
| 5312 | source.GetStackIndex()); |
| 5313 | } |
| 5314 | } else if (source.IsRegisterPair()) { |
| 5315 | if (destination.IsRegisterPair()) { |
| 5316 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5317 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5318 | } else if (destination.IsFpuRegisterPair()) { |
| 5319 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5320 | source.AsRegisterPairLow<Register>(), |
| 5321 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5322 | } else { |
| 5323 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5324 | DCHECK(ExpectedPairLayout(source)); |
| 5325 | __ StoreToOffset( |
| 5326 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5327 | } |
| 5328 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5329 | if (destination.IsRegisterPair()) { |
| 5330 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5331 | destination.AsRegisterPairHigh<Register>(), |
| 5332 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5333 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5334 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5335 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5336 | } else { |
| 5337 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5338 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5339 | SP, |
| 5340 | destination.GetStackIndex()); |
| 5341 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5342 | } else { |
| 5343 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5344 | HConstant* constant = source.GetConstant(); |
| 5345 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5346 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5347 | if (destination.IsRegister()) { |
| 5348 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5349 | } else { |
| 5350 | DCHECK(destination.IsStackSlot()); |
| 5351 | __ LoadImmediate(IP, value); |
| 5352 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5353 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5354 | } else if (constant->IsLongConstant()) { |
| 5355 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5356 | if (destination.IsRegisterPair()) { |
| 5357 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5358 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5359 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5360 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5361 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5362 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5363 | __ LoadImmediate(IP, High32Bits(value)); |
| 5364 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5365 | } |
| 5366 | } else if (constant->IsDoubleConstant()) { |
| 5367 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5368 | if (destination.IsFpuRegisterPair()) { |
| 5369 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5370 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5371 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5372 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5373 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5374 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5375 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5376 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5377 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5378 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5379 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5380 | float value = constant->AsFloatConstant()->GetValue(); |
| 5381 | if (destination.IsFpuRegister()) { |
| 5382 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5383 | } else { |
| 5384 | DCHECK(destination.IsStackSlot()); |
| 5385 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5386 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5387 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5388 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5393 | __ Mov(IP, reg); |
| 5394 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5395 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5396 | } |
| 5397 | |
| 5398 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5399 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5400 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5401 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5402 | SP, mem1 + stack_offset); |
| 5403 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5404 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5405 | SP, mem2 + stack_offset); |
| 5406 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5407 | } |
| 5408 | |
| 5409 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5410 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5411 | Location source = move->GetSource(); |
| 5412 | Location destination = move->GetDestination(); |
| 5413 | |
| 5414 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5415 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5416 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5417 | __ Mov(IP, source.AsRegister<Register>()); |
| 5418 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5419 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5420 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5421 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5422 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5423 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5424 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5425 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5426 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5427 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5428 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5429 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5430 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5431 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5432 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5433 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5434 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5435 | destination.AsRegisterPairHigh<Register>(), |
| 5436 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5437 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5438 | Register low_reg = source.IsRegisterPair() |
| 5439 | ? source.AsRegisterPairLow<Register>() |
| 5440 | : destination.AsRegisterPairLow<Register>(); |
| 5441 | int mem = source.IsRegisterPair() |
| 5442 | ? destination.GetStackIndex() |
| 5443 | : source.GetStackIndex(); |
| 5444 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5445 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5446 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5447 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5448 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5449 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5450 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5451 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5452 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5453 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5454 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5455 | DRegister reg = source.IsFpuRegisterPair() |
| 5456 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5457 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5458 | int mem = source.IsFpuRegisterPair() |
| 5459 | ? destination.GetStackIndex() |
| 5460 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5461 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5462 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5463 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5464 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5465 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5466 | : destination.AsFpuRegister<SRegister>(); |
| 5467 | int mem = source.IsFpuRegister() |
| 5468 | ? destination.GetStackIndex() |
| 5469 | : source.GetStackIndex(); |
| 5470 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5471 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5472 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5473 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5474 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5475 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5476 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5477 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5478 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5479 | } |
| 5480 | } |
| 5481 | |
| 5482 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5483 | __ Push(static_cast<Register>(reg)); |
| 5484 | } |
| 5485 | |
| 5486 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5487 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5488 | } |
| 5489 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5490 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5491 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5492 | switch (desired_class_load_kind) { |
| 5493 | case HLoadClass::LoadKind::kReferrersClass: |
| 5494 | break; |
| 5495 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5496 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5497 | break; |
| 5498 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5499 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5500 | break; |
| 5501 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5502 | break; |
| 5503 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5504 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5505 | break; |
| 5506 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5507 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5508 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5509 | // is incompatible with it. |
| 5510 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5511 | // with irreducible loops. |
| 5512 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5513 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5514 | } |
| 5515 | break; |
| 5516 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5517 | break; |
| 5518 | } |
| 5519 | return desired_class_load_kind; |
| 5520 | } |
| 5521 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5522 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5523 | if (cls->NeedsAccessCheck()) { |
| 5524 | InvokeRuntimeCallingConvention calling_convention; |
| 5525 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5526 | cls, |
| 5527 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5528 | Location::RegisterLocation(R0), |
| 5529 | /* code_generator_supports_read_barrier */ true); |
| 5530 | return; |
| 5531 | } |
| 5532 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5533 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5534 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5535 | ? LocationSummary::kCallOnSlowPath |
| 5536 | : LocationSummary::kNoCall; |
| 5537 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5538 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5539 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5540 | } |
| 5541 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5542 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5543 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5544 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5545 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5546 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5547 | } |
| 5548 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5552 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5553 | if (cls->NeedsAccessCheck()) { |
| 5554 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5555 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5556 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5557 | return; |
| 5558 | } |
| 5559 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5560 | Location out_loc = locations->Out(); |
| 5561 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5562 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5563 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5564 | bool generate_null_check = false; |
| 5565 | switch (cls->GetLoadKind()) { |
| 5566 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5567 | DCHECK(!cls->CanCallRuntime()); |
| 5568 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5569 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5570 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5571 | GenerateGcRootFieldLoad(cls, |
| 5572 | out_loc, |
| 5573 | current_method, |
| 5574 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5575 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5576 | break; |
| 5577 | } |
| 5578 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5579 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5580 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5581 | cls->GetTypeIndex())); |
| 5582 | break; |
| 5583 | } |
| 5584 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5585 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5586 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5587 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5588 | __ BindTrackedLabel(&labels->movw_label); |
| 5589 | __ movw(out, /* placeholder */ 0u); |
| 5590 | __ BindTrackedLabel(&labels->movt_label); |
| 5591 | __ movt(out, /* placeholder */ 0u); |
| 5592 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5593 | __ add(out, out, ShifterOperand(PC)); |
| 5594 | break; |
| 5595 | } |
| 5596 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5597 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5598 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5599 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5600 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5601 | break; |
| 5602 | } |
| 5603 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5604 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5605 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5606 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5607 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5608 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5609 | // and the remaining offset embedded in the load. |
| 5610 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5611 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5612 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5613 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5614 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5615 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5616 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5617 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5618 | generate_null_check = !cls->IsInDexCache(); |
| 5619 | break; |
| 5620 | } |
| 5621 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5622 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5623 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5624 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5625 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5626 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5627 | generate_null_check = !cls->IsInDexCache(); |
| 5628 | break; |
| 5629 | } |
| 5630 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5631 | // /* GcRoot<mirror::Class>[] */ out = |
| 5632 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5633 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5634 | __ LoadFromOffset(kLoadWord, |
| 5635 | out, |
| 5636 | current_method, |
| 5637 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5638 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5639 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5640 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5641 | generate_null_check = !cls->IsInDexCache(); |
| 5642 | } |
| 5643 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5644 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5645 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5646 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5647 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5648 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5649 | codegen_->AddSlowPath(slow_path); |
| 5650 | if (generate_null_check) { |
| 5651 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5652 | } |
| 5653 | if (cls->MustGenerateClinitCheck()) { |
| 5654 | GenerateClassInitializationCheck(slow_path, out); |
| 5655 | } else { |
| 5656 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5657 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5658 | } |
| 5659 | } |
| 5660 | |
| 5661 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5662 | LocationSummary* locations = |
| 5663 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5665 | if (check->HasUses()) { |
| 5666 | locations->SetOut(Location::SameAsFirstInput()); |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5671 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5672 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5673 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5674 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5675 | GenerateClassInitializationCheck(slow_path, |
| 5676 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5677 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5678 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5679 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5680 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5681 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5682 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5683 | __ b(slow_path->GetEntryLabel(), LT); |
| 5684 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5685 | // properly. Therefore, we do a memory fence. |
| 5686 | __ dmb(ISH); |
| 5687 | __ Bind(slow_path->GetExitLabel()); |
| 5688 | } |
| 5689 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5690 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5691 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5692 | switch (desired_string_load_kind) { |
| 5693 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5694 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5695 | break; |
| 5696 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5697 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5698 | break; |
| 5699 | case HLoadString::LoadKind::kBootImageAddress: |
| 5700 | break; |
| 5701 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5702 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5703 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5704 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5705 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5706 | break; |
| 5707 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5708 | break; |
| 5709 | } |
| 5710 | return desired_string_load_kind; |
| 5711 | } |
| 5712 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5713 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5714 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5715 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5716 | ? LocationSummary::kCallOnMainOnly |
| 5717 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5718 | : LocationSummary::kNoCall; |
| 5719 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5720 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5721 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5722 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5723 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5724 | } else { |
| 5725 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 5726 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5727 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5728 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 5729 | // Note that IP may theoretically be clobbered by saving/restoring the live register |
| 5730 | // (only one thanks to the custom calling convention), so we request a different temp. |
| 5731 | locations->AddTemp(Location::RequiresRegister()); |
| 5732 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5733 | InvokeRuntimeCallingConvention calling_convention; |
| 5734 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5735 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5736 | // that the the kPrimNot result register is the same as the first argument register. |
| 5737 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5738 | } else { |
| 5739 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5740 | } |
| 5741 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5742 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5743 | } |
| 5744 | |
| 5745 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5746 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5747 | Location out_loc = locations->Out(); |
| 5748 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5749 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5750 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5751 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5752 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5753 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5754 | load->GetStringIndex())); |
| 5755 | return; // No dex cache slow path. |
| 5756 | } |
| 5757 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5758 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5759 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5760 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5761 | __ BindTrackedLabel(&labels->movw_label); |
| 5762 | __ movw(out, /* placeholder */ 0u); |
| 5763 | __ BindTrackedLabel(&labels->movt_label); |
| 5764 | __ movt(out, /* placeholder */ 0u); |
| 5765 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5766 | __ add(out, out, ShifterOperand(PC)); |
| 5767 | return; // No dex cache slow path. |
| 5768 | } |
| 5769 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5770 | DCHECK_NE(load->GetAddress(), 0u); |
| 5771 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5772 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5773 | return; // No dex cache slow path. |
| 5774 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5775 | case HLoadString::LoadKind::kBssEntry: { |
| 5776 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 5777 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5778 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5779 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5780 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 5781 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5782 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 5783 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5784 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 5785 | __ add(temp, temp, ShifterOperand(PC)); |
| 5786 | GenerateGcRootFieldLoad(load, out_loc, temp, 0); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5787 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5788 | codegen_->AddSlowPath(slow_path); |
| 5789 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5790 | __ Bind(slow_path->GetExitLabel()); |
| 5791 | return; |
| 5792 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5793 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5794 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5795 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5796 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5797 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 5798 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5799 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame^] | 5800 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5801 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex()); |
| 5802 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5803 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5806 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5807 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5808 | } |
| 5809 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5810 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5811 | LocationSummary* locations = |
| 5812 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5813 | locations->SetOut(Location::RequiresRegister()); |
| 5814 | } |
| 5815 | |
| 5816 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5817 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5818 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5819 | } |
| 5820 | |
| 5821 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5822 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5823 | } |
| 5824 | |
| 5825 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5826 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5827 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5831 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5832 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5833 | InvokeRuntimeCallingConvention calling_convention; |
| 5834 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5835 | } |
| 5836 | |
| 5837 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5838 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5839 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5842 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5843 | return kEmitCompilerReadBarrier && |
| 5844 | (kUseBakerReadBarrier || |
| 5845 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5846 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5847 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5848 | } |
| 5849 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5850 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5851 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5852 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5853 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5854 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5855 | case TypeCheckKind::kExactCheck: |
| 5856 | case TypeCheckKind::kAbstractClassCheck: |
| 5857 | case TypeCheckKind::kClassHierarchyCheck: |
| 5858 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5859 | call_kind = |
| 5860 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5861 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5862 | break; |
| 5863 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5864 | case TypeCheckKind::kUnresolvedCheck: |
| 5865 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5866 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5867 | break; |
| 5868 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5869 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5870 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5871 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5872 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5873 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5875 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5876 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5877 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5878 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5879 | // When read barriers are enabled, we need a temporary register for |
| 5880 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5881 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5882 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5883 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5886 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5887 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5888 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5889 | Location obj_loc = locations->InAt(0); |
| 5890 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5891 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5892 | Location out_loc = locations->Out(); |
| 5893 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5894 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5895 | locations->GetTemp(0) : |
| 5896 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5897 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5898 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5899 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5900 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5901 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5902 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5903 | |
| 5904 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5905 | // avoid null check if we know obj is not null. |
| 5906 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5907 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5908 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5909 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5910 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5911 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5913 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5914 | case TypeCheckKind::kExactCheck: { |
| 5915 | __ cmp(out, ShifterOperand(cls)); |
| 5916 | // Classes must be equal for the instanceof to succeed. |
| 5917 | __ b(&zero, NE); |
| 5918 | __ LoadImmediate(out, 1); |
| 5919 | __ b(&done); |
| 5920 | break; |
| 5921 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5922 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5923 | case TypeCheckKind::kAbstractClassCheck: { |
| 5924 | // If the class is abstract, we eagerly fetch the super class of the |
| 5925 | // object to avoid doing a comparison we know will fail. |
| 5926 | Label loop; |
| 5927 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5928 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5929 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5930 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5931 | __ CompareAndBranchIfZero(out, &done); |
| 5932 | __ cmp(out, ShifterOperand(cls)); |
| 5933 | __ b(&loop, NE); |
| 5934 | __ LoadImmediate(out, 1); |
| 5935 | if (zero.IsLinked()) { |
| 5936 | __ b(&done); |
| 5937 | } |
| 5938 | break; |
| 5939 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5940 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5941 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5942 | // Walk over the class hierarchy to find a match. |
| 5943 | Label loop, success; |
| 5944 | __ Bind(&loop); |
| 5945 | __ cmp(out, ShifterOperand(cls)); |
| 5946 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5947 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5948 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5949 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5950 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5951 | __ b(&done); |
| 5952 | __ Bind(&success); |
| 5953 | __ LoadImmediate(out, 1); |
| 5954 | if (zero.IsLinked()) { |
| 5955 | __ b(&done); |
| 5956 | } |
| 5957 | break; |
| 5958 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5959 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5960 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5961 | // Do an exact check. |
| 5962 | Label exact_check; |
| 5963 | __ cmp(out, ShifterOperand(cls)); |
| 5964 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5965 | // 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] | 5966 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5967 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5969 | __ CompareAndBranchIfZero(out, &done); |
| 5970 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5971 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5972 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5973 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5974 | __ LoadImmediate(out, 1); |
| 5975 | __ b(&done); |
| 5976 | break; |
| 5977 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5978 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5979 | case TypeCheckKind::kArrayCheck: { |
| 5980 | __ cmp(out, ShifterOperand(cls)); |
| 5981 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5982 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5983 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5984 | codegen_->AddSlowPath(slow_path); |
| 5985 | __ b(slow_path->GetEntryLabel(), NE); |
| 5986 | __ LoadImmediate(out, 1); |
| 5987 | if (zero.IsLinked()) { |
| 5988 | __ b(&done); |
| 5989 | } |
| 5990 | break; |
| 5991 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5992 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5993 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5994 | case TypeCheckKind::kInterfaceCheck: { |
| 5995 | // 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] | 5996 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5997 | // cases. |
| 5998 | // |
| 5999 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6000 | // entry point without resorting to a type checking slow path |
| 6001 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6002 | // require to assign fixed registers for the inputs of this |
| 6003 | // HInstanceOf instruction (following the runtime calling |
| 6004 | // convention), which might be cluttered by the potential first |
| 6005 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6006 | // |
| 6007 | // TODO: Introduce a new runtime entry point taking the object |
| 6008 | // to test (instead of its class) as argument, and let it deal |
| 6009 | // with the read barrier issues. This will let us refactor this |
| 6010 | // case of the `switch` code as it was previously (with a direct |
| 6011 | // call to the runtime not using a type checking slow path). |
| 6012 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6013 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6014 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6015 | /* is_fatal */ false); |
| 6016 | codegen_->AddSlowPath(slow_path); |
| 6017 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6018 | if (zero.IsLinked()) { |
| 6019 | __ b(&done); |
| 6020 | } |
| 6021 | break; |
| 6022 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6023 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6024 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6025 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6026 | __ Bind(&zero); |
| 6027 | __ LoadImmediate(out, 0); |
| 6028 | } |
| 6029 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6030 | if (done.IsLinked()) { |
| 6031 | __ Bind(&done); |
| 6032 | } |
| 6033 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6034 | if (slow_path != nullptr) { |
| 6035 | __ Bind(slow_path->GetExitLabel()); |
| 6036 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6039 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6040 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6041 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6042 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6043 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6044 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6045 | case TypeCheckKind::kExactCheck: |
| 6046 | case TypeCheckKind::kAbstractClassCheck: |
| 6047 | case TypeCheckKind::kClassHierarchyCheck: |
| 6048 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6049 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6050 | LocationSummary::kCallOnSlowPath : |
| 6051 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6052 | break; |
| 6053 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6054 | case TypeCheckKind::kUnresolvedCheck: |
| 6055 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6056 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6057 | break; |
| 6058 | } |
| 6059 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6060 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6062 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6063 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 6064 | locations->AddTemp(Location::RequiresRegister()); |
| 6065 | // When read barriers are enabled, we need an additional temporary |
| 6066 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6067 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6068 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6069 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6073 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6074 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6075 | Location obj_loc = locations->InAt(0); |
| 6076 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6077 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6078 | Location temp_loc = locations->GetTemp(0); |
| 6079 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6080 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6081 | locations->GetTemp(1) : |
| 6082 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6083 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6084 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6085 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6086 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6087 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6088 | bool is_type_check_slow_path_fatal = |
| 6089 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6090 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6091 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6092 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6093 | !instruction->CanThrowIntoCatchBlock(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6094 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6095 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6096 | is_type_check_slow_path_fatal); |
| 6097 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6098 | |
| 6099 | Label done; |
| 6100 | // Avoid null check if we know obj is not null. |
| 6101 | if (instruction->MustDoNullCheck()) { |
| 6102 | __ CompareAndBranchIfZero(obj, &done); |
| 6103 | } |
| 6104 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6105 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6106 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6107 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6108 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | case TypeCheckKind::kExactCheck: |
| 6110 | case TypeCheckKind::kArrayCheck: { |
| 6111 | __ cmp(temp, ShifterOperand(cls)); |
| 6112 | // Jump to slow path for throwing the exception or doing a |
| 6113 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6114 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6115 | break; |
| 6116 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6117 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6118 | case TypeCheckKind::kAbstractClassCheck: { |
| 6119 | // If the class is abstract, we eagerly fetch the super class of the |
| 6120 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6121 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6122 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6123 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6124 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6125 | |
| 6126 | // If the class reference currently in `temp` is not null, jump |
| 6127 | // to the `compare_classes` label to compare it with the checked |
| 6128 | // class. |
| 6129 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 6130 | // Otherwise, jump to the slow path to throw the exception. |
| 6131 | // |
| 6132 | // But before, move back the object's class into `temp` before |
| 6133 | // going into the slow path, as it has been overwritten in the |
| 6134 | // meantime. |
| 6135 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6136 | GenerateReferenceLoadTwoRegisters( |
| 6137 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6138 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6139 | |
| 6140 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6141 | __ cmp(temp, ShifterOperand(cls)); |
| 6142 | __ b(&loop, NE); |
| 6143 | break; |
| 6144 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6145 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6146 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6147 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6148 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6149 | __ Bind(&loop); |
| 6150 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6151 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6152 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6153 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6154 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6155 | |
| 6156 | // If the class reference currently in `temp` is not null, jump |
| 6157 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6159 | // Otherwise, jump to the slow path to throw the exception. |
| 6160 | // |
| 6161 | // But before, move back the object's class into `temp` before |
| 6162 | // going into the slow path, as it has been overwritten in the |
| 6163 | // meantime. |
| 6164 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6165 | GenerateReferenceLoadTwoRegisters( |
| 6166 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6167 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | break; |
| 6169 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6170 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6172 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6173 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6174 | __ cmp(temp, ShifterOperand(cls)); |
| 6175 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6176 | |
| 6177 | // 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] | 6178 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6179 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6180 | |
| 6181 | // If the component type is not null (i.e. the object is indeed |
| 6182 | // an array), jump to label `check_non_primitive_component_type` |
| 6183 | // to further check that this component type is not a primitive |
| 6184 | // type. |
| 6185 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 6186 | // Otherwise, jump to the slow path to throw the exception. |
| 6187 | // |
| 6188 | // But before, move back the object's class into `temp` before |
| 6189 | // going into the slow path, as it has been overwritten in the |
| 6190 | // meantime. |
| 6191 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6192 | GenerateReferenceLoadTwoRegisters( |
| 6193 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6194 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6195 | |
| 6196 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6197 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6198 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 6199 | __ CompareAndBranchIfZero(temp, &done); |
| 6200 | // Same comment as above regarding `temp` and the slow path. |
| 6201 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6202 | GenerateReferenceLoadTwoRegisters( |
| 6203 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6204 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6205 | break; |
| 6206 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6207 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6208 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6209 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6210 | // We always go into the type check slow path for the unresolved |
| 6211 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6212 | // |
| 6213 | // We cannot directly call the CheckCast runtime entry point |
| 6214 | // without resorting to a type checking slow path here (i.e. by |
| 6215 | // calling InvokeRuntime directly), as it would require to |
| 6216 | // assign fixed registers for the inputs of this HInstanceOf |
| 6217 | // instruction (following the runtime calling convention), which |
| 6218 | // might be cluttered by the potential first read barrier |
| 6219 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6220 | // |
| 6221 | // TODO: Introduce a new runtime entry point taking the object |
| 6222 | // to test (instead of its class) as argument, and let it deal |
| 6223 | // with the read barrier issues. This will let us refactor this |
| 6224 | // case of the `switch` code as it was previously (with a direct |
| 6225 | // call to the runtime not using a type checking slow path). |
| 6226 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6227 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6228 | break; |
| 6229 | } |
| 6230 | __ Bind(&done); |
| 6231 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6232 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6233 | } |
| 6234 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6235 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6236 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6237 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6238 | InvokeRuntimeCallingConvention calling_convention; |
| 6239 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6240 | } |
| 6241 | |
| 6242 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6243 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6244 | instruction, |
| 6245 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6246 | if (instruction->IsEnter()) { |
| 6247 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6248 | } else { |
| 6249 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6250 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6251 | } |
| 6252 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6253 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6254 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6255 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6256 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6257 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6258 | LocationSummary* locations = |
| 6259 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6260 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6261 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6262 | // 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] | 6263 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6264 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6265 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6266 | } |
| 6267 | |
| 6268 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6269 | HandleBitwiseOperation(instruction); |
| 6270 | } |
| 6271 | |
| 6272 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6273 | HandleBitwiseOperation(instruction); |
| 6274 | } |
| 6275 | |
| 6276 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6277 | HandleBitwiseOperation(instruction); |
| 6278 | } |
| 6279 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6280 | |
| 6281 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6282 | LocationSummary* locations = |
| 6283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6284 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6285 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6286 | |
| 6287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6288 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6289 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6290 | } |
| 6291 | |
| 6292 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6293 | LocationSummary* locations = instruction->GetLocations(); |
| 6294 | Location first = locations->InAt(0); |
| 6295 | Location second = locations->InAt(1); |
| 6296 | Location out = locations->Out(); |
| 6297 | |
| 6298 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6299 | Register first_reg = first.AsRegister<Register>(); |
| 6300 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6301 | Register out_reg = out.AsRegister<Register>(); |
| 6302 | |
| 6303 | switch (instruction->GetOpKind()) { |
| 6304 | case HInstruction::kAnd: |
| 6305 | __ bic(out_reg, first_reg, second_reg); |
| 6306 | break; |
| 6307 | case HInstruction::kOr: |
| 6308 | __ orn(out_reg, first_reg, second_reg); |
| 6309 | break; |
| 6310 | // There is no EON on arm. |
| 6311 | case HInstruction::kXor: |
| 6312 | default: |
| 6313 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6314 | UNREACHABLE(); |
| 6315 | } |
| 6316 | return; |
| 6317 | |
| 6318 | } else { |
| 6319 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6320 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6321 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6322 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6323 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6324 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6325 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6326 | |
| 6327 | switch (instruction->GetOpKind()) { |
| 6328 | case HInstruction::kAnd: |
| 6329 | __ bic(out_low, first_low, second_low); |
| 6330 | __ bic(out_high, first_high, second_high); |
| 6331 | break; |
| 6332 | case HInstruction::kOr: |
| 6333 | __ orn(out_low, first_low, second_low); |
| 6334 | __ orn(out_high, first_high, second_high); |
| 6335 | break; |
| 6336 | // There is no EON on arm. |
| 6337 | case HInstruction::kXor: |
| 6338 | default: |
| 6339 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6340 | UNREACHABLE(); |
| 6341 | } |
| 6342 | } |
| 6343 | } |
| 6344 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6345 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6346 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6347 | if (value == 0xffffffffu) { |
| 6348 | if (out != first) { |
| 6349 | __ mov(out, ShifterOperand(first)); |
| 6350 | } |
| 6351 | return; |
| 6352 | } |
| 6353 | if (value == 0u) { |
| 6354 | __ mov(out, ShifterOperand(0)); |
| 6355 | return; |
| 6356 | } |
| 6357 | ShifterOperand so; |
| 6358 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6359 | __ and_(out, first, so); |
| 6360 | } else { |
| 6361 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6362 | __ bic(out, first, ShifterOperand(~value)); |
| 6363 | } |
| 6364 | } |
| 6365 | |
| 6366 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6367 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6368 | if (value == 0u) { |
| 6369 | if (out != first) { |
| 6370 | __ mov(out, ShifterOperand(first)); |
| 6371 | } |
| 6372 | return; |
| 6373 | } |
| 6374 | if (value == 0xffffffffu) { |
| 6375 | __ mvn(out, ShifterOperand(0)); |
| 6376 | return; |
| 6377 | } |
| 6378 | ShifterOperand so; |
| 6379 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6380 | __ orr(out, first, so); |
| 6381 | } else { |
| 6382 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6383 | __ orn(out, first, ShifterOperand(~value)); |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6388 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6389 | if (value == 0u) { |
| 6390 | if (out != first) { |
| 6391 | __ mov(out, ShifterOperand(first)); |
| 6392 | } |
| 6393 | return; |
| 6394 | } |
| 6395 | __ eor(out, first, ShifterOperand(value)); |
| 6396 | } |
| 6397 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6398 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6399 | Location first, |
| 6400 | uint64_t value) { |
| 6401 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6402 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6403 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6404 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6405 | uint32_t value_low = Low32Bits(value); |
| 6406 | uint32_t value_high = High32Bits(value); |
| 6407 | if (value_low == 0u) { |
| 6408 | if (out_low != first_low) { |
| 6409 | __ mov(out_low, ShifterOperand(first_low)); |
| 6410 | } |
| 6411 | __ AddConstant(out_high, first_high, value_high); |
| 6412 | return; |
| 6413 | } |
| 6414 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6415 | ShifterOperand so; |
| 6416 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6417 | __ adc(out_high, first_high, so); |
| 6418 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6419 | __ sbc(out_high, first_high, so); |
| 6420 | } else { |
| 6421 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6422 | UNREACHABLE(); |
| 6423 | } |
| 6424 | } |
| 6425 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6426 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6427 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6428 | Location first = locations->InAt(0); |
| 6429 | Location second = locations->InAt(1); |
| 6430 | Location out = locations->Out(); |
| 6431 | |
| 6432 | if (second.IsConstant()) { |
| 6433 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6434 | uint32_t value_low = Low32Bits(value); |
| 6435 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6436 | Register first_reg = first.AsRegister<Register>(); |
| 6437 | Register out_reg = out.AsRegister<Register>(); |
| 6438 | if (instruction->IsAnd()) { |
| 6439 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6440 | } else if (instruction->IsOr()) { |
| 6441 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6442 | } else { |
| 6443 | DCHECK(instruction->IsXor()); |
| 6444 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6445 | } |
| 6446 | } else { |
| 6447 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6448 | uint32_t value_high = High32Bits(value); |
| 6449 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6450 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6451 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6452 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6453 | if (instruction->IsAnd()) { |
| 6454 | GenerateAndConst(out_low, first_low, value_low); |
| 6455 | GenerateAndConst(out_high, first_high, value_high); |
| 6456 | } else if (instruction->IsOr()) { |
| 6457 | GenerateOrrConst(out_low, first_low, value_low); |
| 6458 | GenerateOrrConst(out_high, first_high, value_high); |
| 6459 | } else { |
| 6460 | DCHECK(instruction->IsXor()); |
| 6461 | GenerateEorConst(out_low, first_low, value_low); |
| 6462 | GenerateEorConst(out_high, first_high, value_high); |
| 6463 | } |
| 6464 | } |
| 6465 | return; |
| 6466 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6467 | |
| 6468 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6469 | Register first_reg = first.AsRegister<Register>(); |
| 6470 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6471 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6472 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6473 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6474 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6475 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6476 | } else { |
| 6477 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6478 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6479 | } |
| 6480 | } else { |
| 6481 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6482 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6483 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6484 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6485 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6486 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6487 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6488 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6489 | __ and_(out_low, first_low, second_low); |
| 6490 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6491 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6492 | __ orr(out_low, first_low, second_low); |
| 6493 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6494 | } else { |
| 6495 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6496 | __ eor(out_low, first_low, second_low); |
| 6497 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6498 | } |
| 6499 | } |
| 6500 | } |
| 6501 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6502 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6503 | Location out, |
| 6504 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6505 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6506 | Register out_reg = out.AsRegister<Register>(); |
| 6507 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6508 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6509 | if (kUseBakerReadBarrier) { |
| 6510 | // Load with fast path based Baker's read barrier. |
| 6511 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6512 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6513 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6514 | } else { |
| 6515 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6516 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6517 | // in the following move operation, as we will need it for the |
| 6518 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6519 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6520 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6521 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6522 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6523 | } |
| 6524 | } else { |
| 6525 | // Plain load with no read barrier. |
| 6526 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6527 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6528 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6529 | } |
| 6530 | } |
| 6531 | |
| 6532 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6533 | Location out, |
| 6534 | Location obj, |
| 6535 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6536 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6537 | Register out_reg = out.AsRegister<Register>(); |
| 6538 | Register obj_reg = obj.AsRegister<Register>(); |
| 6539 | if (kEmitCompilerReadBarrier) { |
| 6540 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6541 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6542 | // Load with fast path based Baker's read barrier. |
| 6543 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6544 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6545 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6546 | } else { |
| 6547 | // Load with slow path based read barrier. |
| 6548 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6549 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6550 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6551 | } |
| 6552 | } else { |
| 6553 | // Plain load with no read barrier. |
| 6554 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6555 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6556 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6561 | Location root, |
| 6562 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6563 | uint32_t offset, |
| 6564 | bool requires_read_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6565 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6566 | if (requires_read_barrier) { |
| 6567 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6568 | if (kUseBakerReadBarrier) { |
| 6569 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6570 | // Baker's read barrier are used: |
| 6571 | // |
| 6572 | // root = obj.field; |
| 6573 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6574 | // root = ReadBarrier::Mark(root) |
| 6575 | // } |
| 6576 | |
| 6577 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6578 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6579 | static_assert( |
| 6580 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6581 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6582 | "have different sizes."); |
| 6583 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6584 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6585 | "have different sizes."); |
| 6586 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6587 | // Slow path marking the GC root `root`. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6588 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6589 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6590 | codegen_->AddSlowPath(slow_path); |
| 6591 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6592 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6593 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6594 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6595 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6596 | __ Bind(slow_path->GetExitLabel()); |
| 6597 | } else { |
| 6598 | // GC root loaded through a slow path for read barriers other |
| 6599 | // than Baker's. |
| 6600 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6601 | __ AddConstant(root_reg, obj, offset); |
| 6602 | // /* mirror::Object* */ root = root->Read() |
| 6603 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6604 | } |
| 6605 | } else { |
| 6606 | // Plain GC root load with no read barrier. |
| 6607 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6608 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6609 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6610 | // do not have to unpoison `root_reg` here. |
| 6611 | } |
| 6612 | } |
| 6613 | |
| 6614 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6615 | Location ref, |
| 6616 | Register obj, |
| 6617 | uint32_t offset, |
| 6618 | Location temp, |
| 6619 | bool needs_null_check) { |
| 6620 | DCHECK(kEmitCompilerReadBarrier); |
| 6621 | DCHECK(kUseBakerReadBarrier); |
| 6622 | |
| 6623 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6624 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6625 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6626 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6627 | 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] | 6628 | } |
| 6629 | |
| 6630 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6631 | Location ref, |
| 6632 | Register obj, |
| 6633 | uint32_t data_offset, |
| 6634 | Location index, |
| 6635 | Location temp, |
| 6636 | bool needs_null_check) { |
| 6637 | DCHECK(kEmitCompilerReadBarrier); |
| 6638 | DCHECK(kUseBakerReadBarrier); |
| 6639 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6640 | static_assert( |
| 6641 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6642 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6643 | // /* HeapReference<Object> */ ref = |
| 6644 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6645 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6646 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6647 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6651 | Location ref, |
| 6652 | Register obj, |
| 6653 | uint32_t offset, |
| 6654 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6655 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6656 | Location temp, |
| 6657 | bool needs_null_check) { |
| 6658 | DCHECK(kEmitCompilerReadBarrier); |
| 6659 | DCHECK(kUseBakerReadBarrier); |
| 6660 | |
| 6661 | // In slow path based read barriers, the read barrier call is |
| 6662 | // inserted after the original load. However, in fast path based |
| 6663 | // Baker's read barriers, we need to perform the load of |
| 6664 | // mirror::Object::monitor_ *before* the original reference load. |
| 6665 | // This load-load ordering is required by the read barrier. |
| 6666 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6667 | // |
| 6668 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6669 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6670 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6671 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6672 | // if (is_gray) { |
| 6673 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6674 | // } |
| 6675 | // |
| 6676 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6677 | // slightly more complex as it performs additional checks that we do |
| 6678 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6679 | |
| 6680 | Register ref_reg = ref.AsRegister<Register>(); |
| 6681 | Register temp_reg = temp.AsRegister<Register>(); |
| 6682 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6683 | |
| 6684 | // /* int32_t */ monitor = obj->monitor_ |
| 6685 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6686 | if (needs_null_check) { |
| 6687 | MaybeRecordImplicitNullCheck(instruction); |
| 6688 | } |
| 6689 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6690 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6691 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6692 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6693 | // Introduce a dependency on the lock_word including the rb_state, |
| 6694 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6695 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 6696 | // `obj` is unchanged by this operation, but its value now depends |
| 6697 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6698 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6699 | |
| 6700 | // The actual reference load. |
| 6701 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6702 | // Load types involving an "index": ArrayGet and |
| 6703 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6704 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6705 | if (index.IsConstant()) { |
| 6706 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6707 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6708 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6709 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6710 | // Handle the special case of the |
| 6711 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6712 | // a register pair as index ("long offset"), of which only the low |
| 6713 | // part contains data. |
| 6714 | Register index_reg = index.IsRegisterPair() |
| 6715 | ? index.AsRegisterPairLow<Register>() |
| 6716 | : index.AsRegister<Register>(); |
| 6717 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6718 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6719 | } |
| 6720 | } else { |
| 6721 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6722 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6723 | } |
| 6724 | |
| 6725 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6726 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6727 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6728 | // Slow path marking the object `ref` when it is gray. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6729 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6730 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6731 | AddSlowPath(slow_path); |
| 6732 | |
| 6733 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6734 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6735 | // Given the numeric representation, it's enough to check the low bit of the |
| 6736 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6737 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6738 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6739 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6740 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6741 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6742 | __ 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] | 6743 | __ Bind(slow_path->GetExitLabel()); |
| 6744 | } |
| 6745 | |
| 6746 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6747 | Location out, |
| 6748 | Location ref, |
| 6749 | Location obj, |
| 6750 | uint32_t offset, |
| 6751 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6752 | DCHECK(kEmitCompilerReadBarrier); |
| 6753 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6754 | // Insert a slow path based read barrier *after* the reference load. |
| 6755 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6756 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6757 | // reference will be carried out by the runtime within the slow |
| 6758 | // path. |
| 6759 | // |
| 6760 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6761 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6762 | // not used by the artReadBarrierSlow entry point. |
| 6763 | // |
| 6764 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6765 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6766 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6767 | AddSlowPath(slow_path); |
| 6768 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6769 | __ b(slow_path->GetEntryLabel()); |
| 6770 | __ Bind(slow_path->GetExitLabel()); |
| 6771 | } |
| 6772 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6773 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6774 | Location out, |
| 6775 | Location ref, |
| 6776 | Location obj, |
| 6777 | uint32_t offset, |
| 6778 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6779 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6780 | // Baker's read barriers shall be handled by the fast path |
| 6781 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6782 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6783 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6784 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6785 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6786 | } else if (kPoisonHeapReferences) { |
| 6787 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6788 | } |
| 6789 | } |
| 6790 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6791 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6792 | Location out, |
| 6793 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6794 | DCHECK(kEmitCompilerReadBarrier); |
| 6795 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6796 | // Insert a slow path based read barrier *after* the GC root load. |
| 6797 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6798 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6799 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6800 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6801 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6802 | AddSlowPath(slow_path); |
| 6803 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6804 | __ b(slow_path->GetEntryLabel()); |
| 6805 | __ Bind(slow_path->GetExitLabel()); |
| 6806 | } |
| 6807 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6808 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6809 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6810 | HInvokeStaticOrDirect* invoke) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6811 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6812 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6813 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6814 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6815 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6816 | if (GetGraph()->HasIrreducibleLoops() && |
| 6817 | (dispatch_info.method_load_kind == |
| 6818 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6819 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6820 | } |
| 6821 | |
| 6822 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6823 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6824 | if (&outer_dex_file != invoke->GetTargetMethod().dex_file) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6825 | // Calls across dex files are more likely to exceed the available BL range, |
| 6826 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6827 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6828 | (desired_dispatch_info.method_load_kind == |
| 6829 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6830 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6831 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6832 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6833 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6834 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6835 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6836 | 0u |
| 6837 | }; |
| 6838 | } |
| 6839 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6840 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6841 | } |
| 6842 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6843 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6844 | Register temp) { |
| 6845 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6846 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6847 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6848 | return location.AsRegister<Register>(); |
| 6849 | } |
| 6850 | // For intrinsics we allow any location, so it may be on the stack. |
| 6851 | if (!location.IsRegister()) { |
| 6852 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6853 | return temp; |
| 6854 | } |
| 6855 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6856 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6857 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6858 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6859 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6860 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6861 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6862 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6863 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6864 | return temp; |
| 6865 | } |
| 6866 | return location.AsRegister<Register>(); |
| 6867 | } |
| 6868 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6869 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6870 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6871 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6872 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6873 | // LR = code address from literal pool with link-time patch. |
| 6874 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6875 | break; |
| 6876 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6877 | // LR = invoke->GetDirectCodePtr(); |
| 6878 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6879 | break; |
| 6880 | default: |
| 6881 | break; |
| 6882 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6883 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6884 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6885 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6886 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 6887 | uint32_t offset = |
| 6888 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6889 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6890 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6891 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6892 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6893 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6894 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6895 | break; |
| 6896 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6897 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6898 | break; |
| 6899 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6900 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6901 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6902 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6903 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6904 | HArmDexCacheArraysBase* base = |
| 6905 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6906 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6907 | temp.AsRegister<Register>()); |
| 6908 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6909 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6910 | break; |
| 6911 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6912 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6913 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6914 | Register method_reg; |
| 6915 | Register reg = temp.AsRegister<Register>(); |
| 6916 | if (current_method.IsRegister()) { |
| 6917 | method_reg = current_method.AsRegister<Register>(); |
| 6918 | } else { |
| 6919 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6920 | DCHECK(!current_method.IsValid()); |
| 6921 | method_reg = reg; |
| 6922 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6923 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6924 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6925 | __ LoadFromOffset(kLoadWord, |
| 6926 | reg, |
| 6927 | method_reg, |
| 6928 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6929 | // temp = temp[index_in_cache]; |
| 6930 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6931 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6932 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6933 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6934 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6935 | } |
| 6936 | |
| 6937 | switch (invoke->GetCodePtrLocation()) { |
| 6938 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6939 | __ bl(GetFrameEntryLabel()); |
| 6940 | break; |
| 6941 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6942 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 6943 | invoke->GetTargetMethod().dex_method_index); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6944 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6945 | // Arbitrarily branch to the BL itself, override at link time. |
| 6946 | __ bl(&relative_call_patches_.back().label); |
| 6947 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6948 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6949 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6950 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6951 | // LR() |
| 6952 | __ blx(LR); |
| 6953 | break; |
| 6954 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6955 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6956 | __ LoadFromOffset( |
| 6957 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6958 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6959 | // LR() |
| 6960 | __ blx(LR); |
| 6961 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6962 | } |
| 6963 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6964 | DCHECK(!IsLeafMethod()); |
| 6965 | } |
| 6966 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6967 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6968 | Register temp = temp_location.AsRegister<Register>(); |
| 6969 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6970 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6971 | |
| 6972 | // Use the calling convention instead of the location of the receiver, as |
| 6973 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6974 | // slow path, the arguments have been moved to the right place, so here we are |
| 6975 | // guaranteed that the receiver is the first register of the calling convention. |
| 6976 | InvokeDexCallingConvention calling_convention; |
| 6977 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6978 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6979 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6980 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6981 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6982 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6983 | // emit a read barrier for the previous class reference load. |
| 6984 | // However this is not required in practice, as this is an |
| 6985 | // intermediate/temporary reference and because the current |
| 6986 | // concurrent copying collector keeps the from-space memory |
| 6987 | // intact/accessible until the end of the marking phase (the |
| 6988 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6989 | __ MaybeUnpoisonHeapReference(temp); |
| 6990 | // temp = temp->GetMethodAt(method_offset); |
| 6991 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6992 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6993 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6994 | // LR = temp->GetEntryPoint(); |
| 6995 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6996 | // LR(); |
| 6997 | __ blx(LR); |
| 6998 | } |
| 6999 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7000 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 7001 | const DexFile& dex_file, uint32_t string_index) { |
| 7002 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 7003 | } |
| 7004 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7005 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 7006 | const DexFile& dex_file, uint32_t type_index) { |
| 7007 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 7008 | } |
| 7009 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7010 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7011 | const DexFile& dex_file, uint32_t element_offset) { |
| 7012 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7013 | } |
| 7014 | |
| 7015 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7016 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7017 | patches->emplace_back(dex_file, offset_or_index); |
| 7018 | return &patches->back(); |
| 7019 | } |
| 7020 | |
| 7021 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 7022 | uint32_t string_index) { |
| 7023 | return boot_image_string_patches_.GetOrCreate( |
| 7024 | StringReference(&dex_file, string_index), |
| 7025 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7026 | } |
| 7027 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7028 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 7029 | uint32_t type_index) { |
| 7030 | return boot_image_type_patches_.GetOrCreate( |
| 7031 | TypeReference(&dex_file, type_index), |
| 7032 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7033 | } |
| 7034 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7035 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7036 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7037 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7038 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7039 | } |
| 7040 | |
| 7041 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 7042 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 7043 | } |
| 7044 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7045 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7046 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7047 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7048 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7049 | for (const PcRelativePatchInfo& info : infos) { |
| 7050 | const DexFile& dex_file = info.target_dex_file; |
| 7051 | size_t offset_or_index = info.offset_or_index; |
| 7052 | DCHECK(info.add_pc_label.IsBound()); |
| 7053 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7054 | // Add MOVW patch. |
| 7055 | DCHECK(info.movw_label.IsBound()); |
| 7056 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7057 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7058 | // Add MOVT patch. |
| 7059 | DCHECK(info.movt_label.IsBound()); |
| 7060 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7061 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7062 | } |
| 7063 | } |
| 7064 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7065 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7066 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7067 | size_t size = |
| 7068 | method_patches_.size() + |
| 7069 | call_patches_.size() + |
| 7070 | relative_call_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7071 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7072 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7073 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7074 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7075 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7076 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7077 | linker_patches->reserve(size); |
| 7078 | for (const auto& entry : method_patches_) { |
| 7079 | const MethodReference& target_method = entry.first; |
| 7080 | Literal* literal = entry.second; |
| 7081 | DCHECK(literal->GetLabel()->IsBound()); |
| 7082 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7083 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 7084 | target_method.dex_file, |
| 7085 | target_method.dex_method_index)); |
| 7086 | } |
| 7087 | for (const auto& entry : call_patches_) { |
| 7088 | const MethodReference& target_method = entry.first; |
| 7089 | Literal* literal = entry.second; |
| 7090 | DCHECK(literal->GetLabel()->IsBound()); |
| 7091 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7092 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 7093 | target_method.dex_file, |
| 7094 | target_method.dex_method_index)); |
| 7095 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7096 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7097 | uint32_t literal_offset = info.label.Position(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7098 | linker_patches->push_back( |
| 7099 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7100 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7101 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7102 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7103 | for (const auto& entry : boot_image_string_patches_) { |
| 7104 | const StringReference& target_string = entry.first; |
| 7105 | Literal* literal = entry.second; |
| 7106 | DCHECK(literal->GetLabel()->IsBound()); |
| 7107 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7108 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7109 | target_string.dex_file, |
| 7110 | target_string.string_index)); |
| 7111 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7112 | if (!GetCompilerOptions().IsBootImage()) { |
| 7113 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7114 | linker_patches); |
| 7115 | } else { |
| 7116 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7117 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7118 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7119 | for (const auto& entry : boot_image_type_patches_) { |
| 7120 | const TypeReference& target_type = entry.first; |
| 7121 | Literal* literal = entry.second; |
| 7122 | DCHECK(literal->GetLabel()->IsBound()); |
| 7123 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7124 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7125 | target_type.dex_file, |
| 7126 | target_type.type_index)); |
| 7127 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7128 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7129 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7130 | for (const auto& entry : boot_image_address_patches_) { |
| 7131 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7132 | Literal* literal = entry.second; |
| 7133 | DCHECK(literal->GetLabel()->IsBound()); |
| 7134 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7135 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7136 | } |
| 7137 | } |
| 7138 | |
| 7139 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7140 | return map->GetOrCreate( |
| 7141 | value, |
| 7142 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7143 | } |
| 7144 | |
| 7145 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7146 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7147 | return map->GetOrCreate( |
| 7148 | target_method, |
| 7149 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 7153 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 7154 | } |
| 7155 | |
| 7156 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 7157 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 7158 | } |
| 7159 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7160 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7161 | LocationSummary* locations = |
| 7162 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7163 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7164 | Location::RequiresRegister()); |
| 7165 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7166 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7167 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7168 | } |
| 7169 | |
| 7170 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7171 | LocationSummary* locations = instr->GetLocations(); |
| 7172 | Register res = locations->Out().AsRegister<Register>(); |
| 7173 | Register accumulator = |
| 7174 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7175 | Register mul_left = |
| 7176 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7177 | Register mul_right = |
| 7178 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7179 | |
| 7180 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7181 | __ mla(res, mul_left, mul_right, accumulator); |
| 7182 | } else { |
| 7183 | __ mls(res, mul_left, mul_right, accumulator); |
| 7184 | } |
| 7185 | } |
| 7186 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7187 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7188 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7189 | LOG(FATAL) << "Unreachable"; |
| 7190 | } |
| 7191 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7192 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7193 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7194 | LOG(FATAL) << "Unreachable"; |
| 7195 | } |
| 7196 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7197 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7198 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7199 | LocationSummary* locations = |
| 7200 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7201 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7202 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7203 | codegen_->GetAssembler()->IsThumb()) { |
| 7204 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7205 | if (switch_instr->GetStartValue() != 0) { |
| 7206 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7207 | } |
| 7208 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7212 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7213 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7214 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7215 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7216 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7217 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7218 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7219 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7220 | Register temp_reg = IP; |
| 7221 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7222 | // the immediate, because IP is used as the destination register. For the other |
| 7223 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7224 | // and they can be encoded in the instruction without making use of IP register. |
| 7225 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7226 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7227 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7228 | // Jump to successors[0] if value == lower_bound. |
| 7229 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7230 | int32_t last_index = 0; |
| 7231 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7232 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7233 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7234 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7235 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7236 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7237 | } |
| 7238 | if (num_entries - last_index == 2) { |
| 7239 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7240 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7241 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7242 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7243 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7244 | // And the default for any other value. |
| 7245 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7246 | __ b(codegen_->GetLabelOf(default_block)); |
| 7247 | } |
| 7248 | } else { |
| 7249 | // Create a table lookup. |
| 7250 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7251 | |
| 7252 | // Materialize a pointer to the switch table |
| 7253 | std::vector<Label*> labels(num_entries); |
| 7254 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7255 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7256 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7257 | } |
| 7258 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7259 | |
| 7260 | // Remove the bias. |
| 7261 | Register key_reg; |
| 7262 | if (lower_bound != 0) { |
| 7263 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7264 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7265 | } else { |
| 7266 | key_reg = value_reg; |
| 7267 | } |
| 7268 | |
| 7269 | // Check whether the value is in the table, jump to default block if not. |
| 7270 | __ CmpConstant(key_reg, num_entries - 1); |
| 7271 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7272 | |
| 7273 | // Load the displacement from the table. |
| 7274 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7275 | |
| 7276 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7277 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7278 | } |
| 7279 | } |
| 7280 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7281 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7282 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7283 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7284 | } |
| 7285 | |
| 7286 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7287 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7288 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7289 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7290 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7291 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7292 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7293 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7294 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7295 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7296 | } |
| 7297 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7298 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7299 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7300 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7301 | return; |
| 7302 | } |
| 7303 | |
| 7304 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7305 | |
| 7306 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7307 | if (return_loc.Equals(trg)) { |
| 7308 | return; |
| 7309 | } |
| 7310 | |
| 7311 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7312 | // with the last branch. |
| 7313 | if (type == Primitive::kPrimLong) { |
| 7314 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7315 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7316 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7317 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7318 | } else if (type == Primitive::kPrimDouble) { |
| 7319 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7320 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7321 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7322 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7323 | } else { |
| 7324 | // Let the parallel move resolver take care of all of this. |
| 7325 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7326 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7327 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7328 | } |
| 7329 | } |
| 7330 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7331 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7332 | LocationSummary* locations = |
| 7333 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7335 | locations->SetOut(Location::RequiresRegister()); |
| 7336 | } |
| 7337 | |
| 7338 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7339 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7340 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7341 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7342 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7343 | __ LoadFromOffset(kLoadWord, |
| 7344 | locations->Out().AsRegister<Register>(), |
| 7345 | locations->InAt(0).AsRegister<Register>(), |
| 7346 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7347 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7348 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7349 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7350 | __ LoadFromOffset(kLoadWord, |
| 7351 | locations->Out().AsRegister<Register>(), |
| 7352 | locations->InAt(0).AsRegister<Register>(), |
| 7353 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7354 | __ LoadFromOffset(kLoadWord, |
| 7355 | locations->Out().AsRegister<Register>(), |
| 7356 | locations->Out().AsRegister<Register>(), |
| 7357 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7358 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7359 | } |
| 7360 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7361 | #undef __ |
| 7362 | #undef QUICK_ENTRY_POINT |
| 7363 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7364 | } // namespace arm |
| 7365 | } // namespace art |