Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 66 | static constexpr int kRegListThreshold = 4; |
| 67 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 68 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 69 | // for each live D registers they treat two corresponding S registers as live ones. |
| 70 | // |
| 71 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 72 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 73 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 74 | // - decreasing code size |
| 75 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 76 | // restored and then used in regular non SlowPath code as D register. |
| 77 | // |
| 78 | // For the following example (v means the S register is live): |
| 79 | // D names: | D0 | D1 | D2 | D4 | ... |
| 80 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 81 | // Live? | | v | v | v | v | v | v | | ... |
| 82 | // |
| 83 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 84 | // as D registers. |
| 85 | static size_t SaveContiguousSRegisterList(size_t first, |
| 86 | size_t last, |
| 87 | CodeGenerator* codegen, |
| 88 | size_t stack_offset) { |
| 89 | DCHECK_LE(first, last); |
| 90 | if ((first == last) && (first == 0)) { |
| 91 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 92 | return stack_offset; |
| 93 | } |
| 94 | if (first % 2 == 1) { |
| 95 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 96 | } |
| 97 | |
| 98 | bool save_last = false; |
| 99 | if (last % 2 == 0) { |
| 100 | save_last = true; |
| 101 | --last; |
| 102 | } |
| 103 | |
| 104 | if (first < last) { |
| 105 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 106 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 107 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 108 | |
| 109 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame^] | 110 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 111 | } else if (number_of_d_regs > 1) { |
| 112 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 113 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 114 | } |
| 115 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 116 | } |
| 117 | |
| 118 | if (save_last) { |
| 119 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 120 | } |
| 121 | |
| 122 | return stack_offset; |
| 123 | } |
| 124 | |
| 125 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 126 | size_t last, |
| 127 | CodeGenerator* codegen, |
| 128 | size_t stack_offset) { |
| 129 | DCHECK_LE(first, last); |
| 130 | if ((first == last) && (first == 0)) { |
| 131 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 132 | return stack_offset; |
| 133 | } |
| 134 | if (first % 2 == 1) { |
| 135 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 136 | } |
| 137 | |
| 138 | bool restore_last = false; |
| 139 | if (last % 2 == 0) { |
| 140 | restore_last = true; |
| 141 | --last; |
| 142 | } |
| 143 | |
| 144 | if (first < last) { |
| 145 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 146 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 147 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 148 | if (number_of_d_regs == 1) { |
| 149 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 150 | } else if (number_of_d_regs > 1) { |
| 151 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 152 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 153 | } |
| 154 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 155 | } |
| 156 | |
| 157 | if (restore_last) { |
| 158 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 159 | } |
| 160 | |
| 161 | return stack_offset; |
| 162 | } |
| 163 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 164 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 165 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 166 | size_t orig_offset = stack_offset; |
| 167 | |
| 168 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 169 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 170 | // If the register holds an object, update the stack mask. |
| 171 | if (locations->RegisterContainsObject(i)) { |
| 172 | locations->SetStackBit(stack_offset / kVRegSize); |
| 173 | } |
| 174 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 175 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 176 | saved_core_stack_offsets_[i] = stack_offset; |
| 177 | stack_offset += kArmWordSize; |
| 178 | } |
| 179 | |
| 180 | int reg_num = POPCOUNT(core_spills); |
| 181 | if (reg_num != 0) { |
| 182 | if (reg_num > kRegListThreshold) { |
| 183 | __ StoreList(RegList(core_spills), orig_offset); |
| 184 | } else { |
| 185 | stack_offset = orig_offset; |
| 186 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 187 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 192 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 193 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 197 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 199 | |
| 200 | stack_offset = orig_offset; |
| 201 | while (fp_spills != 0u) { |
| 202 | uint32_t begin = CTZ(fp_spills); |
| 203 | uint32_t tmp = fp_spills + (1u << begin); |
| 204 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 205 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 206 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 207 | } |
| 208 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 212 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 213 | size_t orig_offset = stack_offset; |
| 214 | |
| 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 218 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 219 | stack_offset += kArmWordSize; |
| 220 | } |
| 221 | |
| 222 | int reg_num = POPCOUNT(core_spills); |
| 223 | if (reg_num != 0) { |
| 224 | if (reg_num > kRegListThreshold) { |
| 225 | __ LoadList(RegList(core_spills), orig_offset); |
| 226 | } else { |
| 227 | stack_offset = orig_offset; |
| 228 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 229 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 234 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 235 | while (fp_spills != 0u) { |
| 236 | uint32_t begin = CTZ(fp_spills); |
| 237 | uint32_t tmp = fp_spills + (1u << begin); |
| 238 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 239 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 240 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 241 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 246 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 251 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 252 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 253 | // Live registers will be restored in the catch block if caught. |
| 254 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 255 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 257 | instruction_, |
| 258 | instruction_->GetDexPc(), |
| 259 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 260 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 263 | bool IsFatal() const OVERRIDE { return true; } |
| 264 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 265 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 266 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 267 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 269 | }; |
| 270 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 271 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 272 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 273 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 276 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 277 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 278 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 282 | bool IsFatal() const OVERRIDE { return true; } |
| 283 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 285 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 286 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 288 | }; |
| 289 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 290 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 291 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 293 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 296 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 297 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 298 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 300 | if (successor_ == nullptr) { |
| 301 | __ b(GetReturnLabel()); |
| 302 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 303 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 304 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 307 | Label* GetReturnLabel() { |
| 308 | DCHECK(successor_ == nullptr); |
| 309 | return &return_label_; |
| 310 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 311 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 312 | HBasicBlock* GetSuccessor() const { |
| 313 | return successor_; |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 317 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 318 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 319 | // If not null, the block to branch to after the suspend check. |
| 320 | HBasicBlock* const successor_; |
| 321 | |
| 322 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 323 | Label return_label_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 329 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 330 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | LocationSummary* locations = instruction_->GetLocations(); |
| 336 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 337 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 338 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 339 | // Live registers will be restored in the catch block if caught. |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 341 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 342 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 343 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 344 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 346 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 351 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 352 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 353 | ? kQuickThrowStringBounds |
| 354 | : kQuickThrowArrayBounds; |
| 355 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return true; } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 364 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 366 | }; |
| 367 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 368 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 369 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 370 | LoadClassSlowPathARM(HLoadClass* cls, |
| 371 | HInstruction* at, |
| 372 | uint32_t dex_pc, |
| 373 | bool do_clinit) |
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())); |
| 432 | |
| 433 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 434 | __ Bind(GetEntryLabel()); |
| 435 | SaveLiveRegisters(codegen, locations); |
| 436 | |
| 437 | InvokeRuntimeCallingConvention calling_convention; |
| 438 | HLoadString* load = instruction_->AsLoadString(); |
| 439 | const uint32_t string_index = load->GetStringIndex(); |
| 440 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
| 441 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 442 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 443 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 444 | |
| 445 | RestoreLiveRegisters(codegen, locations); |
| 446 | |
| 447 | // Store the resolved String to the BSS entry. |
| 448 | // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the |
| 449 | // .bss entry address in the fast path, so that we can avoid another calculation here. |
| 450 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 451 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 452 | __ BindTrackedLabel(&labels->movw_label); |
| 453 | __ movw(IP, /* placeholder */ 0u); |
| 454 | __ BindTrackedLabel(&labels->movt_label); |
| 455 | __ movt(IP, /* placeholder */ 0u); |
| 456 | __ BindTrackedLabel(&labels->add_pc_label); |
| 457 | __ add(IP, IP, ShifterOperand(PC)); |
| 458 | __ str(locations->Out().AsRegister<Register>(), Address(IP)); |
| 459 | |
| 460 | __ b(GetExitLabel()); |
| 461 | } |
| 462 | |
| 463 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 464 | |
| 465 | private: |
| 466 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 467 | }; |
| 468 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 469 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 470 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 471 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 472 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 473 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 474 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 475 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 476 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 477 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 478 | DCHECK(instruction_->IsCheckCast() |
| 479 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 480 | |
| 481 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 482 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 483 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 484 | if (!is_fatal_) { |
| 485 | SaveLiveRegisters(codegen, locations); |
| 486 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 487 | |
| 488 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 489 | // move resolver. |
| 490 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 491 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 492 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 493 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 494 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 495 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 496 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 497 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 498 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 499 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 500 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 501 | instruction_, |
| 502 | instruction_->GetDexPc(), |
| 503 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 504 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 505 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 506 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 507 | } else { |
| 508 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 509 | arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 510 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 511 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 512 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 513 | if (!is_fatal_) { |
| 514 | RestoreLiveRegisters(codegen, locations); |
| 515 | __ b(GetExitLabel()); |
| 516 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 519 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 520 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 521 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 522 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 523 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 524 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 525 | |
| 526 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 527 | }; |
| 528 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 529 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 530 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 531 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 532 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 533 | |
| 534 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 535 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 536 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 537 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 538 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 541 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 542 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 543 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 544 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 545 | }; |
| 546 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 547 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 548 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 549 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 550 | |
| 551 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 552 | LocationSummary* locations = instruction_->GetLocations(); |
| 553 | __ Bind(GetEntryLabel()); |
| 554 | SaveLiveRegisters(codegen, locations); |
| 555 | |
| 556 | InvokeRuntimeCallingConvention calling_convention; |
| 557 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 558 | parallel_move.AddMove( |
| 559 | locations->InAt(0), |
| 560 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 561 | Primitive::kPrimNot, |
| 562 | nullptr); |
| 563 | parallel_move.AddMove( |
| 564 | locations->InAt(1), |
| 565 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 566 | Primitive::kPrimInt, |
| 567 | nullptr); |
| 568 | parallel_move.AddMove( |
| 569 | locations->InAt(2), |
| 570 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 571 | Primitive::kPrimNot, |
| 572 | nullptr); |
| 573 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 574 | |
| 575 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 576 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 577 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 578 | RestoreLiveRegisters(codegen, locations); |
| 579 | __ b(GetExitLabel()); |
| 580 | } |
| 581 | |
| 582 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 583 | |
| 584 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 585 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 586 | }; |
| 587 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 588 | // Slow path marking an object during a read barrier. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 589 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 590 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 591 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 592 | : SlowPathCodeARM(instruction), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 593 | DCHECK(kEmitCompilerReadBarrier); |
| 594 | } |
| 595 | |
| 596 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 597 | |
| 598 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 599 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 600 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 601 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 602 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 603 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 604 | instruction_->IsStaticFieldGet() || |
| 605 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 606 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 607 | instruction_->IsLoadClass() || |
| 608 | instruction_->IsLoadString() || |
| 609 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 610 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 611 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 612 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 613 | << "Unexpected instruction in read barrier marking slow path: " |
| 614 | << instruction_->DebugName(); |
| 615 | |
| 616 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 617 | // No need to save live registers; it's taken care of by the |
| 618 | // entrypoint. Also, there is no need to update the stack mask, |
| 619 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 620 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 621 | DCHECK_NE(reg, SP); |
| 622 | DCHECK_NE(reg, LR); |
| 623 | DCHECK_NE(reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 624 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 625 | // as a temporary, it cannot be the entry point's input/output. |
| 626 | DCHECK_NE(reg, IP); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 627 | DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg; |
| 628 | // "Compact" slow path, saving two moves. |
| 629 | // |
| 630 | // Instead of using the standard runtime calling convention (input |
| 631 | // and output in R0): |
| 632 | // |
| 633 | // R0 <- obj |
| 634 | // R0 <- ReadBarrierMark(R0) |
| 635 | // obj <- R0 |
| 636 | // |
| 637 | // we just use rX (the register holding `obj`) as input and output |
| 638 | // of a dedicated entrypoint: |
| 639 | // |
| 640 | // rX <- ReadBarrierMarkRegX(rX) |
| 641 | // |
| 642 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 643 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 644 | // This runtime call does not require a stack map. |
| 645 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 646 | __ b(GetExitLabel()); |
| 647 | } |
| 648 | |
| 649 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 650 | const Location obj_; |
| 651 | |
| 652 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 653 | }; |
| 654 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 655 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 656 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 657 | public: |
| 658 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 659 | Location out, |
| 660 | Location ref, |
| 661 | Location obj, |
| 662 | uint32_t offset, |
| 663 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 664 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 665 | out_(out), |
| 666 | ref_(ref), |
| 667 | obj_(obj), |
| 668 | offset_(offset), |
| 669 | index_(index) { |
| 670 | DCHECK(kEmitCompilerReadBarrier); |
| 671 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 672 | // has been overwritten by (or after) the heap object reference load |
| 673 | // to be instrumented, e.g.: |
| 674 | // |
| 675 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 676 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 677 | // |
| 678 | // In that case, we have lost the information about the original |
| 679 | // object, and the emitted read barrier cannot work properly. |
| 680 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 681 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 682 | } |
| 683 | |
| 684 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 685 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 686 | LocationSummary* locations = instruction_->GetLocations(); |
| 687 | Register reg_out = out_.AsRegister<Register>(); |
| 688 | DCHECK(locations->CanCall()); |
| 689 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 690 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 691 | instruction_->IsStaticFieldGet() || |
| 692 | instruction_->IsArrayGet() || |
| 693 | instruction_->IsInstanceOf() || |
| 694 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 695 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 696 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 697 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 698 | |
| 699 | __ Bind(GetEntryLabel()); |
| 700 | SaveLiveRegisters(codegen, locations); |
| 701 | |
| 702 | // We may have to change the index's value, but as `index_` is a |
| 703 | // constant member (like other "inputs" of this slow path), |
| 704 | // introduce a copy of it, `index`. |
| 705 | Location index = index_; |
| 706 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 707 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 708 | if (instruction_->IsArrayGet()) { |
| 709 | // Compute the actual memory offset and store it in `index`. |
| 710 | Register index_reg = index_.AsRegister<Register>(); |
| 711 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 712 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 713 | // We are about to change the value of `index_reg` (see the |
| 714 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 715 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 716 | // not been saved by the previous call to |
| 717 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 718 | // callee-save register -- |
| 719 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 720 | // callee-save registers, as it has been designed with the |
| 721 | // assumption that callee-save registers are supposed to be |
| 722 | // handled by the called function. So, as a callee-save |
| 723 | // register, `index_reg` _would_ eventually be saved onto |
| 724 | // the stack, but it would be too late: we would have |
| 725 | // changed its value earlier. Therefore, we manually save |
| 726 | // it here into another freely available register, |
| 727 | // `free_reg`, chosen of course among the caller-save |
| 728 | // registers (as a callee-save `free_reg` register would |
| 729 | // exhibit the same problem). |
| 730 | // |
| 731 | // Note we could have requested a temporary register from |
| 732 | // the register allocator instead; but we prefer not to, as |
| 733 | // this is a slow path, and we know we can find a |
| 734 | // caller-save register that is available. |
| 735 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 736 | __ Mov(free_reg, index_reg); |
| 737 | index_reg = free_reg; |
| 738 | index = Location::RegisterLocation(index_reg); |
| 739 | } else { |
| 740 | // The initial register stored in `index_` has already been |
| 741 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 742 | // (as it is not a callee-save register), so we can freely |
| 743 | // use it. |
| 744 | } |
| 745 | // Shifting the index value contained in `index_reg` by the scale |
| 746 | // factor (2) cannot overflow in practice, as the runtime is |
| 747 | // unable to allocate object arrays with a size larger than |
| 748 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 749 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 750 | static_assert( |
| 751 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 752 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 753 | __ AddConstant(index_reg, index_reg, offset_); |
| 754 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 755 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 756 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 757 | // (as in the case of ArrayGet), as it is actually an offset |
| 758 | // to an object field within an object. |
| 759 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 760 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 761 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 762 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 763 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 764 | DCHECK_EQ(offset_, 0U); |
| 765 | DCHECK(index_.IsRegisterPair()); |
| 766 | // UnsafeGet's offset location is a register pair, the low |
| 767 | // part contains the correct offset. |
| 768 | index = index_.ToLow(); |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | // We're moving two or three locations to locations that could |
| 773 | // overlap, so we need a parallel move resolver. |
| 774 | InvokeRuntimeCallingConvention calling_convention; |
| 775 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 776 | parallel_move.AddMove(ref_, |
| 777 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 778 | Primitive::kPrimNot, |
| 779 | nullptr); |
| 780 | parallel_move.AddMove(obj_, |
| 781 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 782 | Primitive::kPrimNot, |
| 783 | nullptr); |
| 784 | if (index.IsValid()) { |
| 785 | parallel_move.AddMove(index, |
| 786 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 787 | Primitive::kPrimInt, |
| 788 | nullptr); |
| 789 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 790 | } else { |
| 791 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 792 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 793 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 794 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 795 | CheckEntrypointTypes< |
| 796 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 797 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 798 | |
| 799 | RestoreLiveRegisters(codegen, locations); |
| 800 | __ b(GetExitLabel()); |
| 801 | } |
| 802 | |
| 803 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 804 | |
| 805 | private: |
| 806 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 807 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 808 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 809 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 810 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 811 | return static_cast<Register>(i); |
| 812 | } |
| 813 | } |
| 814 | // We shall never fail to find a free caller-save register, as |
| 815 | // there are more than two core caller-save registers on ARM |
| 816 | // (meaning it is possible to find one which is different from |
| 817 | // `ref` and `obj`). |
| 818 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 819 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 820 | UNREACHABLE(); |
| 821 | } |
| 822 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 823 | const Location out_; |
| 824 | const Location ref_; |
| 825 | const Location obj_; |
| 826 | const uint32_t offset_; |
| 827 | // An additional location containing an index to an array. |
| 828 | // Only used for HArrayGet and the UnsafeGetObject & |
| 829 | // UnsafeGetObjectVolatile intrinsics. |
| 830 | const Location index_; |
| 831 | |
| 832 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 833 | }; |
| 834 | |
| 835 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 836 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 837 | public: |
| 838 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 839 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 840 | DCHECK(kEmitCompilerReadBarrier); |
| 841 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 842 | |
| 843 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 844 | LocationSummary* locations = instruction_->GetLocations(); |
| 845 | Register reg_out = out_.AsRegister<Register>(); |
| 846 | DCHECK(locations->CanCall()); |
| 847 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 848 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 849 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 850 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 851 | |
| 852 | __ Bind(GetEntryLabel()); |
| 853 | SaveLiveRegisters(codegen, locations); |
| 854 | |
| 855 | InvokeRuntimeCallingConvention calling_convention; |
| 856 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 857 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 858 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 859 | instruction_, |
| 860 | instruction_->GetDexPc(), |
| 861 | this); |
| 862 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 863 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 864 | |
| 865 | RestoreLiveRegisters(codegen, locations); |
| 866 | __ b(GetExitLabel()); |
| 867 | } |
| 868 | |
| 869 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 870 | |
| 871 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 872 | const Location out_; |
| 873 | const Location root_; |
| 874 | |
| 875 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 876 | }; |
| 877 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 878 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 879 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 880 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 881 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 882 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 883 | switch (cond) { |
| 884 | case kCondEQ: return EQ; |
| 885 | case kCondNE: return NE; |
| 886 | case kCondLT: return LT; |
| 887 | case kCondLE: return LE; |
| 888 | case kCondGT: return GT; |
| 889 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 890 | case kCondB: return LO; |
| 891 | case kCondBE: return LS; |
| 892 | case kCondA: return HI; |
| 893 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 894 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 895 | LOG(FATAL) << "Unreachable"; |
| 896 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 899 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 900 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 901 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 902 | case kCondEQ: return EQ; |
| 903 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 904 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 905 | case kCondLT: return LO; |
| 906 | case kCondLE: return LS; |
| 907 | case kCondGT: return HI; |
| 908 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 909 | // Unsigned remain unchanged. |
| 910 | case kCondB: return LO; |
| 911 | case kCondBE: return LS; |
| 912 | case kCondA: return HI; |
| 913 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 914 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 915 | LOG(FATAL) << "Unreachable"; |
| 916 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 919 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 920 | // The ARM condition codes can express all the necessary branches, see the |
| 921 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 922 | // There is no dex instruction or HIR that would need the missing conditions |
| 923 | // "equal or unordered" or "not equal". |
| 924 | switch (cond) { |
| 925 | case kCondEQ: return EQ; |
| 926 | case kCondNE: return NE /* unordered */; |
| 927 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 928 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 929 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 930 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 931 | default: |
| 932 | LOG(FATAL) << "UNREACHABLE"; |
| 933 | UNREACHABLE(); |
| 934 | } |
| 935 | } |
| 936 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 937 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 938 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 942 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 943 | } |
| 944 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 945 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 946 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 947 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 948 | } |
| 949 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 950 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 951 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 952 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 955 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 956 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 957 | return kArmWordSize; |
| 958 | } |
| 959 | |
| 960 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 961 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 962 | return kArmWordSize; |
| 963 | } |
| 964 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 965 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 966 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 967 | const CompilerOptions& compiler_options, |
| 968 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 969 | : CodeGenerator(graph, |
| 970 | kNumberOfCoreRegisters, |
| 971 | kNumberOfSRegisters, |
| 972 | kNumberOfRegisterPairs, |
| 973 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 974 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 975 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 976 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 977 | compiler_options, |
| 978 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 979 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 980 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 981 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 982 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 983 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 984 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 985 | uint32_literals_(std::less<uint32_t>(), |
| 986 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 987 | method_patches_(MethodReferenceComparator(), |
| 988 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 989 | call_patches_(MethodReferenceComparator(), |
| 990 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 991 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 992 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 993 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 994 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 995 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 996 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 997 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 998 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 999 | boot_image_address_patches_(std::less<uint32_t>(), |
| 1000 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1001 | // Always save the LR register to mimic Quick. |
| 1002 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1005 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1006 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1007 | __ FinalizeCode(); |
| 1008 | |
| 1009 | // Adjust native pc offsets in stack maps. |
| 1010 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 1011 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 1012 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1013 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1014 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1015 | // Adjust pc offsets for the disassembly information. |
| 1016 | if (disasm_info_ != nullptr) { |
| 1017 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1018 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1019 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1020 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1021 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1022 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1023 | } |
| 1024 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1025 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1026 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1027 | } |
| 1028 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1029 | |
| 1030 | CodeGenerator::Finalize(allocator); |
| 1031 | } |
| 1032 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1033 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1034 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1035 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1036 | |
| 1037 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1038 | blocked_core_registers_[SP] = true; |
| 1039 | blocked_core_registers_[LR] = true; |
| 1040 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1041 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1042 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1043 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1044 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1045 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1046 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1047 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1048 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1049 | // Stubs do not save callee-save floating point registers. If the graph |
| 1050 | // is debuggable, we need to deal with these registers differently. For |
| 1051 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1052 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1053 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1054 | } |
| 1055 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1056 | |
| 1057 | UpdateBlockedPairRegisters(); |
| 1058 | } |
| 1059 | |
| 1060 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 1061 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1062 | ArmManagedRegister current = |
| 1063 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1064 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 1065 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 1066 | blocked_register_pairs_[i] = true; |
| 1067 | } |
| 1068 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1069 | } |
| 1070 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1071 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1072 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1073 | assembler_(codegen->GetAssembler()), |
| 1074 | codegen_(codegen) {} |
| 1075 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1076 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1077 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1078 | 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] | 1079 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1080 | // restore another arbitrary register. |
| 1081 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1082 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1083 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1084 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1085 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1086 | // but in the range. |
| 1087 | if (fpu_spill_mask_ != 0) { |
| 1088 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1089 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1090 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1091 | fpu_spill_mask_ |= (1 << i); |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1096 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1097 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1101 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1104 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1105 | bool skip_overflow_check = |
| 1106 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1107 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1108 | __ Bind(&frame_entry_label_); |
| 1109 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1110 | if (HasEmptyFrame()) { |
| 1111 | return; |
| 1112 | } |
| 1113 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1114 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1115 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1116 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1117 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1120 | __ PushList(core_spill_mask_); |
| 1121 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1122 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1123 | if (fpu_spill_mask_ != 0) { |
| 1124 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1125 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1126 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1127 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1128 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1129 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1130 | __ AddConstant(SP, -adjust); |
| 1131 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1132 | |
| 1133 | // Save the current method if we need it. Note that we do not |
| 1134 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1135 | // in the SSA graph. |
| 1136 | if (RequiresCurrentMethod()) { |
| 1137 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1138 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1142 | if (HasEmptyFrame()) { |
| 1143 | __ bx(LR); |
| 1144 | return; |
| 1145 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1146 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1147 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1148 | __ AddConstant(SP, adjust); |
| 1149 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1150 | if (fpu_spill_mask_ != 0) { |
| 1151 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1152 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1153 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1154 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1155 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1156 | // Pop LR into PC to return. |
| 1157 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1158 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1159 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1160 | __ cfi().RestoreState(); |
| 1161 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1164 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1165 | Label* label = GetLabelOf(block); |
| 1166 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1169 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1170 | switch (type) { |
| 1171 | case Primitive::kPrimBoolean: |
| 1172 | case Primitive::kPrimByte: |
| 1173 | case Primitive::kPrimChar: |
| 1174 | case Primitive::kPrimShort: |
| 1175 | case Primitive::kPrimInt: |
| 1176 | case Primitive::kPrimNot: { |
| 1177 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1178 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1179 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1180 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1181 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1182 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1183 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1184 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1186 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 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 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1190 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1191 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1192 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1193 | // Skip R1, and use R2_R3 instead. |
| 1194 | gp_index_++; |
| 1195 | index++; |
| 1196 | } |
| 1197 | } |
| 1198 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1199 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1200 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1201 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1202 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1203 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1204 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1205 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | case Primitive::kPrimFloat: { |
| 1210 | uint32_t stack_index = stack_index_++; |
| 1211 | if (float_index_ % 2 == 0) { |
| 1212 | float_index_ = std::max(double_index_, float_index_); |
| 1213 | } |
| 1214 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1215 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1216 | } else { |
| 1217 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | case Primitive::kPrimDouble: { |
| 1222 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1223 | uint32_t stack_index = stack_index_; |
| 1224 | stack_index_ += 2; |
| 1225 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1226 | uint32_t index = double_index_; |
| 1227 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1228 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1229 | calling_convention.GetFpuRegisterAt(index), |
| 1230 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1231 | DCHECK(ExpectedPairLayout(result)); |
| 1232 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1233 | } else { |
| 1234 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1238 | case Primitive::kPrimVoid: |
| 1239 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1240 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1241 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1242 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1243 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1244 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1245 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1246 | switch (type) { |
| 1247 | case Primitive::kPrimBoolean: |
| 1248 | case Primitive::kPrimByte: |
| 1249 | case Primitive::kPrimChar: |
| 1250 | case Primitive::kPrimShort: |
| 1251 | case Primitive::kPrimInt: |
| 1252 | case Primitive::kPrimNot: { |
| 1253 | return Location::RegisterLocation(R0); |
| 1254 | } |
| 1255 | |
| 1256 | case Primitive::kPrimFloat: { |
| 1257 | return Location::FpuRegisterLocation(S0); |
| 1258 | } |
| 1259 | |
| 1260 | case Primitive::kPrimLong: { |
| 1261 | return Location::RegisterPairLocation(R0, R1); |
| 1262 | } |
| 1263 | |
| 1264 | case Primitive::kPrimDouble: { |
| 1265 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1266 | } |
| 1267 | |
| 1268 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1269 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1270 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1271 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1272 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1275 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1276 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1277 | } |
| 1278 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1279 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1280 | if (source.Equals(destination)) { |
| 1281 | return; |
| 1282 | } |
| 1283 | if (destination.IsRegister()) { |
| 1284 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1285 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1286 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1287 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1288 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1289 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1290 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1291 | } else if (destination.IsFpuRegister()) { |
| 1292 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1293 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1294 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1295 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1296 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1297 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1298 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1299 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1300 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1301 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1302 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1303 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1304 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1305 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1306 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1307 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1308 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1314 | if (source.Equals(destination)) { |
| 1315 | return; |
| 1316 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1317 | if (destination.IsRegisterPair()) { |
| 1318 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1319 | EmitParallelMoves( |
| 1320 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1321 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1322 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1323 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1324 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1325 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1326 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1327 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1328 | } else if (source.IsFpuRegisterPair()) { |
| 1329 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1330 | destination.AsRegisterPairHigh<Register>(), |
| 1331 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1332 | } else { |
| 1333 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1334 | DCHECK(ExpectedPairLayout(destination)); |
| 1335 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1336 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1337 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1338 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1339 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1340 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1341 | SP, |
| 1342 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1343 | } else if (source.IsRegisterPair()) { |
| 1344 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1345 | source.AsRegisterPairLow<Register>(), |
| 1346 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1347 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1348 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1349 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1350 | } else { |
| 1351 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1352 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1353 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1354 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1355 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1356 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1357 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1358 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1359 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1360 | SP, destination.GetStackIndex()); |
| 1361 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1362 | } else if (source.IsFpuRegisterPair()) { |
| 1363 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1364 | SP, |
| 1365 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1366 | } else { |
| 1367 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1368 | EmitParallelMoves( |
| 1369 | Location::StackSlot(source.GetStackIndex()), |
| 1370 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1371 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1372 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1373 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1374 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1379 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1380 | DCHECK(location.IsRegister()); |
| 1381 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1382 | } |
| 1383 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1384 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1385 | HParallelMove move(GetGraph()->GetArena()); |
| 1386 | move.AddMove(src, dst, dst_type, nullptr); |
| 1387 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1391 | if (location.IsRegister()) { |
| 1392 | locations->AddTemp(location); |
| 1393 | } else if (location.IsRegisterPair()) { |
| 1394 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1395 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1396 | } else { |
| 1397 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1398 | } |
| 1399 | } |
| 1400 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1401 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1402 | HInstruction* instruction, |
| 1403 | uint32_t dex_pc, |
| 1404 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1405 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1406 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1407 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1408 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1409 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1412 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1413 | HInstruction* instruction, |
| 1414 | SlowPathCode* slow_path) { |
| 1415 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1416 | GenerateInvokeRuntime(entry_point_offset); |
| 1417 | } |
| 1418 | |
| 1419 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1420 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1421 | __ blx(LR); |
| 1422 | } |
| 1423 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1424 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1425 | DCHECK(!successor->IsExitBlock()); |
| 1426 | |
| 1427 | HBasicBlock* block = got->GetBlock(); |
| 1428 | HInstruction* previous = got->GetPrevious(); |
| 1429 | |
| 1430 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1431 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1432 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1433 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1434 | return; |
| 1435 | } |
| 1436 | |
| 1437 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1438 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1439 | } |
| 1440 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1441 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1445 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1446 | got->SetLocations(nullptr); |
| 1447 | } |
| 1448 | |
| 1449 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1450 | HandleGoto(got, got->GetSuccessor()); |
| 1451 | } |
| 1452 | |
| 1453 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1454 | try_boundary->SetLocations(nullptr); |
| 1455 | } |
| 1456 | |
| 1457 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1458 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1459 | if (!successor->IsExitBlock()) { |
| 1460 | HandleGoto(try_boundary, successor); |
| 1461 | } |
| 1462 | } |
| 1463 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1464 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1465 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1468 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1471 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1472 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1473 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1474 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1475 | if (rhs_loc.IsConstant()) { |
| 1476 | // 0.0 is the only immediate that can be encoded directly in |
| 1477 | // a VCMP instruction. |
| 1478 | // |
| 1479 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1480 | // specify that in a floating-point comparison, positive zero |
| 1481 | // and negative zero are considered equal, so we can use the |
| 1482 | // literal 0.0 for both cases here. |
| 1483 | // |
| 1484 | // Note however that some methods (Float.equal, Float.compare, |
| 1485 | // Float.compareTo, Double.equal, Double.compare, |
| 1486 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1487 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1488 | // -0.0. So if we ever translate calls to these methods into a |
| 1489 | // HCompare instruction, we must handle the -0.0 case with |
| 1490 | // care here. |
| 1491 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1492 | if (type == Primitive::kPrimFloat) { |
| 1493 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1494 | } else { |
| 1495 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1496 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1497 | } |
| 1498 | } else { |
| 1499 | if (type == Primitive::kPrimFloat) { |
| 1500 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1501 | } else { |
| 1502 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1503 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1504 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1509 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1510 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1511 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1512 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1513 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1517 | Label* true_label, |
| 1518 | Label* false_label) { |
| 1519 | LocationSummary* locations = cond->GetLocations(); |
| 1520 | Location left = locations->InAt(0); |
| 1521 | Location right = locations->InAt(1); |
| 1522 | IfCondition if_cond = cond->GetCondition(); |
| 1523 | |
| 1524 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1525 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1526 | IfCondition true_high_cond = if_cond; |
| 1527 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1528 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1529 | |
| 1530 | // Set the conditions for the test, remembering that == needs to be |
| 1531 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1532 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1533 | switch (if_cond) { |
| 1534 | case kCondEQ: |
| 1535 | case kCondNE: |
| 1536 | // Nothing to do. |
| 1537 | break; |
| 1538 | case kCondLT: |
| 1539 | false_high_cond = kCondGT; |
| 1540 | break; |
| 1541 | case kCondLE: |
| 1542 | true_high_cond = kCondLT; |
| 1543 | break; |
| 1544 | case kCondGT: |
| 1545 | false_high_cond = kCondLT; |
| 1546 | break; |
| 1547 | case kCondGE: |
| 1548 | true_high_cond = kCondGT; |
| 1549 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1550 | case kCondB: |
| 1551 | false_high_cond = kCondA; |
| 1552 | break; |
| 1553 | case kCondBE: |
| 1554 | true_high_cond = kCondB; |
| 1555 | break; |
| 1556 | case kCondA: |
| 1557 | false_high_cond = kCondB; |
| 1558 | break; |
| 1559 | case kCondAE: |
| 1560 | true_high_cond = kCondA; |
| 1561 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1562 | } |
| 1563 | if (right.IsConstant()) { |
| 1564 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1565 | int32_t val_low = Low32Bits(value); |
| 1566 | int32_t val_high = High32Bits(value); |
| 1567 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1568 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1569 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1570 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1571 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1572 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1573 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1574 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1575 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1576 | } |
| 1577 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1578 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1579 | } else { |
| 1580 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1581 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1582 | |
| 1583 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1584 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1585 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1586 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1587 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1588 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1589 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1590 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1591 | } |
| 1592 | // Must be equal high, so compare the lows. |
| 1593 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1594 | } |
| 1595 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1596 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1597 | __ b(true_label, final_condition); |
| 1598 | } |
| 1599 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1600 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1601 | Label* true_target_in, |
| 1602 | Label* false_target_in) { |
| 1603 | // Generated branching requires both targets to be explicit. If either of the |
| 1604 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1605 | Label fallthrough_target; |
| 1606 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1607 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1608 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1609 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1610 | switch (type) { |
| 1611 | case Primitive::kPrimLong: |
| 1612 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1613 | break; |
| 1614 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1615 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1616 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1617 | GenerateFPJumps(condition, true_target, false_target); |
| 1618 | break; |
| 1619 | default: |
| 1620 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1621 | } |
| 1622 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1623 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1624 | __ b(false_target); |
| 1625 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | |
| 1627 | if (fallthrough_target.IsLinked()) { |
| 1628 | __ Bind(&fallthrough_target); |
| 1629 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1632 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1633 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1634 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1635 | Label* false_target) { |
| 1636 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1637 | |
| 1638 | if (true_target == nullptr && false_target == nullptr) { |
| 1639 | // Nothing to do. The code always falls through. |
| 1640 | return; |
| 1641 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1642 | // Constant condition, statically compared against "true" (integer value 1). |
| 1643 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1644 | if (true_target != nullptr) { |
| 1645 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1646 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1647 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1648 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1649 | if (false_target != nullptr) { |
| 1650 | __ b(false_target); |
| 1651 | } |
| 1652 | } |
| 1653 | return; |
| 1654 | } |
| 1655 | |
| 1656 | // The following code generates these patterns: |
| 1657 | // (1) true_target == nullptr && false_target != nullptr |
| 1658 | // - opposite condition true => branch to false_target |
| 1659 | // (2) true_target != nullptr && false_target == nullptr |
| 1660 | // - condition true => branch to true_target |
| 1661 | // (3) true_target != nullptr && false_target != nullptr |
| 1662 | // - condition true => branch to true_target |
| 1663 | // - branch to false_target |
| 1664 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1665 | // Condition has been materialized, compare the output to 0. |
| 1666 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1667 | DCHECK(cond_val.IsRegister()); |
| 1668 | if (true_target == nullptr) { |
| 1669 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1670 | } else { |
| 1671 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1672 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1673 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1674 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1675 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1676 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1677 | |
| 1678 | // If this is a long or FP comparison that has been folded into |
| 1679 | // the HCondition, generate the comparison directly. |
| 1680 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1681 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1682 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1683 | return; |
| 1684 | } |
| 1685 | |
| 1686 | LocationSummary* locations = cond->GetLocations(); |
| 1687 | DCHECK(locations->InAt(0).IsRegister()); |
| 1688 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1689 | Location right = locations->InAt(1); |
| 1690 | if (right.IsRegister()) { |
| 1691 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1692 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1693 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1694 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | } |
| 1696 | if (true_target == nullptr) { |
| 1697 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1698 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1699 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1700 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1701 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1702 | |
| 1703 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1704 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1705 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1706 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1710 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1711 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1712 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1718 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1719 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1720 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1721 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1722 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1723 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1724 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1728 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1729 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1730 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1731 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1737 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1738 | GenerateTestAndBranch(deoptimize, |
| 1739 | /* condition_input_index */ 0, |
| 1740 | slow_path->GetEntryLabel(), |
| 1741 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1742 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1743 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1744 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1745 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1746 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1747 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1748 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1749 | } else { |
| 1750 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1751 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1752 | } |
| 1753 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1754 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1755 | } |
| 1756 | locations->SetOut(Location::SameAsFirstInput()); |
| 1757 | } |
| 1758 | |
| 1759 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1760 | LocationSummary* locations = select->GetLocations(); |
| 1761 | Label false_target; |
| 1762 | GenerateTestAndBranch(select, |
| 1763 | /* condition_input_index */ 2, |
| 1764 | /* true_target */ nullptr, |
| 1765 | &false_target); |
| 1766 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1767 | __ Bind(&false_target); |
| 1768 | } |
| 1769 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1770 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1771 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1772 | } |
| 1773 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1774 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1775 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | void CodeGeneratorARM::GenerateNop() { |
| 1779 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1783 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1784 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1785 | // Handle the long/FP comparisons made in instruction simplification. |
| 1786 | switch (cond->InputAt(0)->GetType()) { |
| 1787 | case Primitive::kPrimLong: |
| 1788 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1789 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1790 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1791 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1792 | } |
| 1793 | break; |
| 1794 | |
| 1795 | case Primitive::kPrimFloat: |
| 1796 | case Primitive::kPrimDouble: |
| 1797 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1798 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1799 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1800 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1801 | } |
| 1802 | break; |
| 1803 | |
| 1804 | default: |
| 1805 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1806 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1807 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1808 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1809 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1810 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1814 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1815 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1816 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1817 | |
| 1818 | LocationSummary* locations = cond->GetLocations(); |
| 1819 | Location left = locations->InAt(0); |
| 1820 | Location right = locations->InAt(1); |
| 1821 | Register out = locations->Out().AsRegister<Register>(); |
| 1822 | Label true_label, false_label; |
| 1823 | |
| 1824 | switch (cond->InputAt(0)->GetType()) { |
| 1825 | default: { |
| 1826 | // Integer case. |
| 1827 | if (right.IsRegister()) { |
| 1828 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1829 | } else { |
| 1830 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1831 | __ CmpConstant(left.AsRegister<Register>(), |
| 1832 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1833 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1834 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1835 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1836 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1837 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1838 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1839 | return; |
| 1840 | } |
| 1841 | case Primitive::kPrimLong: |
| 1842 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1843 | break; |
| 1844 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1845 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1846 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1847 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1848 | break; |
| 1849 | } |
| 1850 | |
| 1851 | // Convert the jumps into the result. |
| 1852 | Label done_label; |
| 1853 | |
| 1854 | // False case: result = 0. |
| 1855 | __ Bind(&false_label); |
| 1856 | __ LoadImmediate(out, 0); |
| 1857 | __ b(&done_label); |
| 1858 | |
| 1859 | // True case: result = 1. |
| 1860 | __ Bind(&true_label); |
| 1861 | __ LoadImmediate(out, 1); |
| 1862 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1866 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1870 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1874 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1878 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1882 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1886 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1890 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1894 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1898 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1902 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1906 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1910 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1913 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1914 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1918 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1922 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1926 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1930 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1934 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1938 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1945 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1946 | LocationSummary* locations = |
| 1947 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1948 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1951 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1952 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1955 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1956 | LocationSummary* locations = |
| 1957 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1958 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1959 | } |
| 1960 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1961 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1962 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1965 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1966 | LocationSummary* locations = |
| 1967 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1968 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1971 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1972 | // Will be generated at use site. |
| 1973 | } |
| 1974 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1975 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1976 | LocationSummary* locations = |
| 1977 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1978 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1979 | } |
| 1980 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1981 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1982 | // Will be generated at use site. |
| 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* 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::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1992 | // Will be generated at use site. |
| 1993 | } |
| 1994 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1995 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1996 | memory_barrier->SetLocations(nullptr); |
| 1997 | } |
| 1998 | |
| 1999 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2000 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2003 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2004 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2007 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2008 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2011 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2012 | LocationSummary* locations = |
| 2013 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2014 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2017 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2018 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2021 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2022 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2023 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2024 | // the method_idx. |
| 2025 | HandleInvoke(invoke); |
| 2026 | } |
| 2027 | |
| 2028 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2029 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2030 | } |
| 2031 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2032 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2033 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2034 | // art::PrepareForRegisterAllocation. |
| 2035 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2036 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2037 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2038 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2039 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2040 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2041 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2042 | return; |
| 2043 | } |
| 2044 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2045 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2046 | |
| 2047 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2048 | if (invoke->HasPcRelativeDexCache()) { |
| 2049 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2050 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2051 | } |
| 2052 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2053 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2054 | if (invoke->GetLocations()->Intrinsified()) { |
| 2055 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2056 | intrinsic.Dispatch(invoke); |
| 2057 | return true; |
| 2058 | } |
| 2059 | return false; |
| 2060 | } |
| 2061 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2062 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2063 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2064 | // art::PrepareForRegisterAllocation. |
| 2065 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2066 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2067 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2068 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2069 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2070 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2071 | LocationSummary* locations = invoke->GetLocations(); |
| 2072 | codegen_->GenerateStaticOrDirectCall( |
| 2073 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2074 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2077 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2078 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2079 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2082 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2083 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2084 | if (intrinsic.TryDispatch(invoke)) { |
| 2085 | return; |
| 2086 | } |
| 2087 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2088 | HandleInvoke(invoke); |
| 2089 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2090 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2091 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2092 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2093 | return; |
| 2094 | } |
| 2095 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2096 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2097 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2098 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2101 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2102 | HandleInvoke(invoke); |
| 2103 | // Add the hidden argument. |
| 2104 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2105 | } |
| 2106 | |
| 2107 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2108 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2109 | LocationSummary* locations = invoke->GetLocations(); |
| 2110 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2111 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2112 | Location receiver = locations->InAt(0); |
| 2113 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2114 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2115 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2116 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2117 | DCHECK_EQ(R12, hidden_reg); |
| 2118 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2119 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2120 | if (receiver.IsStackSlot()) { |
| 2121 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2122 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2123 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2124 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2125 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2126 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2127 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2128 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2129 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2130 | // emit a read barrier for the previous class reference load. |
| 2131 | // However this is not required in practice, as this is an |
| 2132 | // intermediate/temporary reference and because the current |
| 2133 | // concurrent copying collector keeps the from-space memory |
| 2134 | // intact/accessible until the end of the marking phase (the |
| 2135 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2136 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2137 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2138 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2139 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2140 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2141 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2142 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2143 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2144 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2145 | // LR = temp->GetEntryPoint(); |
| 2146 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2147 | // LR(); |
| 2148 | __ blx(LR); |
| 2149 | DCHECK(!codegen_->IsLeafMethod()); |
| 2150 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2151 | } |
| 2152 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2153 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2154 | LocationSummary* locations = |
| 2155 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2156 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2157 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2158 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2159 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2160 | break; |
| 2161 | } |
| 2162 | case Primitive::kPrimLong: { |
| 2163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2164 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2165 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2166 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2167 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2168 | case Primitive::kPrimFloat: |
| 2169 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2170 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2171 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2172 | break; |
| 2173 | |
| 2174 | default: |
| 2175 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2180 | LocationSummary* locations = neg->GetLocations(); |
| 2181 | Location out = locations->Out(); |
| 2182 | Location in = locations->InAt(0); |
| 2183 | switch (neg->GetResultType()) { |
| 2184 | case Primitive::kPrimInt: |
| 2185 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2186 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2187 | break; |
| 2188 | |
| 2189 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2190 | DCHECK(in.IsRegisterPair()); |
| 2191 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2192 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2193 | in.AsRegisterPairLow<Register>(), |
| 2194 | ShifterOperand(0)); |
| 2195 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2196 | // instruction here, as it does not exist in the Thumb-2 |
| 2197 | // instruction set. We use the following approach |
| 2198 | // using SBC and SUB instead. |
| 2199 | // |
| 2200 | // out.hi = -C |
| 2201 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2202 | out.AsRegisterPairHigh<Register>(), |
| 2203 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2204 | // out.hi = out.hi - in.hi |
| 2205 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2206 | out.AsRegisterPairHigh<Register>(), |
| 2207 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2208 | break; |
| 2209 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2210 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2211 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2212 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2215 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2216 | DCHECK(in.IsFpuRegisterPair()); |
| 2217 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2218 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2219 | break; |
| 2220 | |
| 2221 | default: |
| 2222 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2223 | } |
| 2224 | } |
| 2225 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2226 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2227 | Primitive::Type result_type = conversion->GetResultType(); |
| 2228 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2229 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2230 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2231 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2232 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2233 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2234 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2235 | && result_type == Primitive::kPrimLong) |
| 2236 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2237 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2238 | : LocationSummary::kNoCall; |
| 2239 | LocationSummary* locations = |
| 2240 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2241 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2242 | // The Java language does not allow treating boolean as an integral type but |
| 2243 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2244 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2245 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimByte: |
| 2247 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimLong: |
| 2249 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimBoolean: |
| 2251 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2252 | case Primitive::kPrimShort: |
| 2253 | case Primitive::kPrimInt: |
| 2254 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2255 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2256 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2257 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2258 | break; |
| 2259 | |
| 2260 | default: |
| 2261 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2262 | << " to " << result_type; |
| 2263 | } |
| 2264 | break; |
| 2265 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimShort: |
| 2267 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimLong: |
| 2269 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimBoolean: |
| 2271 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimByte: |
| 2273 | case Primitive::kPrimInt: |
| 2274 | case Primitive::kPrimChar: |
| 2275 | // Processing a Dex `int-to-short' instruction. |
| 2276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2277 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2278 | break; |
| 2279 | |
| 2280 | default: |
| 2281 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2282 | << " to " << result_type; |
| 2283 | } |
| 2284 | break; |
| 2285 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimInt: |
| 2287 | switch (input_type) { |
| 2288 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2289 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2290 | locations->SetInAt(0, Location::Any()); |
| 2291 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2292 | break; |
| 2293 | |
| 2294 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2295 | // Processing a Dex `float-to-int' instruction. |
| 2296 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2297 | locations->SetOut(Location::RequiresRegister()); |
| 2298 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2299 | break; |
| 2300 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2301 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2302 | // Processing a Dex `double-to-int' instruction. |
| 2303 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2304 | locations->SetOut(Location::RequiresRegister()); |
| 2305 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2306 | break; |
| 2307 | |
| 2308 | default: |
| 2309 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2310 | << " to " << result_type; |
| 2311 | } |
| 2312 | break; |
| 2313 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimLong: |
| 2315 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimBoolean: |
| 2317 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimByte: |
| 2319 | case Primitive::kPrimShort: |
| 2320 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2322 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2323 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2324 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2325 | break; |
| 2326 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimFloat: { |
| 2328 | // Processing a Dex `float-to-long' instruction. |
| 2329 | InvokeRuntimeCallingConvention calling_convention; |
| 2330 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2331 | calling_convention.GetFpuRegisterAt(0))); |
| 2332 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2333 | break; |
| 2334 | } |
| 2335 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2336 | case Primitive::kPrimDouble: { |
| 2337 | // Processing a Dex `double-to-long' instruction. |
| 2338 | InvokeRuntimeCallingConvention calling_convention; |
| 2339 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2340 | calling_convention.GetFpuRegisterAt(0), |
| 2341 | calling_convention.GetFpuRegisterAt(1))); |
| 2342 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2343 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2344 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2345 | |
| 2346 | default: |
| 2347 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2348 | << " to " << result_type; |
| 2349 | } |
| 2350 | break; |
| 2351 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2352 | case Primitive::kPrimChar: |
| 2353 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2354 | case Primitive::kPrimLong: |
| 2355 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimBoolean: |
| 2357 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimByte: |
| 2359 | case Primitive::kPrimShort: |
| 2360 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2361 | // Processing a Dex `int-to-char' instruction. |
| 2362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2363 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2364 | break; |
| 2365 | |
| 2366 | default: |
| 2367 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2368 | << " to " << result_type; |
| 2369 | } |
| 2370 | break; |
| 2371 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2372 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2373 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimBoolean: |
| 2375 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimByte: |
| 2377 | case Primitive::kPrimShort: |
| 2378 | case Primitive::kPrimInt: |
| 2379 | case Primitive::kPrimChar: |
| 2380 | // Processing a Dex `int-to-float' instruction. |
| 2381 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2382 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2383 | break; |
| 2384 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2385 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2386 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2387 | InvokeRuntimeCallingConvention calling_convention; |
| 2388 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2389 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2390 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2391 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2392 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2393 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2394 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2395 | // Processing a Dex `double-to-float' instruction. |
| 2396 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2397 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2398 | break; |
| 2399 | |
| 2400 | default: |
| 2401 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2402 | << " to " << result_type; |
| 2403 | }; |
| 2404 | break; |
| 2405 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2407 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2408 | case Primitive::kPrimBoolean: |
| 2409 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2410 | case Primitive::kPrimByte: |
| 2411 | case Primitive::kPrimShort: |
| 2412 | case Primitive::kPrimInt: |
| 2413 | case Primitive::kPrimChar: |
| 2414 | // Processing a Dex `int-to-double' instruction. |
| 2415 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2416 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2417 | break; |
| 2418 | |
| 2419 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2420 | // Processing a Dex `long-to-double' instruction. |
| 2421 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2422 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2423 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2424 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2425 | break; |
| 2426 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2428 | // Processing a Dex `float-to-double' instruction. |
| 2429 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2430 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2431 | break; |
| 2432 | |
| 2433 | default: |
| 2434 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2435 | << " to " << result_type; |
| 2436 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2437 | break; |
| 2438 | |
| 2439 | default: |
| 2440 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2441 | << " to " << result_type; |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2446 | LocationSummary* locations = conversion->GetLocations(); |
| 2447 | Location out = locations->Out(); |
| 2448 | Location in = locations->InAt(0); |
| 2449 | Primitive::Type result_type = conversion->GetResultType(); |
| 2450 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2451 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2452 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2453 | case Primitive::kPrimByte: |
| 2454 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2455 | case Primitive::kPrimLong: |
| 2456 | // Type conversion from long to byte is a result of code transformations. |
| 2457 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2458 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimBoolean: |
| 2460 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimShort: |
| 2462 | case Primitive::kPrimInt: |
| 2463 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2464 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2465 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2466 | break; |
| 2467 | |
| 2468 | default: |
| 2469 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2470 | << " to " << result_type; |
| 2471 | } |
| 2472 | break; |
| 2473 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimShort: |
| 2475 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2476 | case Primitive::kPrimLong: |
| 2477 | // Type conversion from long to short is a result of code transformations. |
| 2478 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2479 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2480 | case Primitive::kPrimBoolean: |
| 2481 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2482 | case Primitive::kPrimByte: |
| 2483 | case Primitive::kPrimInt: |
| 2484 | case Primitive::kPrimChar: |
| 2485 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2486 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2487 | break; |
| 2488 | |
| 2489 | default: |
| 2490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2491 | << " to " << result_type; |
| 2492 | } |
| 2493 | break; |
| 2494 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimInt: |
| 2496 | switch (input_type) { |
| 2497 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2498 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2499 | DCHECK(out.IsRegister()); |
| 2500 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2501 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2502 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2504 | } else { |
| 2505 | DCHECK(in.IsConstant()); |
| 2506 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2507 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2508 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2509 | } |
| 2510 | break; |
| 2511 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimFloat: { |
| 2513 | // Processing a Dex `float-to-int' instruction. |
| 2514 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2515 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2516 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2517 | break; |
| 2518 | } |
| 2519 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimDouble: { |
| 2521 | // Processing a Dex `double-to-int' instruction. |
| 2522 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2523 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2524 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2525 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2526 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2527 | |
| 2528 | default: |
| 2529 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2530 | << " to " << result_type; |
| 2531 | } |
| 2532 | break; |
| 2533 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimLong: |
| 2535 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimBoolean: |
| 2537 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimByte: |
| 2539 | case Primitive::kPrimShort: |
| 2540 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2542 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2543 | DCHECK(out.IsRegisterPair()); |
| 2544 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2545 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2546 | // Sign extension. |
| 2547 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2548 | out.AsRegisterPairLow<Register>(), |
| 2549 | 31); |
| 2550 | break; |
| 2551 | |
| 2552 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2553 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2554 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2555 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2559 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2560 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2561 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | |
| 2564 | default: |
| 2565 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2566 | << " to " << result_type; |
| 2567 | } |
| 2568 | break; |
| 2569 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2570 | case Primitive::kPrimChar: |
| 2571 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimLong: |
| 2573 | // Type conversion from long to char is a result of code transformations. |
| 2574 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2575 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2576 | case Primitive::kPrimBoolean: |
| 2577 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2578 | case Primitive::kPrimByte: |
| 2579 | case Primitive::kPrimShort: |
| 2580 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2581 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2582 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2583 | break; |
| 2584 | |
| 2585 | default: |
| 2586 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2587 | << " to " << result_type; |
| 2588 | } |
| 2589 | break; |
| 2590 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2591 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2592 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2593 | case Primitive::kPrimBoolean: |
| 2594 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2595 | case Primitive::kPrimByte: |
| 2596 | case Primitive::kPrimShort: |
| 2597 | case Primitive::kPrimInt: |
| 2598 | case Primitive::kPrimChar: { |
| 2599 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2600 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2601 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2602 | break; |
| 2603 | } |
| 2604 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2605 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2606 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2607 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2608 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2609 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2610 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2612 | // Processing a Dex `double-to-float' instruction. |
| 2613 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2614 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2615 | break; |
| 2616 | |
| 2617 | default: |
| 2618 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2619 | << " to " << result_type; |
| 2620 | }; |
| 2621 | break; |
| 2622 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2623 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2624 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2625 | case Primitive::kPrimBoolean: |
| 2626 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimByte: |
| 2628 | case Primitive::kPrimShort: |
| 2629 | case Primitive::kPrimInt: |
| 2630 | case Primitive::kPrimChar: { |
| 2631 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2632 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2633 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2634 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2635 | break; |
| 2636 | } |
| 2637 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimLong: { |
| 2639 | // Processing a Dex `long-to-double' instruction. |
| 2640 | Register low = in.AsRegisterPairLow<Register>(); |
| 2641 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2642 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2643 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2644 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2645 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2646 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2647 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2648 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2649 | // temp_d = int-to-double(high) |
| 2650 | __ vmovsr(temp_s, high); |
| 2651 | __ vcvtdi(temp_d, temp_s); |
| 2652 | // constant_d = k2Pow32EncodingForDouble |
| 2653 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2654 | // out_d = unsigned-to-double(low) |
| 2655 | __ vmovsr(out_s, low); |
| 2656 | __ vcvtdu(out_d, out_s); |
| 2657 | // out_d += temp_d * constant_d |
| 2658 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2659 | break; |
| 2660 | } |
| 2661 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2662 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2663 | // Processing a Dex `float-to-double' instruction. |
| 2664 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2665 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2666 | break; |
| 2667 | |
| 2668 | default: |
| 2669 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2670 | << " to " << result_type; |
| 2671 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2672 | break; |
| 2673 | |
| 2674 | default: |
| 2675 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2676 | << " to " << result_type; |
| 2677 | } |
| 2678 | } |
| 2679 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2680 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2681 | LocationSummary* locations = |
| 2682 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2683 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2684 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2685 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2686 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2687 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2688 | break; |
| 2689 | } |
| 2690 | |
| 2691 | case Primitive::kPrimLong: { |
| 2692 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2693 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2694 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2695 | break; |
| 2696 | } |
| 2697 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2698 | case Primitive::kPrimFloat: |
| 2699 | case Primitive::kPrimDouble: { |
| 2700 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2701 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2702 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2703 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2704 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2705 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2706 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2707 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2708 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2712 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2713 | Location out = locations->Out(); |
| 2714 | Location first = locations->InAt(0); |
| 2715 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2716 | switch (add->GetResultType()) { |
| 2717 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2718 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2719 | __ add(out.AsRegister<Register>(), |
| 2720 | first.AsRegister<Register>(), |
| 2721 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2722 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2723 | __ AddConstant(out.AsRegister<Register>(), |
| 2724 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2725 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2726 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2727 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2728 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2730 | if (second.IsConstant()) { |
| 2731 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2732 | GenerateAddLongConst(out, first, value); |
| 2733 | } else { |
| 2734 | DCHECK(second.IsRegisterPair()); |
| 2735 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2736 | first.AsRegisterPairLow<Register>(), |
| 2737 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2738 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2739 | first.AsRegisterPairHigh<Register>(), |
| 2740 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2741 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2742 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2743 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2744 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2745 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2746 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2747 | first.AsFpuRegister<SRegister>(), |
| 2748 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2749 | break; |
| 2750 | |
| 2751 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2752 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2753 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2754 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2755 | break; |
| 2756 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2757 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2758 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2759 | } |
| 2760 | } |
| 2761 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2762 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2763 | LocationSummary* locations = |
| 2764 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2765 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2766 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2767 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2768 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2769 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2770 | break; |
| 2771 | } |
| 2772 | |
| 2773 | case Primitive::kPrimLong: { |
| 2774 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2775 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2776 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2777 | break; |
| 2778 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2779 | case Primitive::kPrimFloat: |
| 2780 | case Primitive::kPrimDouble: { |
| 2781 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2782 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2783 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2784 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2785 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2786 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2787 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2788 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2792 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2793 | Location out = locations->Out(); |
| 2794 | Location first = locations->InAt(0); |
| 2795 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2796 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2797 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2798 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2799 | __ sub(out.AsRegister<Register>(), |
| 2800 | first.AsRegister<Register>(), |
| 2801 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2802 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2803 | __ AddConstant(out.AsRegister<Register>(), |
| 2804 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2805 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2806 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2807 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2808 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2809 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2810 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2811 | if (second.IsConstant()) { |
| 2812 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2813 | GenerateAddLongConst(out, first, -value); |
| 2814 | } else { |
| 2815 | DCHECK(second.IsRegisterPair()); |
| 2816 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2817 | first.AsRegisterPairLow<Register>(), |
| 2818 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2819 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2820 | first.AsRegisterPairHigh<Register>(), |
| 2821 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2822 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2823 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2824 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2825 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2826 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2827 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2828 | first.AsFpuRegister<SRegister>(), |
| 2829 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2830 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2834 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2835 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2836 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2837 | break; |
| 2838 | } |
| 2839 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2840 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2841 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2842 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2843 | } |
| 2844 | } |
| 2845 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2846 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2847 | LocationSummary* locations = |
| 2848 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2849 | switch (mul->GetResultType()) { |
| 2850 | case Primitive::kPrimInt: |
| 2851 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2852 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2853 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2854 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2855 | break; |
| 2856 | } |
| 2857 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2858 | case Primitive::kPrimFloat: |
| 2859 | case Primitive::kPrimDouble: { |
| 2860 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2861 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2862 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2863 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2864 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2865 | |
| 2866 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2867 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2872 | LocationSummary* locations = mul->GetLocations(); |
| 2873 | Location out = locations->Out(); |
| 2874 | Location first = locations->InAt(0); |
| 2875 | Location second = locations->InAt(1); |
| 2876 | switch (mul->GetResultType()) { |
| 2877 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2878 | __ mul(out.AsRegister<Register>(), |
| 2879 | first.AsRegister<Register>(), |
| 2880 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2881 | break; |
| 2882 | } |
| 2883 | case Primitive::kPrimLong: { |
| 2884 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2885 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2886 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2887 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2888 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2889 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2890 | |
| 2891 | // Extra checks to protect caused by the existence of R1_R2. |
| 2892 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2893 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2894 | DCHECK_NE(out_hi, in1_lo); |
| 2895 | DCHECK_NE(out_hi, in2_lo); |
| 2896 | |
| 2897 | // input: in1 - 64 bits, in2 - 64 bits |
| 2898 | // output: out |
| 2899 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2900 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2901 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2902 | |
| 2903 | // IP <- in1.lo * in2.hi |
| 2904 | __ mul(IP, in1_lo, in2_hi); |
| 2905 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2906 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2907 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2908 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2909 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2910 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2911 | break; |
| 2912 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2913 | |
| 2914 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2915 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2916 | first.AsFpuRegister<SRegister>(), |
| 2917 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2918 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2922 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2923 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2924 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2925 | break; |
| 2926 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2927 | |
| 2928 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2929 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2930 | } |
| 2931 | } |
| 2932 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2933 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2934 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2935 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2936 | |
| 2937 | LocationSummary* locations = instruction->GetLocations(); |
| 2938 | Location second = locations->InAt(1); |
| 2939 | DCHECK(second.IsConstant()); |
| 2940 | |
| 2941 | Register out = locations->Out().AsRegister<Register>(); |
| 2942 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2943 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2944 | DCHECK(imm == 1 || imm == -1); |
| 2945 | |
| 2946 | if (instruction->IsRem()) { |
| 2947 | __ LoadImmediate(out, 0); |
| 2948 | } else { |
| 2949 | if (imm == 1) { |
| 2950 | __ Mov(out, dividend); |
| 2951 | } else { |
| 2952 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2953 | } |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2958 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2959 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2960 | |
| 2961 | LocationSummary* locations = instruction->GetLocations(); |
| 2962 | Location second = locations->InAt(1); |
| 2963 | DCHECK(second.IsConstant()); |
| 2964 | |
| 2965 | Register out = locations->Out().AsRegister<Register>(); |
| 2966 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2967 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2968 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2969 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2970 | int ctz_imm = CTZ(abs_imm); |
| 2971 | |
| 2972 | if (ctz_imm == 1) { |
| 2973 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2974 | } else { |
| 2975 | __ Asr(temp, dividend, 31); |
| 2976 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2977 | } |
| 2978 | __ add(out, temp, ShifterOperand(dividend)); |
| 2979 | |
| 2980 | if (instruction->IsDiv()) { |
| 2981 | __ Asr(out, out, ctz_imm); |
| 2982 | if (imm < 0) { |
| 2983 | __ rsb(out, out, ShifterOperand(0)); |
| 2984 | } |
| 2985 | } else { |
| 2986 | __ ubfx(out, out, 0, ctz_imm); |
| 2987 | __ sub(out, out, ShifterOperand(temp)); |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2992 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2993 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2994 | |
| 2995 | LocationSummary* locations = instruction->GetLocations(); |
| 2996 | Location second = locations->InAt(1); |
| 2997 | DCHECK(second.IsConstant()); |
| 2998 | |
| 2999 | Register out = locations->Out().AsRegister<Register>(); |
| 3000 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3001 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3002 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3003 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3004 | |
| 3005 | int64_t magic; |
| 3006 | int shift; |
| 3007 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3008 | |
| 3009 | __ LoadImmediate(temp1, magic); |
| 3010 | __ smull(temp2, temp1, dividend, temp1); |
| 3011 | |
| 3012 | if (imm > 0 && magic < 0) { |
| 3013 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3014 | } else if (imm < 0 && magic > 0) { |
| 3015 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3016 | } |
| 3017 | |
| 3018 | if (shift != 0) { |
| 3019 | __ Asr(temp1, temp1, shift); |
| 3020 | } |
| 3021 | |
| 3022 | if (instruction->IsDiv()) { |
| 3023 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3024 | } else { |
| 3025 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3026 | // TODO: Strength reduction for mls. |
| 3027 | __ LoadImmediate(temp2, imm); |
| 3028 | __ mls(out, temp1, temp2, dividend); |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3033 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3034 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3035 | |
| 3036 | LocationSummary* locations = instruction->GetLocations(); |
| 3037 | Location second = locations->InAt(1); |
| 3038 | DCHECK(second.IsConstant()); |
| 3039 | |
| 3040 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3041 | if (imm == 0) { |
| 3042 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3043 | } else if (imm == 1 || imm == -1) { |
| 3044 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3045 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3046 | DivRemByPowerOfTwo(instruction); |
| 3047 | } else { |
| 3048 | DCHECK(imm <= -2 || imm >= 2); |
| 3049 | GenerateDivRemWithAnyConstant(instruction); |
| 3050 | } |
| 3051 | } |
| 3052 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3053 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3054 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3055 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3056 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3057 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3058 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3059 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3060 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3061 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3062 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3063 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3066 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3067 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3068 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3069 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3070 | if (div->InputAt(1)->IsConstant()) { |
| 3071 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3072 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3074 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3075 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3076 | // No temp register required. |
| 3077 | } else { |
| 3078 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3079 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3080 | locations->AddTemp(Location::RequiresRegister()); |
| 3081 | } |
| 3082 | } |
| 3083 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3084 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3085 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3086 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3087 | } else { |
| 3088 | InvokeRuntimeCallingConvention calling_convention; |
| 3089 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3090 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3091 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3092 | // we only need the former. |
| 3093 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3094 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3095 | break; |
| 3096 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3097 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3098 | InvokeRuntimeCallingConvention calling_convention; |
| 3099 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3100 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3101 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3102 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3103 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3104 | break; |
| 3105 | } |
| 3106 | case Primitive::kPrimFloat: |
| 3107 | case Primitive::kPrimDouble: { |
| 3108 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3109 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3110 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3111 | break; |
| 3112 | } |
| 3113 | |
| 3114 | default: |
| 3115 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3120 | LocationSummary* locations = div->GetLocations(); |
| 3121 | Location out = locations->Out(); |
| 3122 | Location first = locations->InAt(0); |
| 3123 | Location second = locations->InAt(1); |
| 3124 | |
| 3125 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3126 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3127 | if (second.IsConstant()) { |
| 3128 | GenerateDivRemConstantIntegral(div); |
| 3129 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3130 | __ sdiv(out.AsRegister<Register>(), |
| 3131 | first.AsRegister<Register>(), |
| 3132 | second.AsRegister<Register>()); |
| 3133 | } else { |
| 3134 | InvokeRuntimeCallingConvention calling_convention; |
| 3135 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3136 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3137 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3138 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3139 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3140 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3141 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3142 | break; |
| 3143 | } |
| 3144 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3145 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3146 | InvokeRuntimeCallingConvention calling_convention; |
| 3147 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3148 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3149 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3150 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3151 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3152 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3153 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3154 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3155 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3156 | break; |
| 3157 | } |
| 3158 | |
| 3159 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3160 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3161 | first.AsFpuRegister<SRegister>(), |
| 3162 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3163 | break; |
| 3164 | } |
| 3165 | |
| 3166 | case Primitive::kPrimDouble: { |
| 3167 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3168 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3169 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3170 | break; |
| 3171 | } |
| 3172 | |
| 3173 | default: |
| 3174 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3175 | } |
| 3176 | } |
| 3177 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3178 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3179 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3180 | |
| 3181 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3182 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3183 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3184 | // sdiv will be replaced by other instruction sequence. |
| 3185 | call_kind = LocationSummary::kNoCall; |
| 3186 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3187 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3188 | // Have hardware divide instruction for int, do it with three instructions. |
| 3189 | call_kind = LocationSummary::kNoCall; |
| 3190 | } |
| 3191 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3192 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3193 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3194 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3195 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3196 | if (rem->InputAt(1)->IsConstant()) { |
| 3197 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3198 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3199 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3200 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3201 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3202 | // No temp register required. |
| 3203 | } else { |
| 3204 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3205 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3206 | locations->AddTemp(Location::RequiresRegister()); |
| 3207 | } |
| 3208 | } |
| 3209 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3211 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3212 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3213 | locations->AddTemp(Location::RequiresRegister()); |
| 3214 | } else { |
| 3215 | InvokeRuntimeCallingConvention calling_convention; |
| 3216 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3217 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3218 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3219 | // we only need the latter. |
| 3220 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3221 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3222 | break; |
| 3223 | } |
| 3224 | case Primitive::kPrimLong: { |
| 3225 | InvokeRuntimeCallingConvention calling_convention; |
| 3226 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3227 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3228 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3229 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3230 | // The runtime helper puts the output in R2,R3. |
| 3231 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3232 | break; |
| 3233 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3234 | case Primitive::kPrimFloat: { |
| 3235 | InvokeRuntimeCallingConvention calling_convention; |
| 3236 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3237 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3238 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3239 | break; |
| 3240 | } |
| 3241 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3242 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3243 | InvokeRuntimeCallingConvention calling_convention; |
| 3244 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3245 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3246 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3247 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3248 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | } |
| 3251 | |
| 3252 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3253 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3258 | LocationSummary* locations = rem->GetLocations(); |
| 3259 | Location out = locations->Out(); |
| 3260 | Location first = locations->InAt(0); |
| 3261 | Location second = locations->InAt(1); |
| 3262 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3263 | Primitive::Type type = rem->GetResultType(); |
| 3264 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3265 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3266 | if (second.IsConstant()) { |
| 3267 | GenerateDivRemConstantIntegral(rem); |
| 3268 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3269 | Register reg1 = first.AsRegister<Register>(); |
| 3270 | Register reg2 = second.AsRegister<Register>(); |
| 3271 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3272 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3273 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3274 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3275 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3276 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3277 | } else { |
| 3278 | InvokeRuntimeCallingConvention calling_convention; |
| 3279 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3280 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3281 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3282 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3283 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3284 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3285 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3286 | break; |
| 3287 | } |
| 3288 | |
| 3289 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3290 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3291 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3292 | break; |
| 3293 | } |
| 3294 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3295 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3296 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3297 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3298 | break; |
| 3299 | } |
| 3300 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3301 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3302 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3303 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3304 | break; |
| 3305 | } |
| 3306 | |
| 3307 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3308 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3309 | } |
| 3310 | } |
| 3311 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3312 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3313 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3314 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3318 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3319 | codegen_->AddSlowPath(slow_path); |
| 3320 | |
| 3321 | LocationSummary* locations = instruction->GetLocations(); |
| 3322 | Location value = locations->InAt(0); |
| 3323 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3324 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3325 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3326 | case Primitive::kPrimByte: |
| 3327 | case Primitive::kPrimChar: |
| 3328 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3329 | case Primitive::kPrimInt: { |
| 3330 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3331 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3332 | } else { |
| 3333 | DCHECK(value.IsConstant()) << value; |
| 3334 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3335 | __ b(slow_path->GetEntryLabel()); |
| 3336 | } |
| 3337 | } |
| 3338 | break; |
| 3339 | } |
| 3340 | case Primitive::kPrimLong: { |
| 3341 | if (value.IsRegisterPair()) { |
| 3342 | __ orrs(IP, |
| 3343 | value.AsRegisterPairLow<Register>(), |
| 3344 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3345 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3346 | } else { |
| 3347 | DCHECK(value.IsConstant()) << value; |
| 3348 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3349 | __ b(slow_path->GetEntryLabel()); |
| 3350 | } |
| 3351 | } |
| 3352 | break; |
| 3353 | default: |
| 3354 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3355 | } |
| 3356 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3359 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3360 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3361 | Location rhs = locations->InAt(1); |
| 3362 | Register out = locations->Out().AsRegister<Register>(); |
| 3363 | |
| 3364 | if (rhs.IsConstant()) { |
| 3365 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3366 | // so map all rotations to a +ve. equivalent in that range. |
| 3367 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3368 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3369 | if (rot) { |
| 3370 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3371 | // (e.g. left by 2 bits == right by 30.) |
| 3372 | __ Ror(out, in, rot); |
| 3373 | } else if (out != in) { |
| 3374 | __ Mov(out, in); |
| 3375 | } |
| 3376 | } else { |
| 3377 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3382 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3383 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3384 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3385 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3386 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3387 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3388 | Location rhs = locations->InAt(1); |
| 3389 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3390 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3391 | |
| 3392 | if (rhs.IsConstant()) { |
| 3393 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3394 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3395 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3396 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3397 | // logic below to a simple pair of binary orr. |
| 3398 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3399 | if (rot >= kArmBitsPerWord) { |
| 3400 | rot -= kArmBitsPerWord; |
| 3401 | std::swap(in_reg_hi, in_reg_lo); |
| 3402 | } |
| 3403 | // Rotate, or mov to out for zero or word size rotations. |
| 3404 | if (rot != 0u) { |
| 3405 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3406 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3407 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3408 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3409 | } else { |
| 3410 | __ Mov(out_reg_lo, in_reg_lo); |
| 3411 | __ Mov(out_reg_hi, in_reg_hi); |
| 3412 | } |
| 3413 | } else { |
| 3414 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3415 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3416 | Label end; |
| 3417 | Label shift_by_32_plus_shift_right; |
| 3418 | |
| 3419 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3420 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3421 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3422 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3423 | |
| 3424 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3425 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3426 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3427 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3428 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3429 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3430 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3431 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3432 | __ b(&end); |
| 3433 | |
| 3434 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3435 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3436 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3437 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3438 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3439 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3440 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3441 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3442 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3443 | |
| 3444 | __ Bind(&end); |
| 3445 | } |
| 3446 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3447 | |
| 3448 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3449 | LocationSummary* locations = |
| 3450 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3451 | switch (ror->GetResultType()) { |
| 3452 | case Primitive::kPrimInt: { |
| 3453 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3454 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3456 | break; |
| 3457 | } |
| 3458 | case Primitive::kPrimLong: { |
| 3459 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3460 | if (ror->InputAt(1)->IsConstant()) { |
| 3461 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3462 | } else { |
| 3463 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3464 | locations->AddTemp(Location::RequiresRegister()); |
| 3465 | locations->AddTemp(Location::RequiresRegister()); |
| 3466 | } |
| 3467 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3468 | break; |
| 3469 | } |
| 3470 | default: |
| 3471 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3472 | } |
| 3473 | } |
| 3474 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3475 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3476 | LocationSummary* locations = ror->GetLocations(); |
| 3477 | Primitive::Type type = ror->GetResultType(); |
| 3478 | switch (type) { |
| 3479 | case Primitive::kPrimInt: { |
| 3480 | HandleIntegerRotate(locations); |
| 3481 | break; |
| 3482 | } |
| 3483 | case Primitive::kPrimLong: { |
| 3484 | HandleLongRotate(locations); |
| 3485 | break; |
| 3486 | } |
| 3487 | default: |
| 3488 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3489 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3493 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3494 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3495 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3496 | LocationSummary* locations = |
| 3497 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3498 | |
| 3499 | switch (op->GetResultType()) { |
| 3500 | case Primitive::kPrimInt: { |
| 3501 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3502 | if (op->InputAt(1)->IsConstant()) { |
| 3503 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3504 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3505 | } else { |
| 3506 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3507 | // Make the output overlap, as it will be used to hold the masked |
| 3508 | // second input. |
| 3509 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3510 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3511 | break; |
| 3512 | } |
| 3513 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3514 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3515 | if (op->InputAt(1)->IsConstant()) { |
| 3516 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3517 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3518 | // don't clash with high registers which the register allocator currently guarantees. |
| 3519 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3520 | } else { |
| 3521 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3522 | locations->AddTemp(Location::RequiresRegister()); |
| 3523 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3524 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3525 | break; |
| 3526 | } |
| 3527 | default: |
| 3528 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3533 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3534 | |
| 3535 | LocationSummary* locations = op->GetLocations(); |
| 3536 | Location out = locations->Out(); |
| 3537 | Location first = locations->InAt(0); |
| 3538 | Location second = locations->InAt(1); |
| 3539 | |
| 3540 | Primitive::Type type = op->GetResultType(); |
| 3541 | switch (type) { |
| 3542 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3543 | Register out_reg = out.AsRegister<Register>(); |
| 3544 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3545 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3546 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3547 | // 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] | 3548 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3549 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3550 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3551 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3552 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3553 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3554 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3555 | } |
| 3556 | } else { |
| 3557 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3558 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3559 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3560 | __ Mov(out_reg, first_reg); |
| 3561 | } else if (op->IsShl()) { |
| 3562 | __ Lsl(out_reg, first_reg, shift_value); |
| 3563 | } else if (op->IsShr()) { |
| 3564 | __ Asr(out_reg, first_reg, shift_value); |
| 3565 | } else { |
| 3566 | __ Lsr(out_reg, first_reg, shift_value); |
| 3567 | } |
| 3568 | } |
| 3569 | break; |
| 3570 | } |
| 3571 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3572 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3573 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3574 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3575 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3576 | Register low = first.AsRegisterPairLow<Register>(); |
| 3577 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3578 | if (second.IsRegister()) { |
| 3579 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3580 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3581 | Register second_reg = second.AsRegister<Register>(); |
| 3582 | |
| 3583 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3584 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3585 | // Shift the high part |
| 3586 | __ Lsl(o_h, high, o_l); |
| 3587 | // Shift the low part and `or` what overflew on the high part |
| 3588 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3589 | __ Lsr(temp, low, temp); |
| 3590 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3591 | // If the shift is > 32 bits, override the high part |
| 3592 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3593 | __ it(PL); |
| 3594 | __ Lsl(o_h, low, temp, PL); |
| 3595 | // Shift the low part |
| 3596 | __ Lsl(o_l, low, o_l); |
| 3597 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3598 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3599 | // Shift the low part |
| 3600 | __ Lsr(o_l, low, o_h); |
| 3601 | // Shift the high part and `or` what underflew on the low part |
| 3602 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3603 | __ Lsl(temp, high, temp); |
| 3604 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3605 | // If the shift is > 32 bits, override the low part |
| 3606 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3607 | __ it(PL); |
| 3608 | __ Asr(o_l, high, temp, PL); |
| 3609 | // Shift the high part |
| 3610 | __ Asr(o_h, high, o_h); |
| 3611 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3612 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3613 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3614 | __ Lsr(o_l, low, o_h); |
| 3615 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3616 | __ Lsl(temp, high, temp); |
| 3617 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3618 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3619 | __ it(PL); |
| 3620 | __ Lsr(o_l, high, temp, PL); |
| 3621 | __ Lsr(o_h, high, o_h); |
| 3622 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3623 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3624 | // Register allocator doesn't create partial overlap. |
| 3625 | DCHECK_NE(o_l, high); |
| 3626 | DCHECK_NE(o_h, low); |
| 3627 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3628 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3629 | if (shift_value > 32) { |
| 3630 | if (op->IsShl()) { |
| 3631 | __ Lsl(o_h, low, shift_value - 32); |
| 3632 | __ LoadImmediate(o_l, 0); |
| 3633 | } else if (op->IsShr()) { |
| 3634 | __ Asr(o_l, high, shift_value - 32); |
| 3635 | __ Asr(o_h, high, 31); |
| 3636 | } else { |
| 3637 | __ Lsr(o_l, high, shift_value - 32); |
| 3638 | __ LoadImmediate(o_h, 0); |
| 3639 | } |
| 3640 | } else if (shift_value == 32) { |
| 3641 | if (op->IsShl()) { |
| 3642 | __ mov(o_h, ShifterOperand(low)); |
| 3643 | __ LoadImmediate(o_l, 0); |
| 3644 | } else if (op->IsShr()) { |
| 3645 | __ mov(o_l, ShifterOperand(high)); |
| 3646 | __ Asr(o_h, high, 31); |
| 3647 | } else { |
| 3648 | __ mov(o_l, ShifterOperand(high)); |
| 3649 | __ LoadImmediate(o_h, 0); |
| 3650 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3651 | } else if (shift_value == 1) { |
| 3652 | if (op->IsShl()) { |
| 3653 | __ Lsls(o_l, low, 1); |
| 3654 | __ adc(o_h, high, ShifterOperand(high)); |
| 3655 | } else if (op->IsShr()) { |
| 3656 | __ Asrs(o_h, high, 1); |
| 3657 | __ Rrx(o_l, low); |
| 3658 | } else { |
| 3659 | __ Lsrs(o_h, high, 1); |
| 3660 | __ Rrx(o_l, low); |
| 3661 | } |
| 3662 | } else { |
| 3663 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3664 | if (op->IsShl()) { |
| 3665 | __ Lsl(o_h, high, shift_value); |
| 3666 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3667 | __ Lsl(o_l, low, shift_value); |
| 3668 | } else if (op->IsShr()) { |
| 3669 | __ Lsr(o_l, low, shift_value); |
| 3670 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3671 | __ Asr(o_h, high, shift_value); |
| 3672 | } else { |
| 3673 | __ Lsr(o_l, low, shift_value); |
| 3674 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3675 | __ Lsr(o_h, high, shift_value); |
| 3676 | } |
| 3677 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3678 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3679 | break; |
| 3680 | } |
| 3681 | default: |
| 3682 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3683 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3688 | HandleShift(shl); |
| 3689 | } |
| 3690 | |
| 3691 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3692 | HandleShift(shl); |
| 3693 | } |
| 3694 | |
| 3695 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3696 | HandleShift(shr); |
| 3697 | } |
| 3698 | |
| 3699 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3700 | HandleShift(shr); |
| 3701 | } |
| 3702 | |
| 3703 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3704 | HandleShift(ushr); |
| 3705 | } |
| 3706 | |
| 3707 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3708 | HandleShift(ushr); |
| 3709 | } |
| 3710 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3711 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3712 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3713 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3714 | if (instruction->IsStringAlloc()) { |
| 3715 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3716 | } else { |
| 3717 | InvokeRuntimeCallingConvention calling_convention; |
| 3718 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3719 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3720 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3721 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3725 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3726 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3727 | if (instruction->IsStringAlloc()) { |
| 3728 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3729 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3730 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3731 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3732 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3733 | __ blx(LR); |
| 3734 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3735 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3736 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3737 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3738 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3741 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3742 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3743 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3744 | InvokeRuntimeCallingConvention calling_convention; |
| 3745 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3746 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3747 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3748 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3752 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3753 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3754 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3755 | // of poisoning the reference. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3756 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3757 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3758 | } |
| 3759 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3760 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3761 | LocationSummary* locations = |
| 3762 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3763 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3764 | if (location.IsStackSlot()) { |
| 3765 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3766 | } else if (location.IsDoubleStackSlot()) { |
| 3767 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3768 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3769 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3770 | } |
| 3771 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3772 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3773 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3774 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3778 | LocationSummary* locations = |
| 3779 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3780 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3781 | } |
| 3782 | |
| 3783 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3784 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3785 | } |
| 3786 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3787 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3788 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3789 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3790 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3791 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3792 | } |
| 3793 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3794 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3795 | LocationSummary* locations = not_->GetLocations(); |
| 3796 | Location out = locations->Out(); |
| 3797 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3798 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3799 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3800 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3801 | break; |
| 3802 | |
| 3803 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3804 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3805 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3806 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3807 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3808 | break; |
| 3809 | |
| 3810 | default: |
| 3811 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3812 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3813 | } |
| 3814 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3815 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3816 | LocationSummary* locations = |
| 3817 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3818 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3819 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3820 | } |
| 3821 | |
| 3822 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3823 | LocationSummary* locations = bool_not->GetLocations(); |
| 3824 | Location out = locations->Out(); |
| 3825 | Location in = locations->InAt(0); |
| 3826 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3827 | } |
| 3828 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3829 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3830 | LocationSummary* locations = |
| 3831 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3832 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3833 | case Primitive::kPrimBoolean: |
| 3834 | case Primitive::kPrimByte: |
| 3835 | case Primitive::kPrimShort: |
| 3836 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3837 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3838 | case Primitive::kPrimLong: { |
| 3839 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3840 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3841 | // Output overlaps because it is written before doing the low comparison. |
| 3842 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3843 | break; |
| 3844 | } |
| 3845 | case Primitive::kPrimFloat: |
| 3846 | case Primitive::kPrimDouble: { |
| 3847 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3848 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3849 | locations->SetOut(Location::RequiresRegister()); |
| 3850 | break; |
| 3851 | } |
| 3852 | default: |
| 3853 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3854 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3858 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3859 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3860 | Location left = locations->InAt(0); |
| 3861 | Location right = locations->InAt(1); |
| 3862 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3863 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3864 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3865 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3866 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3867 | case Primitive::kPrimBoolean: |
| 3868 | case Primitive::kPrimByte: |
| 3869 | case Primitive::kPrimShort: |
| 3870 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3871 | case Primitive::kPrimInt: { |
| 3872 | __ LoadImmediate(out, 0); |
| 3873 | __ cmp(left.AsRegister<Register>(), |
| 3874 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3875 | less_cond = LT; |
| 3876 | break; |
| 3877 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3878 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3879 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3880 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3881 | __ b(&less, LT); |
| 3882 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3883 | // 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] | 3884 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3885 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3886 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3887 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3888 | break; |
| 3889 | } |
| 3890 | case Primitive::kPrimFloat: |
| 3891 | case Primitive::kPrimDouble: { |
| 3892 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3893 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3894 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3895 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3896 | break; |
| 3897 | } |
| 3898 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3899 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3900 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3901 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3902 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3903 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3904 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3905 | |
| 3906 | __ Bind(&greater); |
| 3907 | __ LoadImmediate(out, 1); |
| 3908 | __ b(&done); |
| 3909 | |
| 3910 | __ Bind(&less); |
| 3911 | __ LoadImmediate(out, -1); |
| 3912 | |
| 3913 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3914 | } |
| 3915 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3916 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3917 | LocationSummary* locations = |
| 3918 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3919 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3920 | locations->SetInAt(i, Location::Any()); |
| 3921 | } |
| 3922 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3923 | } |
| 3924 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3925 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3926 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3927 | } |
| 3928 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3929 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3930 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3931 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3932 | switch (kind) { |
| 3933 | case MemBarrierKind::kAnyStore: |
| 3934 | case MemBarrierKind::kLoadAny: |
| 3935 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3936 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3937 | break; |
| 3938 | } |
| 3939 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3940 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3941 | break; |
| 3942 | } |
| 3943 | default: |
| 3944 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3945 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3946 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3950 | uint32_t offset, |
| 3951 | Register out_lo, |
| 3952 | Register out_hi) { |
| 3953 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3954 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3955 | // `offset` into `out_lo` does not clutter `addr`. |
| 3956 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3957 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3958 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3959 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3960 | } |
| 3961 | __ ldrexd(out_lo, out_hi, addr); |
| 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3965 | uint32_t offset, |
| 3966 | Register value_lo, |
| 3967 | Register value_hi, |
| 3968 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3969 | Register temp2, |
| 3970 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3971 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3972 | if (offset != 0) { |
| 3973 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3974 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3975 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3976 | } |
| 3977 | __ Bind(&fail); |
| 3978 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3979 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3980 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3981 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3982 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3983 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3987 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3988 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3989 | LocationSummary* locations = |
| 3990 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3991 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3992 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3993 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3994 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3995 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3996 | } else { |
| 3997 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3998 | } |
| 3999 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4000 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4001 | bool generate_volatile = field_info.IsVolatile() |
| 4002 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4003 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4004 | bool needs_write_barrier = |
| 4005 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4006 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4007 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4008 | if (needs_write_barrier) { |
| 4009 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4010 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4011 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4012 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4013 | // - registers need to be consecutive |
| 4014 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4015 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4016 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4017 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4018 | |
| 4019 | locations->AddTemp(Location::RequiresRegister()); |
| 4020 | locations->AddTemp(Location::RequiresRegister()); |
| 4021 | if (field_type == Primitive::kPrimDouble) { |
| 4022 | // For doubles we need two more registers to copy the value. |
| 4023 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4024 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4025 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4026 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4029 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4030 | const FieldInfo& field_info, |
| 4031 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4032 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4033 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4034 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4035 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4036 | Location value = locations->InAt(1); |
| 4037 | |
| 4038 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4039 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4040 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4041 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4042 | bool needs_write_barrier = |
| 4043 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4044 | |
| 4045 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4046 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4047 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4048 | |
| 4049 | switch (field_type) { |
| 4050 | case Primitive::kPrimBoolean: |
| 4051 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4052 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4053 | break; |
| 4054 | } |
| 4055 | |
| 4056 | case Primitive::kPrimShort: |
| 4057 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4058 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4059 | break; |
| 4060 | } |
| 4061 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4062 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4063 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4064 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4065 | // Note that in the case where `value` is a null reference, |
| 4066 | // we do not enter this block, as a null reference does not |
| 4067 | // need poisoning. |
| 4068 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4069 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4070 | __ Mov(temp, value.AsRegister<Register>()); |
| 4071 | __ PoisonHeapReference(temp); |
| 4072 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4073 | } else { |
| 4074 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4075 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4076 | break; |
| 4077 | } |
| 4078 | |
| 4079 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4080 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4081 | GenerateWideAtomicStore(base, offset, |
| 4082 | value.AsRegisterPairLow<Register>(), |
| 4083 | value.AsRegisterPairHigh<Register>(), |
| 4084 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4085 | locations->GetTemp(1).AsRegister<Register>(), |
| 4086 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4087 | } else { |
| 4088 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4089 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4090 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4091 | break; |
| 4092 | } |
| 4093 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4094 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4095 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4096 | break; |
| 4097 | } |
| 4098 | |
| 4099 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4100 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4101 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4102 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4103 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4104 | |
| 4105 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4106 | |
| 4107 | GenerateWideAtomicStore(base, offset, |
| 4108 | value_reg_lo, |
| 4109 | value_reg_hi, |
| 4110 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4111 | locations->GetTemp(3).AsRegister<Register>(), |
| 4112 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4113 | } else { |
| 4114 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4115 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4116 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4117 | break; |
| 4118 | } |
| 4119 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4120 | case Primitive::kPrimVoid: |
| 4121 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4122 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4123 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4124 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4125 | // Longs and doubles are handled in the switch. |
| 4126 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4127 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4128 | } |
| 4129 | |
| 4130 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4131 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4132 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4133 | codegen_->MarkGCCard( |
| 4134 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4137 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4138 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4139 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4142 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4143 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4144 | |
| 4145 | bool object_field_get_with_read_barrier = |
| 4146 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4147 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4148 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4149 | object_field_get_with_read_barrier ? |
| 4150 | LocationSummary::kCallOnSlowPath : |
| 4151 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4152 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4153 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4154 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4155 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4156 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4157 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4158 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4159 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4160 | // The output overlaps in case of volatile long: we don't want the |
| 4161 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4162 | // object's location. Likewise, in the case of an object field get |
| 4163 | // with read barriers enabled, we do not want the load to overwrite |
| 4164 | // the object's location, as we need it to emit the read barrier. |
| 4165 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4166 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4167 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4168 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4169 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4170 | } else { |
| 4171 | locations->SetOut(Location::RequiresRegister(), |
| 4172 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4173 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4174 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4175 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4176 | // - registers need to be consecutive |
| 4177 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4178 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4179 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4180 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4181 | locations->AddTemp(Location::RequiresRegister()); |
| 4182 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4183 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4184 | // We need a temporary register for the read barrier marking slow |
| 4185 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4186 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4187 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4188 | } |
| 4189 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4190 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4191 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4192 | << input->GetType(); |
| 4193 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4194 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4195 | return Location::ConstantLocation(input->AsConstant()); |
| 4196 | } else { |
| 4197 | return Location::RequiresFpuRegister(); |
| 4198 | } |
| 4199 | } |
| 4200 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4201 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4202 | Opcode opcode) { |
| 4203 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4204 | if (constant->IsConstant() && |
| 4205 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4206 | return Location::ConstantLocation(constant->AsConstant()); |
| 4207 | } |
| 4208 | return Location::RequiresRegister(); |
| 4209 | } |
| 4210 | |
| 4211 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4212 | Opcode opcode) { |
| 4213 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4214 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4215 | Opcode high_opcode = opcode; |
| 4216 | SetCc low_set_cc = kCcDontCare; |
| 4217 | switch (opcode) { |
| 4218 | case SUB: |
| 4219 | // Flip the operation to an ADD. |
| 4220 | value = -value; |
| 4221 | opcode = ADD; |
| 4222 | FALLTHROUGH_INTENDED; |
| 4223 | case ADD: |
| 4224 | if (Low32Bits(value) == 0u) { |
| 4225 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4226 | } |
| 4227 | high_opcode = ADC; |
| 4228 | low_set_cc = kCcSet; |
| 4229 | break; |
| 4230 | default: |
| 4231 | break; |
| 4232 | } |
| 4233 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4234 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4235 | } else { |
| 4236 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4237 | } |
| 4238 | } |
| 4239 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4240 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4241 | Opcode opcode, |
| 4242 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4243 | ShifterOperand so; |
| 4244 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4245 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4246 | return true; |
| 4247 | } |
| 4248 | Opcode neg_opcode = kNoOperand; |
| 4249 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4250 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4251 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4252 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4253 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4254 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4255 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4256 | default: |
| 4257 | return false; |
| 4258 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4259 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4260 | } |
| 4261 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4262 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4263 | const FieldInfo& field_info) { |
| 4264 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4265 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4266 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4267 | Location base_loc = locations->InAt(0); |
| 4268 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4269 | Location out = locations->Out(); |
| 4270 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4271 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4272 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4273 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4274 | |
| 4275 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4276 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4277 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4278 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4279 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4280 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4281 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4282 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4283 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4284 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4285 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4286 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4287 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4288 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4289 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4290 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4291 | |
| 4292 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4293 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4294 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4295 | |
| 4296 | case Primitive::kPrimNot: { |
| 4297 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4298 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4299 | Location temp_loc = locations->GetTemp(0); |
| 4300 | // Note that a potential implicit null check is handled in this |
| 4301 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4302 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4303 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4304 | if (is_volatile) { |
| 4305 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4306 | } |
| 4307 | } else { |
| 4308 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4309 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4310 | if (is_volatile) { |
| 4311 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4312 | } |
| 4313 | // If read barriers are enabled, emit read barriers other than |
| 4314 | // Baker's using a slow path (and also unpoison the loaded |
| 4315 | // reference, if heap poisoning is enabled). |
| 4316 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4317 | } |
| 4318 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4321 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4322 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4323 | GenerateWideAtomicLoad(base, offset, |
| 4324 | out.AsRegisterPairLow<Register>(), |
| 4325 | out.AsRegisterPairHigh<Register>()); |
| 4326 | } else { |
| 4327 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4328 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4329 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4330 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4331 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4332 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4333 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4334 | |
| 4335 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4336 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4337 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4338 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4339 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4340 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4341 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4342 | __ vmovdrr(out_reg, lo, hi); |
| 4343 | } else { |
| 4344 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4346 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4347 | break; |
| 4348 | } |
| 4349 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4350 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4351 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4352 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4353 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4354 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4355 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4356 | // Potential implicit null checks, in the case of reference or |
| 4357 | // double fields, are handled in the previous switch statement. |
| 4358 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4359 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4360 | } |
| 4361 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4362 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4363 | if (field_type == Primitive::kPrimNot) { |
| 4364 | // Memory barriers, in the case of references, are also handled |
| 4365 | // in the previous switch statement. |
| 4366 | } else { |
| 4367 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4368 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4369 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4373 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4374 | } |
| 4375 | |
| 4376 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4377 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4381 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4382 | } |
| 4383 | |
| 4384 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4385 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4386 | } |
| 4387 | |
| 4388 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4389 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4390 | } |
| 4391 | |
| 4392 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4393 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4394 | } |
| 4395 | |
| 4396 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4397 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4398 | } |
| 4399 | |
| 4400 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4401 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4402 | } |
| 4403 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4404 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4405 | HUnresolvedInstanceFieldGet* instruction) { |
| 4406 | FieldAccessCallingConventionARM calling_convention; |
| 4407 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4408 | instruction, instruction->GetFieldType(), calling_convention); |
| 4409 | } |
| 4410 | |
| 4411 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4412 | HUnresolvedInstanceFieldGet* instruction) { |
| 4413 | FieldAccessCallingConventionARM calling_convention; |
| 4414 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4415 | instruction->GetFieldType(), |
| 4416 | instruction->GetFieldIndex(), |
| 4417 | instruction->GetDexPc(), |
| 4418 | calling_convention); |
| 4419 | } |
| 4420 | |
| 4421 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4422 | HUnresolvedInstanceFieldSet* instruction) { |
| 4423 | FieldAccessCallingConventionARM calling_convention; |
| 4424 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4425 | instruction, instruction->GetFieldType(), calling_convention); |
| 4426 | } |
| 4427 | |
| 4428 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4429 | HUnresolvedInstanceFieldSet* instruction) { |
| 4430 | FieldAccessCallingConventionARM calling_convention; |
| 4431 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4432 | instruction->GetFieldType(), |
| 4433 | instruction->GetFieldIndex(), |
| 4434 | instruction->GetDexPc(), |
| 4435 | calling_convention); |
| 4436 | } |
| 4437 | |
| 4438 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4439 | HUnresolvedStaticFieldGet* instruction) { |
| 4440 | FieldAccessCallingConventionARM calling_convention; |
| 4441 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4442 | instruction, instruction->GetFieldType(), calling_convention); |
| 4443 | } |
| 4444 | |
| 4445 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4446 | HUnresolvedStaticFieldGet* instruction) { |
| 4447 | FieldAccessCallingConventionARM calling_convention; |
| 4448 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4449 | instruction->GetFieldType(), |
| 4450 | instruction->GetFieldIndex(), |
| 4451 | instruction->GetDexPc(), |
| 4452 | calling_convention); |
| 4453 | } |
| 4454 | |
| 4455 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4456 | HUnresolvedStaticFieldSet* instruction) { |
| 4457 | FieldAccessCallingConventionARM calling_convention; |
| 4458 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4459 | instruction, instruction->GetFieldType(), calling_convention); |
| 4460 | } |
| 4461 | |
| 4462 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4463 | HUnresolvedStaticFieldSet* instruction) { |
| 4464 | FieldAccessCallingConventionARM calling_convention; |
| 4465 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4466 | instruction->GetFieldType(), |
| 4467 | instruction->GetFieldIndex(), |
| 4468 | instruction->GetDexPc(), |
| 4469 | calling_convention); |
| 4470 | } |
| 4471 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4472 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4473 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4474 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4475 | } |
| 4476 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4477 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4478 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4479 | return; |
| 4480 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4481 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4482 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4483 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4484 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4487 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4488 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4489 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4490 | |
| 4491 | LocationSummary* locations = instruction->GetLocations(); |
| 4492 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4493 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4494 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4495 | } |
| 4496 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4497 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4498 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4499 | } |
| 4500 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4501 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4502 | switch (type) { |
| 4503 | case Primitive::kPrimNot: |
| 4504 | return kLoadWord; |
| 4505 | case Primitive::kPrimBoolean: |
| 4506 | return kLoadUnsignedByte; |
| 4507 | case Primitive::kPrimByte: |
| 4508 | return kLoadSignedByte; |
| 4509 | case Primitive::kPrimChar: |
| 4510 | return kLoadUnsignedHalfword; |
| 4511 | case Primitive::kPrimShort: |
| 4512 | return kLoadSignedHalfword; |
| 4513 | case Primitive::kPrimInt: |
| 4514 | return kLoadWord; |
| 4515 | case Primitive::kPrimLong: |
| 4516 | return kLoadWordPair; |
| 4517 | case Primitive::kPrimFloat: |
| 4518 | return kLoadSWord; |
| 4519 | case Primitive::kPrimDouble: |
| 4520 | return kLoadDWord; |
| 4521 | default: |
| 4522 | LOG(FATAL) << "Unreachable type " << type; |
| 4523 | UNREACHABLE(); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4528 | switch (type) { |
| 4529 | case Primitive::kPrimNot: |
| 4530 | return kStoreWord; |
| 4531 | case Primitive::kPrimBoolean: |
| 4532 | case Primitive::kPrimByte: |
| 4533 | return kStoreByte; |
| 4534 | case Primitive::kPrimChar: |
| 4535 | case Primitive::kPrimShort: |
| 4536 | return kStoreHalfword; |
| 4537 | case Primitive::kPrimInt: |
| 4538 | return kStoreWord; |
| 4539 | case Primitive::kPrimLong: |
| 4540 | return kStoreWordPair; |
| 4541 | case Primitive::kPrimFloat: |
| 4542 | return kStoreSWord; |
| 4543 | case Primitive::kPrimDouble: |
| 4544 | return kStoreDWord; |
| 4545 | default: |
| 4546 | LOG(FATAL) << "Unreachable type " << type; |
| 4547 | UNREACHABLE(); |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4552 | Location out_loc, |
| 4553 | Register base, |
| 4554 | Register reg_offset, |
| 4555 | Condition cond) { |
| 4556 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4557 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4558 | |
| 4559 | switch (type) { |
| 4560 | case Primitive::kPrimByte: |
| 4561 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4562 | break; |
| 4563 | case Primitive::kPrimBoolean: |
| 4564 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4565 | break; |
| 4566 | case Primitive::kPrimShort: |
| 4567 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4568 | break; |
| 4569 | case Primitive::kPrimChar: |
| 4570 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4571 | break; |
| 4572 | case Primitive::kPrimNot: |
| 4573 | case Primitive::kPrimInt: |
| 4574 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4575 | break; |
| 4576 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4577 | case Primitive::kPrimLong: |
| 4578 | case Primitive::kPrimFloat: |
| 4579 | case Primitive::kPrimDouble: |
| 4580 | default: |
| 4581 | LOG(FATAL) << "Unreachable type " << type; |
| 4582 | UNREACHABLE(); |
| 4583 | } |
| 4584 | } |
| 4585 | |
| 4586 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4587 | Location loc, |
| 4588 | Register base, |
| 4589 | Register reg_offset, |
| 4590 | Condition cond) { |
| 4591 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4592 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4593 | |
| 4594 | switch (type) { |
| 4595 | case Primitive::kPrimByte: |
| 4596 | case Primitive::kPrimBoolean: |
| 4597 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4598 | break; |
| 4599 | case Primitive::kPrimShort: |
| 4600 | case Primitive::kPrimChar: |
| 4601 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4602 | break; |
| 4603 | case Primitive::kPrimNot: |
| 4604 | case Primitive::kPrimInt: |
| 4605 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4606 | break; |
| 4607 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4608 | case Primitive::kPrimLong: |
| 4609 | case Primitive::kPrimFloat: |
| 4610 | case Primitive::kPrimDouble: |
| 4611 | default: |
| 4612 | LOG(FATAL) << "Unreachable type " << type; |
| 4613 | UNREACHABLE(); |
| 4614 | } |
| 4615 | } |
| 4616 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4617 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4618 | bool object_array_get_with_read_barrier = |
| 4619 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4620 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4621 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4622 | object_array_get_with_read_barrier ? |
| 4623 | LocationSummary::kCallOnSlowPath : |
| 4624 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4625 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4626 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4627 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4629 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4630 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4631 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4632 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4633 | // The output overlaps in the case of an object array get with |
| 4634 | // read barriers enabled: we do not want the move to overwrite the |
| 4635 | // array's location, as we need it to emit the read barrier. |
| 4636 | locations->SetOut( |
| 4637 | Location::RequiresRegister(), |
| 4638 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4639 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4640 | // We need a temporary register for the read barrier marking slow |
| 4641 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4642 | // Also need for String compression feature. |
| 4643 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4644 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4645 | locations->AddTemp(Location::RequiresRegister()); |
| 4646 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4650 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4651 | Location obj_loc = locations->InAt(0); |
| 4652 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4653 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4654 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4655 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4656 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4657 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4658 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4659 | HInstruction* array_instr = instruction->GetArray(); |
| 4660 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4661 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4662 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4663 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4664 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4665 | case Primitive::kPrimBoolean: |
| 4666 | case Primitive::kPrimByte: |
| 4667 | case Primitive::kPrimShort: |
| 4668 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4669 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4670 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4671 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4672 | if (maybe_compressed_char_at) { |
| 4673 | Register length = IP; |
| 4674 | Label uncompressed_load, done; |
| 4675 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4676 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4677 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4678 | __ cmp(length, ShifterOperand(0)); |
| 4679 | __ b(&uncompressed_load, GE); |
| 4680 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4681 | out_loc.AsRegister<Register>(), |
| 4682 | obj, |
| 4683 | data_offset + const_index); |
| 4684 | __ b(&done); |
| 4685 | __ Bind(&uncompressed_load); |
| 4686 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4687 | out_loc.AsRegister<Register>(), |
| 4688 | obj, |
| 4689 | data_offset + (const_index << 1)); |
| 4690 | __ Bind(&done); |
| 4691 | } else { |
| 4692 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4693 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4694 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4695 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4696 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4697 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4698 | Register temp = IP; |
| 4699 | |
| 4700 | if (has_intermediate_address) { |
| 4701 | // We do not need to compute the intermediate address from the array: the |
| 4702 | // input instruction has done it already. See the comment in |
| 4703 | // `TryExtractArrayAccessAddress()`. |
| 4704 | if (kIsDebugBuild) { |
| 4705 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4706 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4707 | } |
| 4708 | temp = obj; |
| 4709 | } else { |
| 4710 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4711 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4712 | if (maybe_compressed_char_at) { |
| 4713 | Label uncompressed_load, done; |
| 4714 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4715 | Register length = locations->GetTemp(0).AsRegister<Register>(); |
| 4716 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4717 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4718 | __ cmp(length, ShifterOperand(0)); |
| 4719 | __ b(&uncompressed_load, GE); |
| 4720 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4721 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4722 | __ b(&done); |
| 4723 | __ Bind(&uncompressed_load); |
| 4724 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4725 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4726 | __ Bind(&done); |
| 4727 | } else { |
| 4728 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4729 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4730 | } |
| 4731 | break; |
| 4732 | } |
| 4733 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4734 | case Primitive::kPrimNot: { |
| 4735 | static_assert( |
| 4736 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4737 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4738 | // /* HeapReference<Object> */ out = |
| 4739 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4740 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4741 | Location temp = locations->GetTemp(0); |
| 4742 | // Note that a potential implicit null check is handled in this |
| 4743 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4744 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4745 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4746 | } else { |
| 4747 | Register out = out_loc.AsRegister<Register>(); |
| 4748 | if (index.IsConstant()) { |
| 4749 | size_t offset = |
| 4750 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4751 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4752 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4753 | // If read barriers are enabled, emit read barriers other than |
| 4754 | // Baker's using a slow path (and also unpoison the loaded |
| 4755 | // reference, if heap poisoning is enabled). |
| 4756 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4757 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4758 | Register temp = IP; |
| 4759 | |
| 4760 | if (has_intermediate_address) { |
| 4761 | // We do not need to compute the intermediate address from the array: the |
| 4762 | // input instruction has done it already. See the comment in |
| 4763 | // `TryExtractArrayAccessAddress()`. |
| 4764 | if (kIsDebugBuild) { |
| 4765 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4766 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4767 | } |
| 4768 | temp = obj; |
| 4769 | } else { |
| 4770 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4771 | } |
| 4772 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4773 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4774 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4775 | // If read barriers are enabled, emit read barriers other than |
| 4776 | // Baker's using a slow path (and also unpoison the loaded |
| 4777 | // reference, if heap poisoning is enabled). |
| 4778 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4779 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4780 | } |
| 4781 | } |
| 4782 | break; |
| 4783 | } |
| 4784 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4785 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4786 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4787 | size_t offset = |
| 4788 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4789 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4790 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4791 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4792 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4793 | } |
| 4794 | break; |
| 4795 | } |
| 4796 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4797 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4798 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4799 | if (index.IsConstant()) { |
| 4800 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4801 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4802 | } else { |
| 4803 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4804 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4805 | } |
| 4806 | break; |
| 4807 | } |
| 4808 | |
| 4809 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4810 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4811 | if (index.IsConstant()) { |
| 4812 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4813 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4814 | } else { |
| 4815 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4816 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4817 | } |
| 4818 | break; |
| 4819 | } |
| 4820 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4821 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4822 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4823 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4824 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4825 | |
| 4826 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4827 | // Potential implicit null checks, in the case of reference |
| 4828 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4829 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4830 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4831 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4835 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4836 | |
| 4837 | bool needs_write_barrier = |
| 4838 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4839 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4840 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4841 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4842 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4843 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4844 | LocationSummary::kCallOnSlowPath : |
| 4845 | LocationSummary::kNoCall); |
| 4846 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4848 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4849 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4850 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4851 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4852 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4853 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4854 | if (needs_write_barrier) { |
| 4855 | // Temporary registers for the write barrier. |
| 4856 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4857 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4858 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4862 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4863 | Location array_loc = locations->InAt(0); |
| 4864 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4865 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4866 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4867 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4868 | bool needs_write_barrier = |
| 4869 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4870 | uint32_t data_offset = |
| 4871 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 4872 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4873 | HInstruction* array_instr = instruction->GetArray(); |
| 4874 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4875 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4876 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4877 | |
| 4878 | switch (value_type) { |
| 4879 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4880 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4881 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4882 | case Primitive::kPrimChar: |
| 4883 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4884 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4885 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4886 | uint32_t full_offset = |
| 4887 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 4888 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 4889 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4890 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4891 | Register temp = IP; |
| 4892 | |
| 4893 | if (has_intermediate_address) { |
| 4894 | // We do not need to compute the intermediate address from the array: the |
| 4895 | // input instruction has done it already. See the comment in |
| 4896 | // `TryExtractArrayAccessAddress()`. |
| 4897 | if (kIsDebugBuild) { |
| 4898 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4899 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 4900 | } |
| 4901 | temp = array; |
| 4902 | } else { |
| 4903 | __ add(temp, array, ShifterOperand(data_offset)); |
| 4904 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4905 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4906 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4907 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4908 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4909 | } |
| 4910 | break; |
| 4911 | } |
| 4912 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4913 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4914 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4915 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 4916 | // See the comment in instruction_simplifier_shared.cc. |
| 4917 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4918 | |
| 4919 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4920 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4921 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4922 | size_t offset = |
| 4923 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4924 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4925 | } else { |
| 4926 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4927 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4928 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4929 | value_loc, |
| 4930 | IP, |
| 4931 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4932 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4933 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4934 | DCHECK(!needs_write_barrier); |
| 4935 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4936 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4937 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4938 | |
| 4939 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4940 | Location temp1_loc = locations->GetTemp(0); |
| 4941 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 4942 | Location temp2_loc = locations->GetTemp(1); |
| 4943 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4944 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4945 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4946 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4947 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4948 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4949 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4950 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4951 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4952 | codegen_->AddSlowPath(slow_path); |
| 4953 | if (instruction->GetValueCanBeNull()) { |
| 4954 | Label non_zero; |
| 4955 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4956 | if (index.IsConstant()) { |
| 4957 | size_t offset = |
| 4958 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4959 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4960 | } else { |
| 4961 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4962 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4963 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4964 | value_loc, |
| 4965 | IP, |
| 4966 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4967 | } |
| 4968 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4969 | __ b(&done); |
| 4970 | __ Bind(&non_zero); |
| 4971 | } |
| 4972 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4973 | // Note that when read barriers are enabled, the type checks |
| 4974 | // are performed without read barriers. This is fine, even in |
| 4975 | // the case where a class object is in the from-space after |
| 4976 | // the flip, as a comparison involving such a type would not |
| 4977 | // produce a false positive; it may of course produce a false |
| 4978 | // negative, in which case we would take the ArraySet slow |
| 4979 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4980 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4981 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4982 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4983 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4984 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4985 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4986 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4987 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4988 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4989 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4990 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4991 | // nor `temp2`, as we are comparing two poisoned references. |
| 4992 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4993 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4994 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4995 | Label do_put; |
| 4996 | __ b(&do_put, EQ); |
| 4997 | // If heap poisoning is enabled, the `temp1` reference has |
| 4998 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4999 | __ MaybeUnpoisonHeapReference(temp1); |
| 5000 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5001 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5002 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5003 | // If heap poisoning is enabled, no need to unpoison |
| 5004 | // `temp1`, as we are comparing against null below. |
| 5005 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5006 | __ Bind(&do_put); |
| 5007 | } else { |
| 5008 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5009 | } |
| 5010 | } |
| 5011 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5012 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5013 | if (kPoisonHeapReferences) { |
| 5014 | // Note that in the case where `value` is a null reference, |
| 5015 | // we do not enter this block, as a null reference does not |
| 5016 | // need poisoning. |
| 5017 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5018 | __ Mov(temp1, value); |
| 5019 | __ PoisonHeapReference(temp1); |
| 5020 | source = temp1; |
| 5021 | } |
| 5022 | |
| 5023 | if (index.IsConstant()) { |
| 5024 | size_t offset = |
| 5025 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5026 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5027 | } else { |
| 5028 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5029 | |
| 5030 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5031 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5032 | Location::RegisterLocation(source), |
| 5033 | IP, |
| 5034 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5035 | } |
| 5036 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5037 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5038 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5039 | } |
| 5040 | |
| 5041 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5042 | |
| 5043 | if (done.IsLinked()) { |
| 5044 | __ Bind(&done); |
| 5045 | } |
| 5046 | |
| 5047 | if (slow_path != nullptr) { |
| 5048 | __ Bind(slow_path->GetExitLabel()); |
| 5049 | } |
| 5050 | |
| 5051 | break; |
| 5052 | } |
| 5053 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5055 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5056 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5057 | size_t offset = |
| 5058 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5059 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5061 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5062 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5063 | } |
| 5064 | break; |
| 5065 | } |
| 5066 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5067 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5068 | Location value = locations->InAt(2); |
| 5069 | DCHECK(value.IsFpuRegister()); |
| 5070 | if (index.IsConstant()) { |
| 5071 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5072 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5073 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5074 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5075 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5076 | } |
| 5077 | break; |
| 5078 | } |
| 5079 | |
| 5080 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5081 | Location value = locations->InAt(2); |
| 5082 | DCHECK(value.IsFpuRegisterPair()); |
| 5083 | if (index.IsConstant()) { |
| 5084 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5085 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5086 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5087 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5088 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5089 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5090 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5091 | break; |
| 5092 | } |
| 5093 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5094 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5095 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5096 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5097 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5098 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5099 | // Objects are handled in the switch. |
| 5100 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5101 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5102 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5106 | LocationSummary* locations = |
| 5107 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5108 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5109 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5113 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5114 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5115 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5116 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5117 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5118 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5119 | // Mask out compression flag from String's array length. |
| 5120 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5121 | __ bic(out, out, ShifterOperand(1u << 31)); |
| 5122 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5123 | } |
| 5124 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5125 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5126 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5127 | DCHECK(!kEmitCompilerReadBarrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5128 | LocationSummary* locations = |
| 5129 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5130 | |
| 5131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5132 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5133 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5134 | } |
| 5135 | |
| 5136 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5137 | LocationSummary* locations = instruction->GetLocations(); |
| 5138 | Location out = locations->Out(); |
| 5139 | Location first = locations->InAt(0); |
| 5140 | Location second = locations->InAt(1); |
| 5141 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5142 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5143 | DCHECK(!kEmitCompilerReadBarrier); |
| 5144 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5145 | if (second.IsRegister()) { |
| 5146 | __ add(out.AsRegister<Register>(), |
| 5147 | first.AsRegister<Register>(), |
| 5148 | ShifterOperand(second.AsRegister<Register>())); |
| 5149 | } else { |
| 5150 | __ AddConstant(out.AsRegister<Register>(), |
| 5151 | first.AsRegister<Register>(), |
| 5152 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5153 | } |
| 5154 | } |
| 5155 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5156 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5157 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5158 | InvokeRuntimeCallingConvention calling_convention; |
| 5159 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5160 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5161 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5162 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5163 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5167 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5168 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5169 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5170 | codegen_->AddSlowPath(slow_path); |
| 5171 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5172 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5173 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5174 | |
| 5175 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5176 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5177 | } |
| 5178 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5179 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5180 | Register card, |
| 5181 | Register object, |
| 5182 | Register value, |
| 5183 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5184 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5185 | if (can_be_null) { |
| 5186 | __ CompareAndBranchIfZero(value, &is_null); |
| 5187 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5188 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5189 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5190 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5191 | if (can_be_null) { |
| 5192 | __ Bind(&is_null); |
| 5193 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5194 | } |
| 5195 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5196 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5197 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5201 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5202 | } |
| 5203 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5204 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5205 | LocationSummary* locations = |
| 5206 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5207 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5211 | HBasicBlock* block = instruction->GetBlock(); |
| 5212 | if (block->GetLoopInformation() != nullptr) { |
| 5213 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5214 | // The back edge will generate the suspend check. |
| 5215 | return; |
| 5216 | } |
| 5217 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5218 | // The goto will generate the suspend check. |
| 5219 | return; |
| 5220 | } |
| 5221 | GenerateSuspendCheck(instruction, nullptr); |
| 5222 | } |
| 5223 | |
| 5224 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5225 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5226 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5227 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5228 | if (slow_path == nullptr) { |
| 5229 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5230 | instruction->SetSlowPath(slow_path); |
| 5231 | codegen_->AddSlowPath(slow_path); |
| 5232 | if (successor != nullptr) { |
| 5233 | DCHECK(successor->IsLoopHeader()); |
| 5234 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5235 | } |
| 5236 | } else { |
| 5237 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5238 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5239 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5240 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5241 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5242 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5243 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5244 | __ Bind(slow_path->GetReturnLabel()); |
| 5245 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5246 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5247 | __ b(slow_path->GetEntryLabel()); |
| 5248 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5251 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5252 | return codegen_->GetAssembler(); |
| 5253 | } |
| 5254 | |
| 5255 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5256 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5257 | Location source = move->GetSource(); |
| 5258 | Location destination = move->GetDestination(); |
| 5259 | |
| 5260 | if (source.IsRegister()) { |
| 5261 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5262 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5263 | } else if (destination.IsFpuRegister()) { |
| 5264 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5265 | } else { |
| 5266 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5267 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5268 | SP, destination.GetStackIndex()); |
| 5269 | } |
| 5270 | } else if (source.IsStackSlot()) { |
| 5271 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5272 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5273 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5274 | } else if (destination.IsFpuRegister()) { |
| 5275 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5276 | } else { |
| 5277 | DCHECK(destination.IsStackSlot()); |
| 5278 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5279 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5280 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5281 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5282 | if (destination.IsRegister()) { |
| 5283 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5284 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5285 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5286 | } else { |
| 5287 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5288 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5289 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5290 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5291 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5292 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5293 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5294 | } else if (destination.IsRegisterPair()) { |
| 5295 | DCHECK(ExpectedPairLayout(destination)); |
| 5296 | __ LoadFromOffset( |
| 5297 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5298 | } else { |
| 5299 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5300 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5301 | SP, |
| 5302 | source.GetStackIndex()); |
| 5303 | } |
| 5304 | } else if (source.IsRegisterPair()) { |
| 5305 | if (destination.IsRegisterPair()) { |
| 5306 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5307 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5308 | } else if (destination.IsFpuRegisterPair()) { |
| 5309 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5310 | source.AsRegisterPairLow<Register>(), |
| 5311 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5312 | } else { |
| 5313 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5314 | DCHECK(ExpectedPairLayout(source)); |
| 5315 | __ StoreToOffset( |
| 5316 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5317 | } |
| 5318 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5319 | if (destination.IsRegisterPair()) { |
| 5320 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5321 | destination.AsRegisterPairHigh<Register>(), |
| 5322 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5323 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5324 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5325 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5326 | } else { |
| 5327 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5328 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5329 | SP, |
| 5330 | destination.GetStackIndex()); |
| 5331 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5332 | } else { |
| 5333 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5334 | HConstant* constant = source.GetConstant(); |
| 5335 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5336 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5337 | if (destination.IsRegister()) { |
| 5338 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5339 | } else { |
| 5340 | DCHECK(destination.IsStackSlot()); |
| 5341 | __ LoadImmediate(IP, value); |
| 5342 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5343 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5344 | } else if (constant->IsLongConstant()) { |
| 5345 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5346 | if (destination.IsRegisterPair()) { |
| 5347 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5348 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5349 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5350 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5351 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5352 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5353 | __ LoadImmediate(IP, High32Bits(value)); |
| 5354 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5355 | } |
| 5356 | } else if (constant->IsDoubleConstant()) { |
| 5357 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5358 | if (destination.IsFpuRegisterPair()) { |
| 5359 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5360 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5361 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5362 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5363 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5364 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5365 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5366 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5367 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5368 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5369 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5370 | float value = constant->AsFloatConstant()->GetValue(); |
| 5371 | if (destination.IsFpuRegister()) { |
| 5372 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5373 | } else { |
| 5374 | DCHECK(destination.IsStackSlot()); |
| 5375 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5376 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5377 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5378 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5383 | __ Mov(IP, reg); |
| 5384 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5385 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5386 | } |
| 5387 | |
| 5388 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5389 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5390 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5391 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5392 | SP, mem1 + stack_offset); |
| 5393 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5394 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5395 | SP, mem2 + stack_offset); |
| 5396 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5397 | } |
| 5398 | |
| 5399 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5400 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5401 | Location source = move->GetSource(); |
| 5402 | Location destination = move->GetDestination(); |
| 5403 | |
| 5404 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5405 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5406 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5407 | __ Mov(IP, source.AsRegister<Register>()); |
| 5408 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5409 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5410 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5411 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5412 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5413 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5414 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5415 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5416 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5417 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5418 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5419 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5420 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5421 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5422 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5423 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5424 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5425 | destination.AsRegisterPairHigh<Register>(), |
| 5426 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5427 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5428 | Register low_reg = source.IsRegisterPair() |
| 5429 | ? source.AsRegisterPairLow<Register>() |
| 5430 | : destination.AsRegisterPairLow<Register>(); |
| 5431 | int mem = source.IsRegisterPair() |
| 5432 | ? destination.GetStackIndex() |
| 5433 | : source.GetStackIndex(); |
| 5434 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5435 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5436 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5437 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5438 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5439 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5440 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5441 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5442 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5443 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5444 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5445 | DRegister reg = source.IsFpuRegisterPair() |
| 5446 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5447 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5448 | int mem = source.IsFpuRegisterPair() |
| 5449 | ? destination.GetStackIndex() |
| 5450 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5451 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5452 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5453 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5454 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5455 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5456 | : destination.AsFpuRegister<SRegister>(); |
| 5457 | int mem = source.IsFpuRegister() |
| 5458 | ? destination.GetStackIndex() |
| 5459 | : source.GetStackIndex(); |
| 5460 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5461 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5462 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5463 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5464 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5465 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5466 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5467 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5468 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5473 | __ Push(static_cast<Register>(reg)); |
| 5474 | } |
| 5475 | |
| 5476 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5477 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5478 | } |
| 5479 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5480 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5481 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5482 | switch (desired_class_load_kind) { |
| 5483 | case HLoadClass::LoadKind::kReferrersClass: |
| 5484 | break; |
| 5485 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5486 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5487 | break; |
| 5488 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5489 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5490 | break; |
| 5491 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5492 | break; |
| 5493 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5494 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5495 | break; |
| 5496 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5497 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5498 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5499 | // is incompatible with it. |
| 5500 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5501 | // with irreducible loops. |
| 5502 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5503 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5504 | } |
| 5505 | break; |
| 5506 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5507 | break; |
| 5508 | } |
| 5509 | return desired_class_load_kind; |
| 5510 | } |
| 5511 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5512 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5513 | if (cls->NeedsAccessCheck()) { |
| 5514 | InvokeRuntimeCallingConvention calling_convention; |
| 5515 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5516 | cls, |
| 5517 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5518 | Location::RegisterLocation(R0), |
| 5519 | /* code_generator_supports_read_barrier */ true); |
| 5520 | return; |
| 5521 | } |
| 5522 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5523 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5524 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5525 | ? LocationSummary::kCallOnSlowPath |
| 5526 | : LocationSummary::kNoCall; |
| 5527 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5528 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5529 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5530 | } |
| 5531 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5532 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5533 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5534 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5535 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5537 | } |
| 5538 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5542 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5543 | if (cls->NeedsAccessCheck()) { |
| 5544 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5545 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5546 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5547 | return; |
| 5548 | } |
| 5549 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5550 | Location out_loc = locations->Out(); |
| 5551 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5552 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5553 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5554 | bool generate_null_check = false; |
| 5555 | switch (cls->GetLoadKind()) { |
| 5556 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5557 | DCHECK(!cls->CanCallRuntime()); |
| 5558 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5559 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5560 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5561 | GenerateGcRootFieldLoad(cls, |
| 5562 | out_loc, |
| 5563 | current_method, |
| 5564 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5565 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5566 | break; |
| 5567 | } |
| 5568 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5569 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5570 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5571 | cls->GetTypeIndex())); |
| 5572 | break; |
| 5573 | } |
| 5574 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5575 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5576 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5577 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5578 | __ BindTrackedLabel(&labels->movw_label); |
| 5579 | __ movw(out, /* placeholder */ 0u); |
| 5580 | __ BindTrackedLabel(&labels->movt_label); |
| 5581 | __ movt(out, /* placeholder */ 0u); |
| 5582 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5583 | __ add(out, out, ShifterOperand(PC)); |
| 5584 | break; |
| 5585 | } |
| 5586 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5587 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5588 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5589 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5590 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5591 | break; |
| 5592 | } |
| 5593 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5594 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5595 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5596 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5597 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5598 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5599 | // and the remaining offset embedded in the load. |
| 5600 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5601 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5602 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5603 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5604 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5605 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5606 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5607 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5608 | generate_null_check = !cls->IsInDexCache(); |
| 5609 | break; |
| 5610 | } |
| 5611 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5612 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5613 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5614 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5615 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5616 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5617 | generate_null_check = !cls->IsInDexCache(); |
| 5618 | break; |
| 5619 | } |
| 5620 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5621 | // /* GcRoot<mirror::Class>[] */ out = |
| 5622 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5623 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5624 | __ LoadFromOffset(kLoadWord, |
| 5625 | out, |
| 5626 | current_method, |
| 5627 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5628 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5629 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5630 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5631 | generate_null_check = !cls->IsInDexCache(); |
| 5632 | } |
| 5633 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5634 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5635 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5636 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5637 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5638 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5639 | codegen_->AddSlowPath(slow_path); |
| 5640 | if (generate_null_check) { |
| 5641 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5642 | } |
| 5643 | if (cls->MustGenerateClinitCheck()) { |
| 5644 | GenerateClassInitializationCheck(slow_path, out); |
| 5645 | } else { |
| 5646 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5647 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5652 | LocationSummary* locations = |
| 5653 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5654 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5655 | if (check->HasUses()) { |
| 5656 | locations->SetOut(Location::SameAsFirstInput()); |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5661 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5662 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5663 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5664 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5665 | GenerateClassInitializationCheck(slow_path, |
| 5666 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5667 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5668 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5669 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5670 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5671 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5672 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5673 | __ b(slow_path->GetEntryLabel(), LT); |
| 5674 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5675 | // properly. Therefore, we do a memory fence. |
| 5676 | __ dmb(ISH); |
| 5677 | __ Bind(slow_path->GetExitLabel()); |
| 5678 | } |
| 5679 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5680 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5681 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5682 | switch (desired_string_load_kind) { |
| 5683 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5684 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5685 | break; |
| 5686 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5687 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5688 | break; |
| 5689 | case HLoadString::LoadKind::kBootImageAddress: |
| 5690 | break; |
| 5691 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5692 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5693 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5694 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5695 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5696 | break; |
| 5697 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5698 | break; |
| 5699 | } |
| 5700 | return desired_string_load_kind; |
| 5701 | } |
| 5702 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5703 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5704 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5705 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5706 | ? LocationSummary::kCallOnMainOnly |
| 5707 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5708 | : LocationSummary::kNoCall; |
| 5709 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5710 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5711 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5712 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5713 | locations->SetInAt(0, Location::RequiresRegister()); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5714 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5715 | } else { |
| 5716 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5717 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5721 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5722 | Location out_loc = locations->Out(); |
| 5723 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5724 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5725 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5726 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5727 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5728 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5729 | load->GetStringIndex())); |
| 5730 | return; // No dex cache slow path. |
| 5731 | } |
| 5732 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5733 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5734 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5735 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5736 | __ BindTrackedLabel(&labels->movw_label); |
| 5737 | __ movw(out, /* placeholder */ 0u); |
| 5738 | __ BindTrackedLabel(&labels->movt_label); |
| 5739 | __ movt(out, /* placeholder */ 0u); |
| 5740 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5741 | __ add(out, out, ShifterOperand(PC)); |
| 5742 | return; // No dex cache slow path. |
| 5743 | } |
| 5744 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5745 | DCHECK_NE(load->GetAddress(), 0u); |
| 5746 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5747 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5748 | return; // No dex cache slow path. |
| 5749 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5750 | case HLoadString::LoadKind::kBssEntry: { |
| 5751 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5752 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5753 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5754 | __ BindTrackedLabel(&labels->movw_label); |
| 5755 | __ movw(out, /* placeholder */ 0u); |
| 5756 | __ BindTrackedLabel(&labels->movt_label); |
| 5757 | __ movt(out, /* placeholder */ 0u); |
| 5758 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5759 | __ add(out, out, ShifterOperand(PC)); |
| 5760 | GenerateGcRootFieldLoad(load, out_loc, out, 0); |
| 5761 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5762 | codegen_->AddSlowPath(slow_path); |
| 5763 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5764 | __ Bind(slow_path->GetExitLabel()); |
| 5765 | return; |
| 5766 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5767 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5768 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5769 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5770 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5771 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 5772 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5773 | InvokeRuntimeCallingConvention calling_convention; |
| 5774 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex()); |
| 5775 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5776 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5777 | } |
| 5778 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5779 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5780 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5781 | } |
| 5782 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5783 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5784 | LocationSummary* locations = |
| 5785 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5786 | locations->SetOut(Location::RequiresRegister()); |
| 5787 | } |
| 5788 | |
| 5789 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5790 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5791 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5792 | } |
| 5793 | |
| 5794 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5795 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5796 | } |
| 5797 | |
| 5798 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5799 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5800 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5804 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5805 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5806 | InvokeRuntimeCallingConvention calling_convention; |
| 5807 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5808 | } |
| 5809 | |
| 5810 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5811 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5812 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5813 | } |
| 5814 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5815 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5816 | return kEmitCompilerReadBarrier && |
| 5817 | (kUseBakerReadBarrier || |
| 5818 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5819 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5820 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5821 | } |
| 5822 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5823 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5824 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5825 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5826 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5827 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5828 | case TypeCheckKind::kExactCheck: |
| 5829 | case TypeCheckKind::kAbstractClassCheck: |
| 5830 | case TypeCheckKind::kClassHierarchyCheck: |
| 5831 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5832 | call_kind = |
| 5833 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5834 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5835 | break; |
| 5836 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5837 | case TypeCheckKind::kUnresolvedCheck: |
| 5838 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5839 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5840 | break; |
| 5841 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5842 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5843 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5844 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5845 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5846 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5848 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5849 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5850 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5851 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5852 | // When read barriers are enabled, we need a temporary register for |
| 5853 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5854 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5855 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5856 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5857 | } |
| 5858 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5859 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5860 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5861 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5862 | Location obj_loc = locations->InAt(0); |
| 5863 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5864 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5865 | Location out_loc = locations->Out(); |
| 5866 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5867 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5868 | locations->GetTemp(0) : |
| 5869 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5870 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5871 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5872 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5873 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5874 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5875 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5876 | |
| 5877 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5878 | // avoid null check if we know obj is not null. |
| 5879 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5880 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5881 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5882 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5883 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5884 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5885 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5886 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5887 | case TypeCheckKind::kExactCheck: { |
| 5888 | __ cmp(out, ShifterOperand(cls)); |
| 5889 | // Classes must be equal for the instanceof to succeed. |
| 5890 | __ b(&zero, NE); |
| 5891 | __ LoadImmediate(out, 1); |
| 5892 | __ b(&done); |
| 5893 | break; |
| 5894 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5895 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5896 | case TypeCheckKind::kAbstractClassCheck: { |
| 5897 | // If the class is abstract, we eagerly fetch the super class of the |
| 5898 | // object to avoid doing a comparison we know will fail. |
| 5899 | Label loop; |
| 5900 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5901 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5902 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5903 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5904 | __ CompareAndBranchIfZero(out, &done); |
| 5905 | __ cmp(out, ShifterOperand(cls)); |
| 5906 | __ b(&loop, NE); |
| 5907 | __ LoadImmediate(out, 1); |
| 5908 | if (zero.IsLinked()) { |
| 5909 | __ b(&done); |
| 5910 | } |
| 5911 | break; |
| 5912 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5913 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5914 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5915 | // Walk over the class hierarchy to find a match. |
| 5916 | Label loop, success; |
| 5917 | __ Bind(&loop); |
| 5918 | __ cmp(out, ShifterOperand(cls)); |
| 5919 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5920 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5921 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5922 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5923 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5924 | __ b(&done); |
| 5925 | __ Bind(&success); |
| 5926 | __ LoadImmediate(out, 1); |
| 5927 | if (zero.IsLinked()) { |
| 5928 | __ b(&done); |
| 5929 | } |
| 5930 | break; |
| 5931 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5932 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5933 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5934 | // Do an exact check. |
| 5935 | Label exact_check; |
| 5936 | __ cmp(out, ShifterOperand(cls)); |
| 5937 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5938 | // 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] | 5939 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5940 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5941 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5942 | __ CompareAndBranchIfZero(out, &done); |
| 5943 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5944 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5945 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5946 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5947 | __ LoadImmediate(out, 1); |
| 5948 | __ b(&done); |
| 5949 | break; |
| 5950 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5951 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5952 | case TypeCheckKind::kArrayCheck: { |
| 5953 | __ cmp(out, ShifterOperand(cls)); |
| 5954 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5955 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5956 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | codegen_->AddSlowPath(slow_path); |
| 5958 | __ b(slow_path->GetEntryLabel(), NE); |
| 5959 | __ LoadImmediate(out, 1); |
| 5960 | if (zero.IsLinked()) { |
| 5961 | __ b(&done); |
| 5962 | } |
| 5963 | break; |
| 5964 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5965 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5966 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5967 | case TypeCheckKind::kInterfaceCheck: { |
| 5968 | // 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] | 5969 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5970 | // cases. |
| 5971 | // |
| 5972 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5973 | // entry point without resorting to a type checking slow path |
| 5974 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5975 | // require to assign fixed registers for the inputs of this |
| 5976 | // HInstanceOf instruction (following the runtime calling |
| 5977 | // convention), which might be cluttered by the potential first |
| 5978 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5979 | // |
| 5980 | // TODO: Introduce a new runtime entry point taking the object |
| 5981 | // to test (instead of its class) as argument, and let it deal |
| 5982 | // with the read barrier issues. This will let us refactor this |
| 5983 | // case of the `switch` code as it was previously (with a direct |
| 5984 | // call to the runtime not using a type checking slow path). |
| 5985 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5986 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5987 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5988 | /* is_fatal */ false); |
| 5989 | codegen_->AddSlowPath(slow_path); |
| 5990 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5991 | if (zero.IsLinked()) { |
| 5992 | __ b(&done); |
| 5993 | } |
| 5994 | break; |
| 5995 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5996 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5997 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5998 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5999 | __ Bind(&zero); |
| 6000 | __ LoadImmediate(out, 0); |
| 6001 | } |
| 6002 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6003 | if (done.IsLinked()) { |
| 6004 | __ Bind(&done); |
| 6005 | } |
| 6006 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6007 | if (slow_path != nullptr) { |
| 6008 | __ Bind(slow_path->GetExitLabel()); |
| 6009 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6010 | } |
| 6011 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6012 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6013 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6014 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6015 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6016 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6017 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6018 | case TypeCheckKind::kExactCheck: |
| 6019 | case TypeCheckKind::kAbstractClassCheck: |
| 6020 | case TypeCheckKind::kClassHierarchyCheck: |
| 6021 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6022 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6023 | LocationSummary::kCallOnSlowPath : |
| 6024 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6025 | break; |
| 6026 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6027 | case TypeCheckKind::kUnresolvedCheck: |
| 6028 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6029 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6030 | break; |
| 6031 | } |
| 6032 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6033 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6035 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6036 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 6037 | locations->AddTemp(Location::RequiresRegister()); |
| 6038 | // When read barriers are enabled, we need an additional temporary |
| 6039 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6040 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6041 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6042 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6046 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6047 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6048 | Location obj_loc = locations->InAt(0); |
| 6049 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6050 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6051 | Location temp_loc = locations->GetTemp(0); |
| 6052 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6053 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6054 | locations->GetTemp(1) : |
| 6055 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6056 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6057 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6058 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6059 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6060 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6061 | bool is_type_check_slow_path_fatal = |
| 6062 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6063 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6064 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6065 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6066 | !instruction->CanThrowIntoCatchBlock(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6067 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6068 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6069 | is_type_check_slow_path_fatal); |
| 6070 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6071 | |
| 6072 | Label done; |
| 6073 | // Avoid null check if we know obj is not null. |
| 6074 | if (instruction->MustDoNullCheck()) { |
| 6075 | __ CompareAndBranchIfZero(obj, &done); |
| 6076 | } |
| 6077 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6078 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6079 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6080 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6081 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6082 | case TypeCheckKind::kExactCheck: |
| 6083 | case TypeCheckKind::kArrayCheck: { |
| 6084 | __ cmp(temp, ShifterOperand(cls)); |
| 6085 | // Jump to slow path for throwing the exception or doing a |
| 6086 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6087 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6088 | break; |
| 6089 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6090 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6091 | case TypeCheckKind::kAbstractClassCheck: { |
| 6092 | // If the class is abstract, we eagerly fetch the super class of the |
| 6093 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6094 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6095 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6096 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6097 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6098 | |
| 6099 | // If the class reference currently in `temp` is not null, jump |
| 6100 | // to the `compare_classes` label to compare it with the checked |
| 6101 | // class. |
| 6102 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 6103 | // Otherwise, jump to the slow path to throw the exception. |
| 6104 | // |
| 6105 | // But before, move back the object's class into `temp` before |
| 6106 | // going into the slow path, as it has been overwritten in the |
| 6107 | // meantime. |
| 6108 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6109 | GenerateReferenceLoadTwoRegisters( |
| 6110 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6111 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6112 | |
| 6113 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6114 | __ cmp(temp, ShifterOperand(cls)); |
| 6115 | __ b(&loop, NE); |
| 6116 | break; |
| 6117 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6118 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6119 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6120 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6121 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6122 | __ Bind(&loop); |
| 6123 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6124 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6125 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6126 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6127 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6128 | |
| 6129 | // If the class reference currently in `temp` is not null, jump |
| 6130 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6131 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6132 | // Otherwise, jump to the slow path to throw the exception. |
| 6133 | // |
| 6134 | // But before, move back the object's class into `temp` before |
| 6135 | // going into the slow path, as it has been overwritten in the |
| 6136 | // meantime. |
| 6137 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6138 | GenerateReferenceLoadTwoRegisters( |
| 6139 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6140 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6141 | break; |
| 6142 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6143 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6144 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6145 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6146 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6147 | __ cmp(temp, ShifterOperand(cls)); |
| 6148 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6149 | |
| 6150 | // 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] | 6151 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6152 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6153 | |
| 6154 | // If the component type is not null (i.e. the object is indeed |
| 6155 | // an array), jump to label `check_non_primitive_component_type` |
| 6156 | // to further check that this component type is not a primitive |
| 6157 | // type. |
| 6158 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 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()); |
| 6168 | |
| 6169 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6170 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6171 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 6172 | __ CompareAndBranchIfZero(temp, &done); |
| 6173 | // Same comment as above regarding `temp` and the slow path. |
| 6174 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6175 | GenerateReferenceLoadTwoRegisters( |
| 6176 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6177 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6178 | break; |
| 6179 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6180 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6181 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6182 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6183 | // We always go into the type check slow path for the unresolved |
| 6184 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6185 | // |
| 6186 | // We cannot directly call the CheckCast runtime entry point |
| 6187 | // without resorting to a type checking slow path here (i.e. by |
| 6188 | // calling InvokeRuntime directly), as it would require to |
| 6189 | // assign fixed registers for the inputs of this HInstanceOf |
| 6190 | // instruction (following the runtime calling convention), which |
| 6191 | // might be cluttered by the potential first read barrier |
| 6192 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6193 | // |
| 6194 | // TODO: Introduce a new runtime entry point taking the object |
| 6195 | // to test (instead of its class) as argument, and let it deal |
| 6196 | // with the read barrier issues. This will let us refactor this |
| 6197 | // case of the `switch` code as it was previously (with a direct |
| 6198 | // call to the runtime not using a type checking slow path). |
| 6199 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6200 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6201 | break; |
| 6202 | } |
| 6203 | __ Bind(&done); |
| 6204 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6205 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6208 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6209 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6210 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6211 | InvokeRuntimeCallingConvention calling_convention; |
| 6212 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6213 | } |
| 6214 | |
| 6215 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6216 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6217 | instruction, |
| 6218 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6219 | if (instruction->IsEnter()) { |
| 6220 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6221 | } else { |
| 6222 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6223 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6224 | } |
| 6225 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6226 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6227 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6228 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6229 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6230 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6231 | LocationSummary* locations = |
| 6232 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6233 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6234 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6235 | // 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] | 6236 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6237 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6238 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6242 | HandleBitwiseOperation(instruction); |
| 6243 | } |
| 6244 | |
| 6245 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6246 | HandleBitwiseOperation(instruction); |
| 6247 | } |
| 6248 | |
| 6249 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6250 | HandleBitwiseOperation(instruction); |
| 6251 | } |
| 6252 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6253 | |
| 6254 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6255 | LocationSummary* locations = |
| 6256 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6257 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6258 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6259 | |
| 6260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6261 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6263 | } |
| 6264 | |
| 6265 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6266 | LocationSummary* locations = instruction->GetLocations(); |
| 6267 | Location first = locations->InAt(0); |
| 6268 | Location second = locations->InAt(1); |
| 6269 | Location out = locations->Out(); |
| 6270 | |
| 6271 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6272 | Register first_reg = first.AsRegister<Register>(); |
| 6273 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6274 | Register out_reg = out.AsRegister<Register>(); |
| 6275 | |
| 6276 | switch (instruction->GetOpKind()) { |
| 6277 | case HInstruction::kAnd: |
| 6278 | __ bic(out_reg, first_reg, second_reg); |
| 6279 | break; |
| 6280 | case HInstruction::kOr: |
| 6281 | __ orn(out_reg, first_reg, second_reg); |
| 6282 | break; |
| 6283 | // There is no EON on arm. |
| 6284 | case HInstruction::kXor: |
| 6285 | default: |
| 6286 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6287 | UNREACHABLE(); |
| 6288 | } |
| 6289 | return; |
| 6290 | |
| 6291 | } else { |
| 6292 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6293 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6294 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6295 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6296 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6297 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6298 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6299 | |
| 6300 | switch (instruction->GetOpKind()) { |
| 6301 | case HInstruction::kAnd: |
| 6302 | __ bic(out_low, first_low, second_low); |
| 6303 | __ bic(out_high, first_high, second_high); |
| 6304 | break; |
| 6305 | case HInstruction::kOr: |
| 6306 | __ orn(out_low, first_low, second_low); |
| 6307 | __ orn(out_high, first_high, second_high); |
| 6308 | break; |
| 6309 | // There is no EON on arm. |
| 6310 | case HInstruction::kXor: |
| 6311 | default: |
| 6312 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6313 | UNREACHABLE(); |
| 6314 | } |
| 6315 | } |
| 6316 | } |
| 6317 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6318 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6319 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6320 | if (value == 0xffffffffu) { |
| 6321 | if (out != first) { |
| 6322 | __ mov(out, ShifterOperand(first)); |
| 6323 | } |
| 6324 | return; |
| 6325 | } |
| 6326 | if (value == 0u) { |
| 6327 | __ mov(out, ShifterOperand(0)); |
| 6328 | return; |
| 6329 | } |
| 6330 | ShifterOperand so; |
| 6331 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6332 | __ and_(out, first, so); |
| 6333 | } else { |
| 6334 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6335 | __ bic(out, first, ShifterOperand(~value)); |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6340 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6341 | if (value == 0u) { |
| 6342 | if (out != first) { |
| 6343 | __ mov(out, ShifterOperand(first)); |
| 6344 | } |
| 6345 | return; |
| 6346 | } |
| 6347 | if (value == 0xffffffffu) { |
| 6348 | __ mvn(out, ShifterOperand(0)); |
| 6349 | return; |
| 6350 | } |
| 6351 | ShifterOperand so; |
| 6352 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6353 | __ orr(out, first, so); |
| 6354 | } else { |
| 6355 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6356 | __ orn(out, first, ShifterOperand(~value)); |
| 6357 | } |
| 6358 | } |
| 6359 | |
| 6360 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6361 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6362 | if (value == 0u) { |
| 6363 | if (out != first) { |
| 6364 | __ mov(out, ShifterOperand(first)); |
| 6365 | } |
| 6366 | return; |
| 6367 | } |
| 6368 | __ eor(out, first, ShifterOperand(value)); |
| 6369 | } |
| 6370 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6371 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6372 | Location first, |
| 6373 | uint64_t value) { |
| 6374 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6375 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6376 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6377 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6378 | uint32_t value_low = Low32Bits(value); |
| 6379 | uint32_t value_high = High32Bits(value); |
| 6380 | if (value_low == 0u) { |
| 6381 | if (out_low != first_low) { |
| 6382 | __ mov(out_low, ShifterOperand(first_low)); |
| 6383 | } |
| 6384 | __ AddConstant(out_high, first_high, value_high); |
| 6385 | return; |
| 6386 | } |
| 6387 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6388 | ShifterOperand so; |
| 6389 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6390 | __ adc(out_high, first_high, so); |
| 6391 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6392 | __ sbc(out_high, first_high, so); |
| 6393 | } else { |
| 6394 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6395 | UNREACHABLE(); |
| 6396 | } |
| 6397 | } |
| 6398 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6399 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6400 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6401 | Location first = locations->InAt(0); |
| 6402 | Location second = locations->InAt(1); |
| 6403 | Location out = locations->Out(); |
| 6404 | |
| 6405 | if (second.IsConstant()) { |
| 6406 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6407 | uint32_t value_low = Low32Bits(value); |
| 6408 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6409 | Register first_reg = first.AsRegister<Register>(); |
| 6410 | Register out_reg = out.AsRegister<Register>(); |
| 6411 | if (instruction->IsAnd()) { |
| 6412 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6413 | } else if (instruction->IsOr()) { |
| 6414 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6415 | } else { |
| 6416 | DCHECK(instruction->IsXor()); |
| 6417 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6418 | } |
| 6419 | } else { |
| 6420 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6421 | uint32_t value_high = High32Bits(value); |
| 6422 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6423 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6424 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6425 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6426 | if (instruction->IsAnd()) { |
| 6427 | GenerateAndConst(out_low, first_low, value_low); |
| 6428 | GenerateAndConst(out_high, first_high, value_high); |
| 6429 | } else if (instruction->IsOr()) { |
| 6430 | GenerateOrrConst(out_low, first_low, value_low); |
| 6431 | GenerateOrrConst(out_high, first_high, value_high); |
| 6432 | } else { |
| 6433 | DCHECK(instruction->IsXor()); |
| 6434 | GenerateEorConst(out_low, first_low, value_low); |
| 6435 | GenerateEorConst(out_high, first_high, value_high); |
| 6436 | } |
| 6437 | } |
| 6438 | return; |
| 6439 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6440 | |
| 6441 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6442 | Register first_reg = first.AsRegister<Register>(); |
| 6443 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6444 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6445 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6446 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6447 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6448 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6449 | } else { |
| 6450 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6451 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6452 | } |
| 6453 | } else { |
| 6454 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6455 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6456 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6457 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6458 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6459 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6460 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6461 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6462 | __ and_(out_low, first_low, second_low); |
| 6463 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6464 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6465 | __ orr(out_low, first_low, second_low); |
| 6466 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6467 | } else { |
| 6468 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6469 | __ eor(out_low, first_low, second_low); |
| 6470 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6471 | } |
| 6472 | } |
| 6473 | } |
| 6474 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6475 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6476 | Location out, |
| 6477 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6478 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6479 | Register out_reg = out.AsRegister<Register>(); |
| 6480 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6481 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6482 | if (kUseBakerReadBarrier) { |
| 6483 | // Load with fast path based Baker's read barrier. |
| 6484 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6485 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6486 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6487 | } else { |
| 6488 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6489 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6490 | // in the following move operation, as we will need it for the |
| 6491 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6492 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6493 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6494 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6495 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6496 | } |
| 6497 | } else { |
| 6498 | // Plain load with no read barrier. |
| 6499 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6500 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6501 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6506 | Location out, |
| 6507 | Location obj, |
| 6508 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6509 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6510 | Register out_reg = out.AsRegister<Register>(); |
| 6511 | Register obj_reg = obj.AsRegister<Register>(); |
| 6512 | if (kEmitCompilerReadBarrier) { |
| 6513 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6514 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6515 | // Load with fast path based Baker's read barrier. |
| 6516 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6517 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6518 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6519 | } else { |
| 6520 | // Load with slow path based read barrier. |
| 6521 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6522 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6523 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6524 | } |
| 6525 | } else { |
| 6526 | // Plain load with no read barrier. |
| 6527 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6528 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6529 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6534 | Location root, |
| 6535 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6536 | uint32_t offset, |
| 6537 | bool requires_read_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6538 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6539 | if (requires_read_barrier) { |
| 6540 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6541 | if (kUseBakerReadBarrier) { |
| 6542 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6543 | // Baker's read barrier are used: |
| 6544 | // |
| 6545 | // root = obj.field; |
| 6546 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6547 | // root = ReadBarrier::Mark(root) |
| 6548 | // } |
| 6549 | |
| 6550 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6551 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6552 | static_assert( |
| 6553 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6554 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6555 | "have different sizes."); |
| 6556 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6557 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6558 | "have different sizes."); |
| 6559 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6560 | // Slow path marking the GC root `root`. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6561 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6562 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6563 | codegen_->AddSlowPath(slow_path); |
| 6564 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6565 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6566 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6567 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6568 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6569 | __ Bind(slow_path->GetExitLabel()); |
| 6570 | } else { |
| 6571 | // GC root loaded through a slow path for read barriers other |
| 6572 | // than Baker's. |
| 6573 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6574 | __ AddConstant(root_reg, obj, offset); |
| 6575 | // /* mirror::Object* */ root = root->Read() |
| 6576 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6577 | } |
| 6578 | } else { |
| 6579 | // Plain GC root load with no read barrier. |
| 6580 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6581 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6582 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6583 | // do not have to unpoison `root_reg` here. |
| 6584 | } |
| 6585 | } |
| 6586 | |
| 6587 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6588 | Location ref, |
| 6589 | Register obj, |
| 6590 | uint32_t offset, |
| 6591 | Location temp, |
| 6592 | bool needs_null_check) { |
| 6593 | DCHECK(kEmitCompilerReadBarrier); |
| 6594 | DCHECK(kUseBakerReadBarrier); |
| 6595 | |
| 6596 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6597 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6598 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6599 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6600 | 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] | 6601 | } |
| 6602 | |
| 6603 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6604 | Location ref, |
| 6605 | Register obj, |
| 6606 | uint32_t data_offset, |
| 6607 | Location index, |
| 6608 | Location temp, |
| 6609 | bool needs_null_check) { |
| 6610 | DCHECK(kEmitCompilerReadBarrier); |
| 6611 | DCHECK(kUseBakerReadBarrier); |
| 6612 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6613 | static_assert( |
| 6614 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6615 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6616 | // /* HeapReference<Object> */ ref = |
| 6617 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6618 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6619 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6620 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6624 | Location ref, |
| 6625 | Register obj, |
| 6626 | uint32_t offset, |
| 6627 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6628 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6629 | Location temp, |
| 6630 | bool needs_null_check) { |
| 6631 | DCHECK(kEmitCompilerReadBarrier); |
| 6632 | DCHECK(kUseBakerReadBarrier); |
| 6633 | |
| 6634 | // In slow path based read barriers, the read barrier call is |
| 6635 | // inserted after the original load. However, in fast path based |
| 6636 | // Baker's read barriers, we need to perform the load of |
| 6637 | // mirror::Object::monitor_ *before* the original reference load. |
| 6638 | // This load-load ordering is required by the read barrier. |
| 6639 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6640 | // |
| 6641 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6642 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6643 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6644 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6645 | // if (is_gray) { |
| 6646 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6647 | // } |
| 6648 | // |
| 6649 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6650 | // slightly more complex as it performs additional checks that we do |
| 6651 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6652 | |
| 6653 | Register ref_reg = ref.AsRegister<Register>(); |
| 6654 | Register temp_reg = temp.AsRegister<Register>(); |
| 6655 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6656 | |
| 6657 | // /* int32_t */ monitor = obj->monitor_ |
| 6658 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6659 | if (needs_null_check) { |
| 6660 | MaybeRecordImplicitNullCheck(instruction); |
| 6661 | } |
| 6662 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6663 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6664 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6665 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6666 | // Introduce a dependency on the lock_word including the rb_state, |
| 6667 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6668 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 6669 | // `obj` is unchanged by this operation, but its value now depends |
| 6670 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6671 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6672 | |
| 6673 | // The actual reference load. |
| 6674 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6675 | // Load types involving an "index": ArrayGet and |
| 6676 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6677 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6678 | if (index.IsConstant()) { |
| 6679 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6680 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6681 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6682 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6683 | // Handle the special case of the |
| 6684 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6685 | // a register pair as index ("long offset"), of which only the low |
| 6686 | // part contains data. |
| 6687 | Register index_reg = index.IsRegisterPair() |
| 6688 | ? index.AsRegisterPairLow<Register>() |
| 6689 | : index.AsRegister<Register>(); |
| 6690 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6691 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6692 | } |
| 6693 | } else { |
| 6694 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6695 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6696 | } |
| 6697 | |
| 6698 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6699 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6700 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6701 | // Slow path marking the object `ref` when it is gray. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6702 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6703 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6704 | AddSlowPath(slow_path); |
| 6705 | |
| 6706 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6707 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6708 | // Given the numeric representation, it's enough to check the low bit of the |
| 6709 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6710 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6711 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6712 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6713 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6714 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6715 | __ 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] | 6716 | __ Bind(slow_path->GetExitLabel()); |
| 6717 | } |
| 6718 | |
| 6719 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6720 | Location out, |
| 6721 | Location ref, |
| 6722 | Location obj, |
| 6723 | uint32_t offset, |
| 6724 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6725 | DCHECK(kEmitCompilerReadBarrier); |
| 6726 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6727 | // Insert a slow path based read barrier *after* the reference load. |
| 6728 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6729 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6730 | // reference will be carried out by the runtime within the slow |
| 6731 | // path. |
| 6732 | // |
| 6733 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6734 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6735 | // not used by the artReadBarrierSlow entry point. |
| 6736 | // |
| 6737 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6738 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6739 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6740 | AddSlowPath(slow_path); |
| 6741 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6742 | __ b(slow_path->GetEntryLabel()); |
| 6743 | __ Bind(slow_path->GetExitLabel()); |
| 6744 | } |
| 6745 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6746 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(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 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6753 | // Baker's read barriers shall be handled by the fast path |
| 6754 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6755 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6756 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6757 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6758 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6759 | } else if (kPoisonHeapReferences) { |
| 6760 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6761 | } |
| 6762 | } |
| 6763 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6764 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6765 | Location out, |
| 6766 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6767 | DCHECK(kEmitCompilerReadBarrier); |
| 6768 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6769 | // Insert a slow path based read barrier *after* the GC root load. |
| 6770 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6771 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6772 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6773 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6774 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6775 | AddSlowPath(slow_path); |
| 6776 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6777 | __ b(slow_path->GetEntryLabel()); |
| 6778 | __ Bind(slow_path->GetExitLabel()); |
| 6779 | } |
| 6780 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6781 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6782 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6783 | HInvokeStaticOrDirect* invoke) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6784 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6785 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6786 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6787 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6788 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6789 | if (GetGraph()->HasIrreducibleLoops() && |
| 6790 | (dispatch_info.method_load_kind == |
| 6791 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6792 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6793 | } |
| 6794 | |
| 6795 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6796 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6797 | if (&outer_dex_file != invoke->GetTargetMethod().dex_file) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6798 | // Calls across dex files are more likely to exceed the available BL range, |
| 6799 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6800 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6801 | (desired_dispatch_info.method_load_kind == |
| 6802 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6803 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6804 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6805 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6806 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6807 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6808 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6809 | 0u |
| 6810 | }; |
| 6811 | } |
| 6812 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6813 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6814 | } |
| 6815 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6816 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6817 | Register temp) { |
| 6818 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6819 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6820 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6821 | return location.AsRegister<Register>(); |
| 6822 | } |
| 6823 | // For intrinsics we allow any location, so it may be on the stack. |
| 6824 | if (!location.IsRegister()) { |
| 6825 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6826 | return temp; |
| 6827 | } |
| 6828 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6829 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6830 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6831 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6832 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6833 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6834 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6835 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6836 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6837 | return temp; |
| 6838 | } |
| 6839 | return location.AsRegister<Register>(); |
| 6840 | } |
| 6841 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6842 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6843 | // 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] | 6844 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6845 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6846 | // LR = code address from literal pool with link-time patch. |
| 6847 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6848 | break; |
| 6849 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6850 | // LR = invoke->GetDirectCodePtr(); |
| 6851 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6852 | break; |
| 6853 | default: |
| 6854 | break; |
| 6855 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6856 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6857 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6858 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6859 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 6860 | uint32_t offset = |
| 6861 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6862 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6863 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6864 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 6865 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6866 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6867 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6868 | break; |
| 6869 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6870 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6871 | break; |
| 6872 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6873 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6874 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6875 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6876 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6877 | HArmDexCacheArraysBase* base = |
| 6878 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6879 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6880 | temp.AsRegister<Register>()); |
| 6881 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6882 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6883 | break; |
| 6884 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6885 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6886 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6887 | Register method_reg; |
| 6888 | Register reg = temp.AsRegister<Register>(); |
| 6889 | if (current_method.IsRegister()) { |
| 6890 | method_reg = current_method.AsRegister<Register>(); |
| 6891 | } else { |
| 6892 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6893 | DCHECK(!current_method.IsValid()); |
| 6894 | method_reg = reg; |
| 6895 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6896 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6897 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6898 | __ LoadFromOffset(kLoadWord, |
| 6899 | reg, |
| 6900 | method_reg, |
| 6901 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6902 | // temp = temp[index_in_cache]; |
| 6903 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6904 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6905 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6906 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6907 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6908 | } |
| 6909 | |
| 6910 | switch (invoke->GetCodePtrLocation()) { |
| 6911 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6912 | __ bl(GetFrameEntryLabel()); |
| 6913 | break; |
| 6914 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6915 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 6916 | invoke->GetTargetMethod().dex_method_index); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6917 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6918 | // Arbitrarily branch to the BL itself, override at link time. |
| 6919 | __ bl(&relative_call_patches_.back().label); |
| 6920 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6921 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6922 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6923 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6924 | // LR() |
| 6925 | __ blx(LR); |
| 6926 | break; |
| 6927 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6928 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6929 | __ LoadFromOffset( |
| 6930 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6931 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6932 | // LR() |
| 6933 | __ blx(LR); |
| 6934 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6935 | } |
| 6936 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6937 | DCHECK(!IsLeafMethod()); |
| 6938 | } |
| 6939 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6940 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6941 | Register temp = temp_location.AsRegister<Register>(); |
| 6942 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6943 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6944 | |
| 6945 | // Use the calling convention instead of the location of the receiver, as |
| 6946 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6947 | // slow path, the arguments have been moved to the right place, so here we are |
| 6948 | // guaranteed that the receiver is the first register of the calling convention. |
| 6949 | InvokeDexCallingConvention calling_convention; |
| 6950 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6951 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6952 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6953 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6954 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6955 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6956 | // emit a read barrier for the previous class reference load. |
| 6957 | // However this is not required in practice, as this is an |
| 6958 | // intermediate/temporary reference and because the current |
| 6959 | // concurrent copying collector keeps the from-space memory |
| 6960 | // intact/accessible until the end of the marking phase (the |
| 6961 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6962 | __ MaybeUnpoisonHeapReference(temp); |
| 6963 | // temp = temp->GetMethodAt(method_offset); |
| 6964 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6965 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6966 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6967 | // LR = temp->GetEntryPoint(); |
| 6968 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6969 | // LR(); |
| 6970 | __ blx(LR); |
| 6971 | } |
| 6972 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6973 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 6974 | const DexFile& dex_file, uint32_t string_index) { |
| 6975 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 6976 | } |
| 6977 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6978 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 6979 | const DexFile& dex_file, uint32_t type_index) { |
| 6980 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 6981 | } |
| 6982 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6983 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 6984 | const DexFile& dex_file, uint32_t element_offset) { |
| 6985 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 6986 | } |
| 6987 | |
| 6988 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 6989 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 6990 | patches->emplace_back(dex_file, offset_or_index); |
| 6991 | return &patches->back(); |
| 6992 | } |
| 6993 | |
| 6994 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 6995 | uint32_t string_index) { |
| 6996 | return boot_image_string_patches_.GetOrCreate( |
| 6997 | StringReference(&dex_file, string_index), |
| 6998 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6999 | } |
| 7000 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7001 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 7002 | uint32_t type_index) { |
| 7003 | return boot_image_type_patches_.GetOrCreate( |
| 7004 | TypeReference(&dex_file, type_index), |
| 7005 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7006 | } |
| 7007 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7008 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7009 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7010 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7011 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7012 | } |
| 7013 | |
| 7014 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 7015 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 7016 | } |
| 7017 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7018 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7019 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7020 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7021 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7022 | for (const PcRelativePatchInfo& info : infos) { |
| 7023 | const DexFile& dex_file = info.target_dex_file; |
| 7024 | size_t offset_or_index = info.offset_or_index; |
| 7025 | DCHECK(info.add_pc_label.IsBound()); |
| 7026 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7027 | // Add MOVW patch. |
| 7028 | DCHECK(info.movw_label.IsBound()); |
| 7029 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7030 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7031 | // Add MOVT patch. |
| 7032 | DCHECK(info.movt_label.IsBound()); |
| 7033 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7034 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7035 | } |
| 7036 | } |
| 7037 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7038 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7039 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7040 | size_t size = |
| 7041 | method_patches_.size() + |
| 7042 | call_patches_.size() + |
| 7043 | relative_call_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7044 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7045 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7046 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7047 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7048 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7049 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7050 | linker_patches->reserve(size); |
| 7051 | for (const auto& entry : method_patches_) { |
| 7052 | const MethodReference& target_method = entry.first; |
| 7053 | Literal* literal = entry.second; |
| 7054 | DCHECK(literal->GetLabel()->IsBound()); |
| 7055 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7056 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 7057 | target_method.dex_file, |
| 7058 | target_method.dex_method_index)); |
| 7059 | } |
| 7060 | for (const auto& entry : call_patches_) { |
| 7061 | const MethodReference& target_method = entry.first; |
| 7062 | Literal* literal = entry.second; |
| 7063 | DCHECK(literal->GetLabel()->IsBound()); |
| 7064 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7065 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 7066 | target_method.dex_file, |
| 7067 | target_method.dex_method_index)); |
| 7068 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7069 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7070 | uint32_t literal_offset = info.label.Position(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7071 | linker_patches->push_back( |
| 7072 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7073 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7074 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7075 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7076 | for (const auto& entry : boot_image_string_patches_) { |
| 7077 | const StringReference& target_string = entry.first; |
| 7078 | Literal* literal = entry.second; |
| 7079 | DCHECK(literal->GetLabel()->IsBound()); |
| 7080 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7081 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7082 | target_string.dex_file, |
| 7083 | target_string.string_index)); |
| 7084 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7085 | if (!GetCompilerOptions().IsBootImage()) { |
| 7086 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7087 | linker_patches); |
| 7088 | } else { |
| 7089 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7090 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7091 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7092 | for (const auto& entry : boot_image_type_patches_) { |
| 7093 | const TypeReference& target_type = entry.first; |
| 7094 | Literal* literal = entry.second; |
| 7095 | DCHECK(literal->GetLabel()->IsBound()); |
| 7096 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7097 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7098 | target_type.dex_file, |
| 7099 | target_type.type_index)); |
| 7100 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7101 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7102 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7103 | for (const auto& entry : boot_image_address_patches_) { |
| 7104 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7105 | Literal* literal = entry.second; |
| 7106 | DCHECK(literal->GetLabel()->IsBound()); |
| 7107 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7108 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7109 | } |
| 7110 | } |
| 7111 | |
| 7112 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7113 | return map->GetOrCreate( |
| 7114 | value, |
| 7115 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7119 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7120 | return map->GetOrCreate( |
| 7121 | target_method, |
| 7122 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7123 | } |
| 7124 | |
| 7125 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 7126 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 7127 | } |
| 7128 | |
| 7129 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 7130 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 7131 | } |
| 7132 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7133 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7134 | LocationSummary* locations = |
| 7135 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7136 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7137 | Location::RequiresRegister()); |
| 7138 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7139 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7140 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7141 | } |
| 7142 | |
| 7143 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7144 | LocationSummary* locations = instr->GetLocations(); |
| 7145 | Register res = locations->Out().AsRegister<Register>(); |
| 7146 | Register accumulator = |
| 7147 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7148 | Register mul_left = |
| 7149 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7150 | Register mul_right = |
| 7151 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7152 | |
| 7153 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7154 | __ mla(res, mul_left, mul_right, accumulator); |
| 7155 | } else { |
| 7156 | __ mls(res, mul_left, mul_right, accumulator); |
| 7157 | } |
| 7158 | } |
| 7159 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7160 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7161 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7162 | LOG(FATAL) << "Unreachable"; |
| 7163 | } |
| 7164 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7165 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7166 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7167 | LOG(FATAL) << "Unreachable"; |
| 7168 | } |
| 7169 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7170 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7171 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7172 | LocationSummary* locations = |
| 7173 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7174 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7175 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7176 | codegen_->GetAssembler()->IsThumb()) { |
| 7177 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7178 | if (switch_instr->GetStartValue() != 0) { |
| 7179 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7180 | } |
| 7181 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7182 | } |
| 7183 | |
| 7184 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7185 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7186 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7187 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7188 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7189 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7190 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7191 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7192 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7193 | Register temp_reg = IP; |
| 7194 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7195 | // the immediate, because IP is used as the destination register. For the other |
| 7196 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7197 | // and they can be encoded in the instruction without making use of IP register. |
| 7198 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7199 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7200 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7201 | // Jump to successors[0] if value == lower_bound. |
| 7202 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7203 | int32_t last_index = 0; |
| 7204 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7205 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7206 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7207 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7208 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7209 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7210 | } |
| 7211 | if (num_entries - last_index == 2) { |
| 7212 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7213 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7214 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7215 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7216 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7217 | // And the default for any other value. |
| 7218 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7219 | __ b(codegen_->GetLabelOf(default_block)); |
| 7220 | } |
| 7221 | } else { |
| 7222 | // Create a table lookup. |
| 7223 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7224 | |
| 7225 | // Materialize a pointer to the switch table |
| 7226 | std::vector<Label*> labels(num_entries); |
| 7227 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7228 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7229 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7230 | } |
| 7231 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7232 | |
| 7233 | // Remove the bias. |
| 7234 | Register key_reg; |
| 7235 | if (lower_bound != 0) { |
| 7236 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7237 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7238 | } else { |
| 7239 | key_reg = value_reg; |
| 7240 | } |
| 7241 | |
| 7242 | // Check whether the value is in the table, jump to default block if not. |
| 7243 | __ CmpConstant(key_reg, num_entries - 1); |
| 7244 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7245 | |
| 7246 | // Load the displacement from the table. |
| 7247 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7248 | |
| 7249 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7250 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7251 | } |
| 7252 | } |
| 7253 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7254 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7255 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7256 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7260 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7261 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7262 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7263 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7264 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7265 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7266 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7267 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7268 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7269 | } |
| 7270 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7271 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7272 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7273 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7274 | return; |
| 7275 | } |
| 7276 | |
| 7277 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7278 | |
| 7279 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7280 | if (return_loc.Equals(trg)) { |
| 7281 | return; |
| 7282 | } |
| 7283 | |
| 7284 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7285 | // with the last branch. |
| 7286 | if (type == Primitive::kPrimLong) { |
| 7287 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7288 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7289 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7290 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7291 | } else if (type == Primitive::kPrimDouble) { |
| 7292 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7293 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7294 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7295 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7296 | } else { |
| 7297 | // Let the parallel move resolver take care of all of this. |
| 7298 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7299 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7300 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7301 | } |
| 7302 | } |
| 7303 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7304 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7305 | LocationSummary* locations = |
| 7306 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7307 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7308 | locations->SetOut(Location::RequiresRegister()); |
| 7309 | } |
| 7310 | |
| 7311 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7312 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7313 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7314 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7315 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7316 | __ LoadFromOffset(kLoadWord, |
| 7317 | locations->Out().AsRegister<Register>(), |
| 7318 | locations->InAt(0).AsRegister<Register>(), |
| 7319 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7320 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7321 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7322 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7323 | __ LoadFromOffset(kLoadWord, |
| 7324 | locations->Out().AsRegister<Register>(), |
| 7325 | locations->InAt(0).AsRegister<Register>(), |
| 7326 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7327 | __ LoadFromOffset(kLoadWord, |
| 7328 | locations->Out().AsRegister<Register>(), |
| 7329 | locations->Out().AsRegister<Register>(), |
| 7330 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7331 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7332 | } |
| 7333 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7334 | #undef __ |
| 7335 | #undef QUICK_ENTRY_POINT |
| 7336 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7337 | } // namespace arm |
| 7338 | } // namespace art |