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" |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 22 | #include "common_arm.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 31 | #include "utils/arm/assembler_arm.h" |
| 32 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 33 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 34 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace arm { |
| 42 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 43 | static bool ExpectedPairLayout(Location location) { |
| 44 | // We expected this for both core and fpu register pairs. |
| 45 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 46 | } |
| 47 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 49 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 52 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 53 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 54 | static constexpr SRegister kFpuCalleeSaves[] = |
| 55 | { 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] | 56 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 57 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 58 | // S registers. Therefore there is no need to block it. |
| 59 | static constexpr DRegister DTMP = D31; |
| 60 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 61 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 62 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 63 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 64 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 65 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 67 | static constexpr int kRegListThreshold = 4; |
| 68 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 69 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 70 | // for each live D registers they treat two corresponding S registers as live ones. |
| 71 | // |
| 72 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 73 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 74 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 75 | // - decreasing code size |
| 76 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 77 | // restored and then used in regular non SlowPath code as D register. |
| 78 | // |
| 79 | // For the following example (v means the S register is live): |
| 80 | // D names: | D0 | D1 | D2 | D4 | ... |
| 81 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 82 | // Live? | | v | v | v | v | v | v | | ... |
| 83 | // |
| 84 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 85 | // as D registers. |
| 86 | static size_t SaveContiguousSRegisterList(size_t first, |
| 87 | size_t last, |
| 88 | CodeGenerator* codegen, |
| 89 | size_t stack_offset) { |
| 90 | DCHECK_LE(first, last); |
| 91 | if ((first == last) && (first == 0)) { |
| 92 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 93 | return stack_offset; |
| 94 | } |
| 95 | if (first % 2 == 1) { |
| 96 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 97 | } |
| 98 | |
| 99 | bool save_last = false; |
| 100 | if (last % 2 == 0) { |
| 101 | save_last = true; |
| 102 | --last; |
| 103 | } |
| 104 | |
| 105 | if (first < last) { |
| 106 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 107 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 108 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 109 | |
| 110 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 111 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 112 | } else if (number_of_d_regs > 1) { |
| 113 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 114 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 115 | } |
| 116 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 117 | } |
| 118 | |
| 119 | if (save_last) { |
| 120 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 121 | } |
| 122 | |
| 123 | return stack_offset; |
| 124 | } |
| 125 | |
| 126 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 127 | size_t last, |
| 128 | CodeGenerator* codegen, |
| 129 | size_t stack_offset) { |
| 130 | DCHECK_LE(first, last); |
| 131 | if ((first == last) && (first == 0)) { |
| 132 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 133 | return stack_offset; |
| 134 | } |
| 135 | if (first % 2 == 1) { |
| 136 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 137 | } |
| 138 | |
| 139 | bool restore_last = false; |
| 140 | if (last % 2 == 0) { |
| 141 | restore_last = true; |
| 142 | --last; |
| 143 | } |
| 144 | |
| 145 | if (first < last) { |
| 146 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 147 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 148 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 149 | if (number_of_d_regs == 1) { |
| 150 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 151 | } else if (number_of_d_regs > 1) { |
| 152 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 153 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 154 | } |
| 155 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 156 | } |
| 157 | |
| 158 | if (restore_last) { |
| 159 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 160 | } |
| 161 | |
| 162 | return stack_offset; |
| 163 | } |
| 164 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 165 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 166 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 167 | size_t orig_offset = stack_offset; |
| 168 | |
| 169 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 170 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 171 | // If the register holds an object, update the stack mask. |
| 172 | if (locations->RegisterContainsObject(i)) { |
| 173 | locations->SetStackBit(stack_offset / kVRegSize); |
| 174 | } |
| 175 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 176 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 177 | saved_core_stack_offsets_[i] = stack_offset; |
| 178 | stack_offset += kArmWordSize; |
| 179 | } |
| 180 | |
| 181 | int reg_num = POPCOUNT(core_spills); |
| 182 | if (reg_num != 0) { |
| 183 | if (reg_num > kRegListThreshold) { |
| 184 | __ StoreList(RegList(core_spills), orig_offset); |
| 185 | } else { |
| 186 | stack_offset = orig_offset; |
| 187 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 188 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 193 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 194 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 195 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 196 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 197 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 198 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 199 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 200 | |
| 201 | stack_offset = orig_offset; |
| 202 | while (fp_spills != 0u) { |
| 203 | uint32_t begin = CTZ(fp_spills); |
| 204 | uint32_t tmp = fp_spills + (1u << begin); |
| 205 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 206 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 207 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 208 | } |
| 209 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 213 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 214 | size_t orig_offset = stack_offset; |
| 215 | |
| 216 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 217 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 218 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 219 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 220 | stack_offset += kArmWordSize; |
| 221 | } |
| 222 | |
| 223 | int reg_num = POPCOUNT(core_spills); |
| 224 | if (reg_num != 0) { |
| 225 | if (reg_num > kRegListThreshold) { |
| 226 | __ LoadList(RegList(core_spills), orig_offset); |
| 227 | } else { |
| 228 | stack_offset = orig_offset; |
| 229 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 230 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 235 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 236 | while (fp_spills != 0u) { |
| 237 | uint32_t begin = CTZ(fp_spills); |
| 238 | uint32_t tmp = fp_spills + (1u << begin); |
| 239 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 240 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 241 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 242 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 243 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 247 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 248 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 249 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 250 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 251 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 252 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 253 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 254 | // Live registers will be restored in the catch block if caught. |
| 255 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 256 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 257 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 258 | instruction_, |
| 259 | instruction_->GetDexPc(), |
| 260 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 261 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 264 | bool IsFatal() const OVERRIDE { return true; } |
| 265 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 266 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 267 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 269 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 270 | }; |
| 271 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 272 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 273 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 274 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 275 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 276 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 277 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 278 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 279 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 280 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 283 | bool IsFatal() const OVERRIDE { return true; } |
| 284 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 285 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 286 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 288 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 289 | }; |
| 290 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 291 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 292 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 294 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 295 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 297 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 298 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 299 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 300 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 301 | if (successor_ == nullptr) { |
| 302 | __ b(GetReturnLabel()); |
| 303 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 304 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 305 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 308 | Label* GetReturnLabel() { |
| 309 | DCHECK(successor_ == nullptr); |
| 310 | return &return_label_; |
| 311 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 312 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 313 | HBasicBlock* GetSuccessor() const { |
| 314 | return successor_; |
| 315 | } |
| 316 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 317 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 318 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 319 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 320 | // If not null, the block to branch to after the suspend check. |
| 321 | HBasicBlock* const successor_; |
| 322 | |
| 323 | // 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] | 324 | Label return_label_; |
| 325 | |
| 326 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 327 | }; |
| 328 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 329 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 330 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 331 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 332 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 333 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 334 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 335 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 336 | LocationSummary* locations = instruction_->GetLocations(); |
| 337 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 338 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 339 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 340 | // Live registers will be restored in the catch block if caught. |
| 341 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 342 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 343 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 344 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 345 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 346 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 348 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 349 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 350 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 351 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 352 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 353 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 354 | ? kQuickThrowStringBounds |
| 355 | : kQuickThrowArrayBounds; |
| 356 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 358 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 361 | bool IsFatal() const OVERRIDE { return true; } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 364 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 366 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 367 | }; |
| 368 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 369 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 370 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 371 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 372 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 373 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 374 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 375 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 376 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 377 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 378 | Location out = locations->Out(); |
| 379 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 380 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 381 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 382 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 383 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 385 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 386 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 387 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 388 | bool is_load_class_bss_entry = |
| 389 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 390 | Register entry_address = kNoRegister; |
| 391 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 392 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 393 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 394 | // the kSaveEverything call. |
| 395 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 396 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 397 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 398 | if (temp_is_r0) { |
| 399 | __ mov(entry_address, ShifterOperand(temp)); |
| 400 | } |
| 401 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 402 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 403 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 404 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 405 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 406 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 407 | if (do_clinit_) { |
| 408 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 409 | } else { |
| 410 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 411 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 412 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 413 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 414 | if (is_load_class_bss_entry) { |
| 415 | if (call_saves_everything_except_r0) { |
| 416 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 417 | __ str(R0, Address(entry_address)); |
| 418 | } else { |
| 419 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 420 | Register temp = IP; |
| 421 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 422 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 423 | __ BindTrackedLabel(&labels->movw_label); |
| 424 | __ movw(temp, /* placeholder */ 0u); |
| 425 | __ BindTrackedLabel(&labels->movt_label); |
| 426 | __ movt(temp, /* placeholder */ 0u); |
| 427 | __ BindTrackedLabel(&labels->add_pc_label); |
| 428 | __ add(temp, temp, ShifterOperand(PC)); |
| 429 | __ str(R0, Address(temp)); |
| 430 | } |
| 431 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 432 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 433 | if (out.IsValid()) { |
| 434 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 435 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 436 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 438 | __ b(GetExitLabel()); |
| 439 | } |
| 440 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 441 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 442 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 443 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 444 | // The class this slow path will load. |
| 445 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 446 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 447 | // The dex PC of `at_`. |
| 448 | const uint32_t dex_pc_; |
| 449 | |
| 450 | // Whether to initialize the class. |
| 451 | const bool do_clinit_; |
| 452 | |
| 453 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 454 | }; |
| 455 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 456 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 457 | public: |
| 458 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 459 | |
| 460 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 461 | DCHECK(instruction_->IsLoadString()); |
| 462 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 463 | LocationSummary* locations = instruction_->GetLocations(); |
| 464 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 465 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 466 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 467 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 468 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 469 | |
| 470 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 471 | __ Bind(GetEntryLabel()); |
| 472 | SaveLiveRegisters(codegen, locations); |
| 473 | |
| 474 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 475 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 476 | // the kSaveEverything call. |
| 477 | Register entry_address = kNoRegister; |
| 478 | if (call_saves_everything_except_r0) { |
| 479 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 480 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 481 | entry_address = temp_is_r0 ? out : temp; |
| 482 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 483 | if (temp_is_r0) { |
| 484 | __ mov(entry_address, ShifterOperand(temp)); |
| 485 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 488 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 489 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 490 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 491 | |
| 492 | // Store the resolved String to the .bss entry. |
| 493 | if (call_saves_everything_except_r0) { |
| 494 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 495 | __ str(R0, Address(entry_address)); |
| 496 | } else { |
| 497 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 498 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 499 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 500 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 501 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 502 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 503 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 504 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 505 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 506 | __ add(temp, temp, ShifterOperand(PC)); |
| 507 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 510 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 511 | RestoreLiveRegisters(codegen, locations); |
| 512 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 513 | __ b(GetExitLabel()); |
| 514 | } |
| 515 | |
| 516 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 517 | |
| 518 | private: |
| 519 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 520 | }; |
| 521 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 522 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 523 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 524 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 525 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 527 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 528 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 529 | DCHECK(instruction_->IsCheckCast() |
| 530 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 531 | |
| 532 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 533 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 534 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 535 | if (!is_fatal_) { |
| 536 | SaveLiveRegisters(codegen, locations); |
| 537 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 538 | |
| 539 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 540 | // move resolver. |
| 541 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 542 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 543 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 544 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 545 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 546 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 547 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 548 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 549 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 550 | instruction_, |
| 551 | instruction_->GetDexPc(), |
| 552 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 553 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 554 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 555 | } else { |
| 556 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 557 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 558 | instruction_, |
| 559 | instruction_->GetDexPc(), |
| 560 | this); |
| 561 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 562 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 563 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 564 | if (!is_fatal_) { |
| 565 | RestoreLiveRegisters(codegen, locations); |
| 566 | __ b(GetExitLabel()); |
| 567 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 570 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 571 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 572 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 573 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 574 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 575 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 576 | |
| 577 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 578 | }; |
| 579 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 580 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 581 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 582 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 583 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 584 | |
| 585 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 586 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 587 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 588 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 589 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 592 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 593 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 594 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 595 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 596 | }; |
| 597 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 598 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 599 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 600 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 601 | |
| 602 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 603 | LocationSummary* locations = instruction_->GetLocations(); |
| 604 | __ Bind(GetEntryLabel()); |
| 605 | SaveLiveRegisters(codegen, locations); |
| 606 | |
| 607 | InvokeRuntimeCallingConvention calling_convention; |
| 608 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 609 | parallel_move.AddMove( |
| 610 | locations->InAt(0), |
| 611 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 612 | Primitive::kPrimNot, |
| 613 | nullptr); |
| 614 | parallel_move.AddMove( |
| 615 | locations->InAt(1), |
| 616 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 617 | Primitive::kPrimInt, |
| 618 | nullptr); |
| 619 | parallel_move.AddMove( |
| 620 | locations->InAt(2), |
| 621 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 622 | Primitive::kPrimNot, |
| 623 | nullptr); |
| 624 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 625 | |
| 626 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 627 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 628 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 629 | RestoreLiveRegisters(codegen, locations); |
| 630 | __ b(GetExitLabel()); |
| 631 | } |
| 632 | |
| 633 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 634 | |
| 635 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 636 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 637 | }; |
| 638 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 639 | // Slow path marking an object reference `ref` during a read |
| 640 | // barrier. The field `obj.field` in the object `obj` holding this |
| 641 | // reference does not get updated by this slow path after marking (see |
| 642 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 643 | // |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 644 | // This means that after the execution of this slow path, `ref` will |
| 645 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 646 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 647 | // probably still be a from-space reference (unless it gets updated by |
| 648 | // another thread, or if another thread installed another object |
| 649 | // reference (different from `ref`) in `obj.field`). |
| 650 | // |
| 651 | // If `entrypoint` is a valid location it is assumed to already be |
| 652 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 653 | // is for the GcRoot read barrier. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 654 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
| 655 | public: |
| 656 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 657 | Location ref, |
| 658 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 659 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 660 | DCHECK(kEmitCompilerReadBarrier); |
| 661 | } |
| 662 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 663 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 664 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 665 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 666 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 667 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 668 | DCHECK(locations->CanCall()); |
| 669 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 670 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 671 | instruction_->IsStaticFieldGet() || |
| 672 | instruction_->IsArrayGet() || |
| 673 | instruction_->IsArraySet() || |
| 674 | instruction_->IsLoadClass() || |
| 675 | instruction_->IsLoadString() || |
| 676 | instruction_->IsInstanceOf() || |
| 677 | instruction_->IsCheckCast() || |
| 678 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 679 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 680 | << "Unexpected instruction in read barrier marking slow path: " |
| 681 | << instruction_->DebugName(); |
| 682 | // The read barrier instrumentation of object ArrayGet |
| 683 | // instructions does not support the HIntermediateAddress |
| 684 | // instruction. |
| 685 | DCHECK(!(instruction_->IsArrayGet() && |
| 686 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 687 | |
| 688 | __ Bind(GetEntryLabel()); |
| 689 | // No need to save live registers; it's taken care of by the |
| 690 | // entrypoint. Also, there is no need to update the stack mask, |
| 691 | // as this runtime call will not trigger a garbage collection. |
| 692 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 693 | DCHECK_NE(ref_reg, SP); |
| 694 | DCHECK_NE(ref_reg, LR); |
| 695 | DCHECK_NE(ref_reg, PC); |
| 696 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 697 | // as a temporary, it cannot be the entry point's input/output. |
| 698 | DCHECK_NE(ref_reg, IP); |
| 699 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 700 | // "Compact" slow path, saving two moves. |
| 701 | // |
| 702 | // Instead of using the standard runtime calling convention (input |
| 703 | // and output in R0): |
| 704 | // |
| 705 | // R0 <- ref |
| 706 | // R0 <- ReadBarrierMark(R0) |
| 707 | // ref <- R0 |
| 708 | // |
| 709 | // we just use rX (the register containing `ref`) as input and output |
| 710 | // of a dedicated entrypoint: |
| 711 | // |
| 712 | // rX <- ReadBarrierMarkRegX(rX) |
| 713 | // |
| 714 | if (entrypoint_.IsValid()) { |
| 715 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 716 | __ blx(entrypoint_.AsRegister<Register>()); |
| 717 | } else { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 718 | int32_t entry_point_offset = |
| 719 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 720 | // This runtime call does not require a stack map. |
| 721 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 722 | } |
| 723 | __ b(GetExitLabel()); |
| 724 | } |
| 725 | |
| 726 | private: |
| 727 | // The location (register) of the marked object reference. |
| 728 | const Location ref_; |
| 729 | |
| 730 | // The location of the entrypoint if already loaded. |
| 731 | const Location entrypoint_; |
| 732 | |
| 733 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 734 | }; |
| 735 | |
| 736 | // Slow path marking an object reference `ref` during a read barrier, |
| 737 | // and if needed, atomically updating the field `obj.field` in the |
| 738 | // object `obj` holding this reference after marking (contrary to |
| 739 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 740 | // `obj.field`). |
| 741 | // |
| 742 | // This means that after the execution of this slow path, both `ref` |
| 743 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 744 | // hold the same to-space reference (unless another thread installed |
| 745 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 746 | class ReadBarrierMarkAndUpdateFieldSlowPathARM : public SlowPathCodeARM { |
| 747 | public: |
| 748 | ReadBarrierMarkAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 749 | Location ref, |
| 750 | Register obj, |
| 751 | Location field_offset, |
| 752 | Register temp1, |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 753 | Register temp2) |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 754 | : SlowPathCodeARM(instruction), |
| 755 | ref_(ref), |
| 756 | obj_(obj), |
| 757 | field_offset_(field_offset), |
| 758 | temp1_(temp1), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 759 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 760 | DCHECK(kEmitCompilerReadBarrier); |
| 761 | } |
| 762 | |
| 763 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathARM"; } |
| 764 | |
| 765 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 766 | LocationSummary* locations = instruction_->GetLocations(); |
| 767 | Register ref_reg = ref_.AsRegister<Register>(); |
| 768 | DCHECK(locations->CanCall()); |
| 769 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 770 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 771 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 772 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 773 | << instruction_->DebugName(); |
| 774 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 775 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 776 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 777 | |
| 778 | __ Bind(GetEntryLabel()); |
| 779 | |
| 780 | // Save the old reference. |
| 781 | // Note that we cannot use IP to save the old reference, as IP is |
| 782 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 783 | // need the old reference after the call to that entry point. |
| 784 | DCHECK_NE(temp1_, IP); |
| 785 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 786 | |
| 787 | // No need to save live registers; it's taken care of by the |
| 788 | // entrypoint. Also, there is no need to update the stack mask, |
| 789 | // as this runtime call will not trigger a garbage collection. |
| 790 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 791 | DCHECK_NE(ref_reg, SP); |
| 792 | DCHECK_NE(ref_reg, LR); |
| 793 | DCHECK_NE(ref_reg, PC); |
| 794 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 795 | // as a temporary, it cannot be the entry point's input/output. |
| 796 | DCHECK_NE(ref_reg, IP); |
| 797 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 798 | // "Compact" slow path, saving two moves. |
| 799 | // |
| 800 | // Instead of using the standard runtime calling convention (input |
| 801 | // and output in R0): |
| 802 | // |
| 803 | // R0 <- ref |
| 804 | // R0 <- ReadBarrierMark(R0) |
| 805 | // ref <- R0 |
| 806 | // |
| 807 | // we just use rX (the register containing `ref`) as input and output |
| 808 | // of a dedicated entrypoint: |
| 809 | // |
| 810 | // rX <- ReadBarrierMarkRegX(rX) |
| 811 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 812 | int32_t entry_point_offset = |
| 813 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 814 | // This runtime call does not require a stack map. |
| 815 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 816 | |
| 817 | // If the new reference is different from the old reference, |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 818 | // update the field in the holder (`*(obj_ + field_offset_)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 819 | // |
| 820 | // Note that this field could also hold a different object, if |
| 821 | // another thread had concurrently changed it. In that case, the |
| 822 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 823 | // (CAS) operation below would abort the CAS, leaving the field |
| 824 | // as-is. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 825 | Label done; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 826 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 827 | __ b(&done, EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 828 | |
| 829 | // Update the the holder's field atomically. This may fail if |
| 830 | // mutator updates before us, but it's OK. This is achieved |
| 831 | // using a strong compare-and-set (CAS) operation with relaxed |
| 832 | // memory synchronization ordering, where the expected value is |
| 833 | // the old reference and the desired value is the new reference. |
| 834 | |
| 835 | // Convenience aliases. |
| 836 | Register base = obj_; |
| 837 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 838 | // offset ("long offset"), of which only the low part contains |
| 839 | // data. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 840 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 841 | Register expected = temp1_; |
| 842 | Register value = ref_reg; |
| 843 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 844 | Register tmp = temp2_; // Value in memory. |
| 845 | |
| 846 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 847 | |
| 848 | if (kPoisonHeapReferences) { |
| 849 | __ PoisonHeapReference(expected); |
| 850 | if (value == expected) { |
| 851 | // Do not poison `value`, as it is the same register as |
| 852 | // `expected`, which has just been poisoned. |
| 853 | } else { |
| 854 | __ PoisonHeapReference(value); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | // do { |
| 859 | // tmp = [r_ptr] - expected; |
| 860 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 861 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 862 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 863 | __ Bind(&loop_head); |
| 864 | |
| 865 | __ ldrex(tmp, tmp_ptr); |
| 866 | |
| 867 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 868 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 869 | __ it(NE); |
| 870 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 871 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 872 | __ b(&exit_loop, NE); |
| 873 | |
| 874 | __ strex(tmp, value, tmp_ptr); |
| 875 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 876 | __ b(&loop_head, EQ); |
| 877 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 878 | __ Bind(&exit_loop); |
| 879 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 880 | if (kPoisonHeapReferences) { |
| 881 | __ UnpoisonHeapReference(expected); |
| 882 | if (value == expected) { |
| 883 | // Do not unpoison `value`, as it is the same register as |
| 884 | // `expected`, which has just been unpoisoned. |
| 885 | } else { |
| 886 | __ UnpoisonHeapReference(value); |
| 887 | } |
| 888 | } |
| 889 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 890 | __ Bind(&done); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 891 | __ b(GetExitLabel()); |
| 892 | } |
| 893 | |
| 894 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 895 | // The location (register) of the marked object reference. |
| 896 | const Location ref_; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 897 | // The register containing the object holding the marked object reference field. |
| 898 | const Register obj_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 899 | // The location of the offset of the marked reference field within `obj_`. |
| 900 | Location field_offset_; |
| 901 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 902 | const Register temp1_; |
| 903 | const Register temp2_; |
| 904 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 905 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 906 | }; |
| 907 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 908 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 909 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 910 | public: |
| 911 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 912 | Location out, |
| 913 | Location ref, |
| 914 | Location obj, |
| 915 | uint32_t offset, |
| 916 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 917 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 918 | out_(out), |
| 919 | ref_(ref), |
| 920 | obj_(obj), |
| 921 | offset_(offset), |
| 922 | index_(index) { |
| 923 | DCHECK(kEmitCompilerReadBarrier); |
| 924 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 925 | // has been overwritten by (or after) the heap object reference load |
| 926 | // to be instrumented, e.g.: |
| 927 | // |
| 928 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 929 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 930 | // |
| 931 | // In that case, we have lost the information about the original |
| 932 | // object, and the emitted read barrier cannot work properly. |
| 933 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 934 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 935 | } |
| 936 | |
| 937 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 938 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 939 | LocationSummary* locations = instruction_->GetLocations(); |
| 940 | Register reg_out = out_.AsRegister<Register>(); |
| 941 | DCHECK(locations->CanCall()); |
| 942 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 943 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 944 | instruction_->IsStaticFieldGet() || |
| 945 | instruction_->IsArrayGet() || |
| 946 | instruction_->IsInstanceOf() || |
| 947 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 948 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 949 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 950 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 951 | // The read barrier instrumentation of object ArrayGet |
| 952 | // instructions does not support the HIntermediateAddress |
| 953 | // instruction. |
| 954 | DCHECK(!(instruction_->IsArrayGet() && |
| 955 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 956 | |
| 957 | __ Bind(GetEntryLabel()); |
| 958 | SaveLiveRegisters(codegen, locations); |
| 959 | |
| 960 | // We may have to change the index's value, but as `index_` is a |
| 961 | // constant member (like other "inputs" of this slow path), |
| 962 | // introduce a copy of it, `index`. |
| 963 | Location index = index_; |
| 964 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 965 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 966 | if (instruction_->IsArrayGet()) { |
| 967 | // Compute the actual memory offset and store it in `index`. |
| 968 | Register index_reg = index_.AsRegister<Register>(); |
| 969 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 970 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 971 | // We are about to change the value of `index_reg` (see the |
| 972 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 973 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 974 | // not been saved by the previous call to |
| 975 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 976 | // callee-save register -- |
| 977 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 978 | // callee-save registers, as it has been designed with the |
| 979 | // assumption that callee-save registers are supposed to be |
| 980 | // handled by the called function. So, as a callee-save |
| 981 | // register, `index_reg` _would_ eventually be saved onto |
| 982 | // the stack, but it would be too late: we would have |
| 983 | // changed its value earlier. Therefore, we manually save |
| 984 | // it here into another freely available register, |
| 985 | // `free_reg`, chosen of course among the caller-save |
| 986 | // registers (as a callee-save `free_reg` register would |
| 987 | // exhibit the same problem). |
| 988 | // |
| 989 | // Note we could have requested a temporary register from |
| 990 | // the register allocator instead; but we prefer not to, as |
| 991 | // this is a slow path, and we know we can find a |
| 992 | // caller-save register that is available. |
| 993 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 994 | __ Mov(free_reg, index_reg); |
| 995 | index_reg = free_reg; |
| 996 | index = Location::RegisterLocation(index_reg); |
| 997 | } else { |
| 998 | // The initial register stored in `index_` has already been |
| 999 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1000 | // (as it is not a callee-save register), so we can freely |
| 1001 | // use it. |
| 1002 | } |
| 1003 | // Shifting the index value contained in `index_reg` by the scale |
| 1004 | // factor (2) cannot overflow in practice, as the runtime is |
| 1005 | // unable to allocate object arrays with a size larger than |
| 1006 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1007 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1008 | static_assert( |
| 1009 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1010 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1011 | __ AddConstant(index_reg, index_reg, offset_); |
| 1012 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1013 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1014 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1015 | // (as in the case of ArrayGet), as it is actually an offset |
| 1016 | // to an object field within an object. |
| 1017 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1018 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1019 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1020 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1021 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1022 | DCHECK_EQ(offset_, 0U); |
| 1023 | DCHECK(index_.IsRegisterPair()); |
| 1024 | // UnsafeGet's offset location is a register pair, the low |
| 1025 | // part contains the correct offset. |
| 1026 | index = index_.ToLow(); |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | // We're moving two or three locations to locations that could |
| 1031 | // overlap, so we need a parallel move resolver. |
| 1032 | InvokeRuntimeCallingConvention calling_convention; |
| 1033 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1034 | parallel_move.AddMove(ref_, |
| 1035 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1036 | Primitive::kPrimNot, |
| 1037 | nullptr); |
| 1038 | parallel_move.AddMove(obj_, |
| 1039 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1040 | Primitive::kPrimNot, |
| 1041 | nullptr); |
| 1042 | if (index.IsValid()) { |
| 1043 | parallel_move.AddMove(index, |
| 1044 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1045 | Primitive::kPrimInt, |
| 1046 | nullptr); |
| 1047 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1048 | } else { |
| 1049 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1050 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1051 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1052 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1053 | CheckEntrypointTypes< |
| 1054 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1055 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1056 | |
| 1057 | RestoreLiveRegisters(codegen, locations); |
| 1058 | __ b(GetExitLabel()); |
| 1059 | } |
| 1060 | |
| 1061 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1062 | |
| 1063 | private: |
| 1064 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1065 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1066 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1067 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1068 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1069 | return static_cast<Register>(i); |
| 1070 | } |
| 1071 | } |
| 1072 | // We shall never fail to find a free caller-save register, as |
| 1073 | // there are more than two core caller-save registers on ARM |
| 1074 | // (meaning it is possible to find one which is different from |
| 1075 | // `ref` and `obj`). |
| 1076 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1077 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1078 | UNREACHABLE(); |
| 1079 | } |
| 1080 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1081 | const Location out_; |
| 1082 | const Location ref_; |
| 1083 | const Location obj_; |
| 1084 | const uint32_t offset_; |
| 1085 | // An additional location containing an index to an array. |
| 1086 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1087 | // UnsafeGetObjectVolatile intrinsics. |
| 1088 | const Location index_; |
| 1089 | |
| 1090 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1091 | }; |
| 1092 | |
| 1093 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1094 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1095 | public: |
| 1096 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1097 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1098 | DCHECK(kEmitCompilerReadBarrier); |
| 1099 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1100 | |
| 1101 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1102 | LocationSummary* locations = instruction_->GetLocations(); |
| 1103 | Register reg_out = out_.AsRegister<Register>(); |
| 1104 | DCHECK(locations->CanCall()); |
| 1105 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1106 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1107 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1108 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1109 | |
| 1110 | __ Bind(GetEntryLabel()); |
| 1111 | SaveLiveRegisters(codegen, locations); |
| 1112 | |
| 1113 | InvokeRuntimeCallingConvention calling_convention; |
| 1114 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1115 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1116 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1117 | instruction_, |
| 1118 | instruction_->GetDexPc(), |
| 1119 | this); |
| 1120 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1121 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1122 | |
| 1123 | RestoreLiveRegisters(codegen, locations); |
| 1124 | __ b(GetExitLabel()); |
| 1125 | } |
| 1126 | |
| 1127 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1128 | |
| 1129 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1130 | const Location out_; |
| 1131 | const Location root_; |
| 1132 | |
| 1133 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1134 | }; |
| 1135 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1136 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1137 | switch (cond) { |
| 1138 | case kCondEQ: return EQ; |
| 1139 | case kCondNE: return NE; |
| 1140 | case kCondLT: return LT; |
| 1141 | case kCondLE: return LE; |
| 1142 | case kCondGT: return GT; |
| 1143 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1144 | case kCondB: return LO; |
| 1145 | case kCondBE: return LS; |
| 1146 | case kCondA: return HI; |
| 1147 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1148 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1149 | LOG(FATAL) << "Unreachable"; |
| 1150 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1153 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1154 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1155 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1156 | case kCondEQ: return EQ; |
| 1157 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1158 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1159 | case kCondLT: return LO; |
| 1160 | case kCondLE: return LS; |
| 1161 | case kCondGT: return HI; |
| 1162 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1163 | // Unsigned remain unchanged. |
| 1164 | case kCondB: return LO; |
| 1165 | case kCondBE: return LS; |
| 1166 | case kCondA: return HI; |
| 1167 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1168 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1169 | LOG(FATAL) << "Unreachable"; |
| 1170 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1173 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1174 | // The ARM condition codes can express all the necessary branches, see the |
| 1175 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1176 | // There is no dex instruction or HIR that would need the missing conditions |
| 1177 | // "equal or unordered" or "not equal". |
| 1178 | switch (cond) { |
| 1179 | case kCondEQ: return EQ; |
| 1180 | case kCondNE: return NE /* unordered */; |
| 1181 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1182 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1183 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1184 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1185 | default: |
| 1186 | LOG(FATAL) << "UNREACHABLE"; |
| 1187 | UNREACHABLE(); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1191 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1192 | switch (op_kind) { |
| 1193 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1194 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1195 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1196 | default: |
| 1197 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1198 | UNREACHABLE(); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1203 | Register out, |
| 1204 | Register first, |
| 1205 | const ShifterOperand& second, |
| 1206 | CodeGeneratorARM* codegen) { |
| 1207 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1208 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1209 | ? ShifterOperand(0) |
| 1210 | : ShifterOperand(first); |
| 1211 | |
| 1212 | __ mov(out, in); |
| 1213 | } else { |
| 1214 | switch (kind) { |
| 1215 | case HInstruction::kAdd: |
| 1216 | __ add(out, first, second); |
| 1217 | break; |
| 1218 | case HInstruction::kAnd: |
| 1219 | __ and_(out, first, second); |
| 1220 | break; |
| 1221 | case HInstruction::kOr: |
| 1222 | __ orr(out, first, second); |
| 1223 | break; |
| 1224 | case HInstruction::kSub: |
| 1225 | __ sub(out, first, second); |
| 1226 | break; |
| 1227 | case HInstruction::kXor: |
| 1228 | __ eor(out, first, second); |
| 1229 | break; |
| 1230 | default: |
| 1231 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1232 | UNREACHABLE(); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1238 | const Location& out, |
| 1239 | const Location& first, |
| 1240 | const ShifterOperand& second_lo, |
| 1241 | const ShifterOperand& second_hi, |
| 1242 | CodeGeneratorARM* codegen) { |
| 1243 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1244 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1245 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1246 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1247 | |
| 1248 | if (kind == HInstruction::kAdd) { |
| 1249 | __ adds(out_lo, first_lo, second_lo); |
| 1250 | __ adc(out_hi, first_hi, second_hi); |
| 1251 | } else if (kind == HInstruction::kSub) { |
| 1252 | __ subs(out_lo, first_lo, second_lo); |
| 1253 | __ sbc(out_hi, first_hi, second_hi); |
| 1254 | } else { |
| 1255 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1256 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1261 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1262 | } |
| 1263 | |
| 1264 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1265 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1266 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1267 | |
| 1268 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1269 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1270 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1271 | const Location first = locations->InAt(0); |
| 1272 | const Location second = locations->InAt(1); |
| 1273 | const Location out = locations->Out(); |
| 1274 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1275 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1276 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1277 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1278 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1279 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1280 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1281 | |
| 1282 | if (shift_value >= 32) { |
| 1283 | if (shift == LSL) { |
| 1284 | GenerateDataProcInstruction(kind, |
| 1285 | out_hi, |
| 1286 | first_hi, |
| 1287 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1288 | codegen); |
| 1289 | GenerateDataProcInstruction(kind, |
| 1290 | out_lo, |
| 1291 | first_lo, |
| 1292 | ShifterOperand(0), |
| 1293 | codegen); |
| 1294 | } else if (shift == ASR) { |
| 1295 | GenerateDataProc(kind, |
| 1296 | out, |
| 1297 | first, |
| 1298 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1299 | ShifterOperand(second_hi, ASR, 31), |
| 1300 | codegen); |
| 1301 | } else { |
| 1302 | DCHECK_EQ(shift, LSR); |
| 1303 | GenerateDataProc(kind, |
| 1304 | out, |
| 1305 | first, |
| 1306 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1307 | ShifterOperand(0), |
| 1308 | codegen); |
| 1309 | } |
| 1310 | } else { |
| 1311 | DCHECK_GT(shift_value, 1U); |
| 1312 | DCHECK_LT(shift_value, 32U); |
| 1313 | |
| 1314 | if (shift == LSL) { |
| 1315 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1316 | // Location::kOutputOverlap; not applicable to other cases. |
| 1317 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1318 | GenerateDataProcInstruction(kind, |
| 1319 | out_hi, |
| 1320 | first_hi, |
| 1321 | ShifterOperand(second_hi, LSL, shift_value), |
| 1322 | codegen); |
| 1323 | GenerateDataProcInstruction(kind, |
| 1324 | out_hi, |
| 1325 | out_hi, |
| 1326 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1327 | codegen); |
| 1328 | GenerateDataProcInstruction(kind, |
| 1329 | out_lo, |
| 1330 | first_lo, |
| 1331 | ShifterOperand(second_lo, LSL, shift_value), |
| 1332 | codegen); |
| 1333 | } else { |
| 1334 | __ Lsl(IP, second_hi, shift_value); |
| 1335 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1336 | GenerateDataProc(kind, |
| 1337 | out, |
| 1338 | first, |
| 1339 | ShifterOperand(second_lo, LSL, shift_value), |
| 1340 | ShifterOperand(IP), |
| 1341 | codegen); |
| 1342 | } |
| 1343 | } else { |
| 1344 | DCHECK(shift == ASR || shift == LSR); |
| 1345 | |
| 1346 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1347 | // Location::kOutputOverlap; not applicable to other cases. |
| 1348 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1349 | GenerateDataProcInstruction(kind, |
| 1350 | out_lo, |
| 1351 | first_lo, |
| 1352 | ShifterOperand(second_lo, LSR, shift_value), |
| 1353 | codegen); |
| 1354 | GenerateDataProcInstruction(kind, |
| 1355 | out_lo, |
| 1356 | out_lo, |
| 1357 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1358 | codegen); |
| 1359 | GenerateDataProcInstruction(kind, |
| 1360 | out_hi, |
| 1361 | first_hi, |
| 1362 | ShifterOperand(second_hi, shift, shift_value), |
| 1363 | codegen); |
| 1364 | } else { |
| 1365 | __ Lsr(IP, second_lo, shift_value); |
| 1366 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1367 | GenerateDataProc(kind, |
| 1368 | out, |
| 1369 | first, |
| 1370 | ShifterOperand(IP), |
| 1371 | ShifterOperand(second_hi, shift, shift_value), |
| 1372 | codegen); |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 1378 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1379 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1380 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1381 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1382 | if (rhs_loc.IsConstant()) { |
| 1383 | // 0.0 is the only immediate that can be encoded directly in |
| 1384 | // a VCMP instruction. |
| 1385 | // |
| 1386 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1387 | // specify that in a floating-point comparison, positive zero |
| 1388 | // and negative zero are considered equal, so we can use the |
| 1389 | // literal 0.0 for both cases here. |
| 1390 | // |
| 1391 | // Note however that some methods (Float.equal, Float.compare, |
| 1392 | // Float.compareTo, Double.equal, Double.compare, |
| 1393 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1394 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1395 | // -0.0. So if we ever translate calls to these methods into a |
| 1396 | // HCompare instruction, we must handle the -0.0 case with |
| 1397 | // care here. |
| 1398 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1399 | if (type == Primitive::kPrimFloat) { |
| 1400 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1401 | } else { |
| 1402 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1403 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1404 | } |
| 1405 | } else { |
| 1406 | if (type == Primitive::kPrimFloat) { |
| 1407 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1408 | } else { |
| 1409 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1410 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1411 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | static Condition GenerateLongTestConstant(HCondition* condition, |
| 1417 | bool invert, |
| 1418 | CodeGeneratorARM* codegen) { |
| 1419 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1420 | |
| 1421 | const LocationSummary* const locations = condition->GetLocations(); |
| 1422 | IfCondition cond = invert ? condition->GetOppositeCondition() : condition->GetCondition(); |
| 1423 | Condition ret = EQ; |
| 1424 | const Location left = locations->InAt(0); |
| 1425 | const Location right = locations->InAt(1); |
| 1426 | |
| 1427 | DCHECK(right.IsConstant()); |
| 1428 | |
| 1429 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1430 | const Register left_low = left.AsRegisterPairLow<Register>(); |
| 1431 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1432 | |
| 1433 | switch (cond) { |
| 1434 | case kCondEQ: |
| 1435 | case kCondNE: |
| 1436 | case kCondB: |
| 1437 | case kCondBE: |
| 1438 | case kCondA: |
| 1439 | case kCondAE: |
| 1440 | __ CmpConstant(left_high, High32Bits(value)); |
| 1441 | __ it(EQ); |
| 1442 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
| 1443 | ret = ARMUnsignedCondition(cond); |
| 1444 | break; |
| 1445 | case kCondLE: |
| 1446 | case kCondGT: |
| 1447 | // Trivially true or false. |
| 1448 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1449 | __ cmp(left_low, ShifterOperand(left_low)); |
| 1450 | ret = cond == kCondLE ? EQ : NE; |
| 1451 | break; |
| 1452 | } |
| 1453 | |
| 1454 | if (cond == kCondLE) { |
| 1455 | cond = kCondLT; |
| 1456 | } else { |
| 1457 | DCHECK_EQ(cond, kCondGT); |
| 1458 | cond = kCondGE; |
| 1459 | } |
| 1460 | |
| 1461 | value++; |
| 1462 | FALLTHROUGH_INTENDED; |
| 1463 | case kCondGE: |
| 1464 | case kCondLT: |
| 1465 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1466 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
| 1467 | ret = ARMCondition(cond); |
| 1468 | break; |
| 1469 | default: |
| 1470 | LOG(FATAL) << "Unreachable"; |
| 1471 | UNREACHABLE(); |
| 1472 | } |
| 1473 | |
| 1474 | return ret; |
| 1475 | } |
| 1476 | |
| 1477 | static Condition GenerateLongTest(HCondition* condition, |
| 1478 | bool invert, |
| 1479 | CodeGeneratorARM* codegen) { |
| 1480 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1481 | |
| 1482 | const LocationSummary* const locations = condition->GetLocations(); |
| 1483 | IfCondition cond = invert ? condition->GetOppositeCondition() : condition->GetCondition(); |
| 1484 | Condition ret = EQ; |
| 1485 | Location left = locations->InAt(0); |
| 1486 | Location right = locations->InAt(1); |
| 1487 | |
| 1488 | DCHECK(right.IsRegisterPair()); |
| 1489 | |
| 1490 | switch (cond) { |
| 1491 | case kCondEQ: |
| 1492 | case kCondNE: |
| 1493 | case kCondB: |
| 1494 | case kCondBE: |
| 1495 | case kCondA: |
| 1496 | case kCondAE: |
| 1497 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1498 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1499 | __ it(EQ); |
| 1500 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1501 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1502 | EQ); |
| 1503 | ret = ARMUnsignedCondition(cond); |
| 1504 | break; |
| 1505 | case kCondLE: |
| 1506 | case kCondGT: |
| 1507 | if (cond == kCondLE) { |
| 1508 | cond = kCondGE; |
| 1509 | } else { |
| 1510 | DCHECK_EQ(cond, kCondGT); |
| 1511 | cond = kCondLT; |
| 1512 | } |
| 1513 | |
| 1514 | std::swap(left, right); |
| 1515 | FALLTHROUGH_INTENDED; |
| 1516 | case kCondGE: |
| 1517 | case kCondLT: |
| 1518 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1519 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1520 | __ sbcs(IP, |
| 1521 | left.AsRegisterPairHigh<Register>(), |
| 1522 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1523 | ret = ARMCondition(cond); |
| 1524 | break; |
| 1525 | default: |
| 1526 | LOG(FATAL) << "Unreachable"; |
| 1527 | UNREACHABLE(); |
| 1528 | } |
| 1529 | |
| 1530 | return ret; |
| 1531 | } |
| 1532 | |
| 1533 | static Condition GenerateTest(HInstruction* instruction, |
| 1534 | Location loc, |
| 1535 | bool invert, |
| 1536 | CodeGeneratorARM* codegen) { |
| 1537 | DCHECK(!instruction->IsConstant()); |
| 1538 | |
| 1539 | Condition ret = invert ? EQ : NE; |
| 1540 | |
| 1541 | if (IsBooleanValueOrMaterializedCondition(instruction)) { |
| 1542 | __ CmpConstant(loc.AsRegister<Register>(), 0); |
| 1543 | } else { |
| 1544 | HCondition* const condition = instruction->AsCondition(); |
| 1545 | const LocationSummary* const locations = condition->GetLocations(); |
| 1546 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1547 | const IfCondition cond = invert ? condition->GetOppositeCondition() : condition->GetCondition(); |
| 1548 | const Location right = locations->InAt(1); |
| 1549 | |
| 1550 | if (type == Primitive::kPrimLong) { |
| 1551 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1552 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1553 | : GenerateLongTest(condition, invert, codegen); |
| 1554 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1555 | GenerateVcmp(condition, codegen); |
| 1556 | __ vmstat(); |
| 1557 | ret = ARMFPCondition(cond, condition->IsGtBias()); |
| 1558 | } else { |
| 1559 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1560 | |
| 1561 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1562 | |
| 1563 | if (right.IsRegister()) { |
| 1564 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 1565 | } else { |
| 1566 | DCHECK(right.IsConstant()); |
| 1567 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1568 | } |
| 1569 | |
| 1570 | ret = ARMCondition(cond); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | return ret; |
| 1575 | } |
| 1576 | |
| 1577 | static bool CanGenerateTest(HInstruction* condition, ArmAssembler* assembler) { |
| 1578 | if (!IsBooleanValueOrMaterializedCondition(condition)) { |
| 1579 | const HCondition* const cond = condition->AsCondition(); |
| 1580 | |
| 1581 | if (cond->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1582 | const LocationSummary* const locations = cond->GetLocations(); |
| 1583 | const IfCondition c = cond->GetCondition(); |
| 1584 | |
| 1585 | if (locations->InAt(1).IsConstant()) { |
| 1586 | const int64_t value = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 1587 | ShifterOperand so; |
| 1588 | |
| 1589 | if (c < kCondLT || c > kCondGE) { |
| 1590 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1591 | // we check that the least significant half of the first input to be compared |
| 1592 | // is in a low register (the other half is read outside an IT block), and |
| 1593 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
| 1594 | // encoding can be used. |
| 1595 | if (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1596 | !IsUint<8>(Low32Bits(value))) { |
| 1597 | return false; |
| 1598 | } |
| 1599 | } else if (c == kCondLE || c == kCondGT) { |
| 1600 | if (value < std::numeric_limits<int64_t>::max() && |
| 1601 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1602 | kNoRegister, |
| 1603 | SBC, |
| 1604 | High32Bits(value + 1), |
| 1605 | kCcSet, |
| 1606 | &so)) { |
| 1607 | return false; |
| 1608 | } |
| 1609 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1610 | kNoRegister, |
| 1611 | SBC, |
| 1612 | High32Bits(value), |
| 1613 | kCcSet, |
| 1614 | &so)) { |
| 1615 | return false; |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | return true; |
| 1622 | } |
| 1623 | |
| 1624 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1625 | const Primitive::Type type = constant->GetType(); |
| 1626 | bool ret = false; |
| 1627 | |
| 1628 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1629 | |
| 1630 | if (type == Primitive::kPrimLong) { |
| 1631 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 1632 | |
| 1633 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1634 | } else { |
| 1635 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 1636 | } |
| 1637 | |
| 1638 | return ret; |
| 1639 | } |
| 1640 | |
| 1641 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1642 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1643 | |
| 1644 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1645 | return Location::ConstantLocation(constant->AsConstant()); |
| 1646 | } |
| 1647 | |
| 1648 | return Location::RequiresRegister(); |
| 1649 | } |
| 1650 | |
| 1651 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1652 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1653 | // we check that we are not dealing with floating-point output (there is no |
| 1654 | // 16-bit VMOV encoding). |
| 1655 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1656 | return false; |
| 1657 | } |
| 1658 | |
| 1659 | // For constants, we also check that the output is in one or two low registers, |
| 1660 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1661 | // MOV encoding can be used. |
| 1662 | if (src.IsConstant()) { |
| 1663 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1664 | return false; |
| 1665 | } |
| 1666 | |
| 1667 | if (out.IsRegister()) { |
| 1668 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 1669 | return false; |
| 1670 | } |
| 1671 | } else { |
| 1672 | DCHECK(out.IsRegisterPair()); |
| 1673 | |
| 1674 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 1675 | return false; |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | return true; |
| 1681 | } |
| 1682 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1683 | #undef __ |
| 1684 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1685 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1686 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 1687 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 1688 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
| 1689 | |
| 1690 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1691 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1692 | HInstruction* const next = instruction->GetNext(); |
| 1693 | |
| 1694 | // Avoid a branch to a branch. |
| 1695 | if (next->IsGoto() && (info == nullptr || |
| 1696 | !info->IsBackEdge(*block) || |
| 1697 | !info->HasSuspendCheck())) { |
| 1698 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1699 | } |
| 1700 | |
| 1701 | return final_label; |
| 1702 | } |
| 1703 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1704 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1705 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1709 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1712 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1713 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1714 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1717 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1718 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1719 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1720 | } |
| 1721 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1722 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1723 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1724 | return kArmWordSize; |
| 1725 | } |
| 1726 | |
| 1727 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1728 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1729 | return kArmWordSize; |
| 1730 | } |
| 1731 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1732 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1733 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1734 | const CompilerOptions& compiler_options, |
| 1735 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1736 | : CodeGenerator(graph, |
| 1737 | kNumberOfCoreRegisters, |
| 1738 | kNumberOfSRegisters, |
| 1739 | kNumberOfRegisterPairs, |
| 1740 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1741 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1742 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1743 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1744 | compiler_options, |
| 1745 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1746 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1747 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1748 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1749 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1750 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1751 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1752 | uint32_literals_(std::less<uint32_t>(), |
| 1753 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1754 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1755 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1756 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1757 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1758 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1759 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1760 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1761 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1762 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1763 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1764 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1765 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1766 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1767 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1768 | // Always save the LR register to mimic Quick. |
| 1769 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1772 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1773 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1774 | __ FinalizeCode(); |
| 1775 | |
| 1776 | // Adjust native pc offsets in stack maps. |
| 1777 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1778 | uint32_t old_position = |
| 1779 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1780 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1781 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1782 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1783 | // Adjust pc offsets for the disassembly information. |
| 1784 | if (disasm_info_ != nullptr) { |
| 1785 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1786 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1787 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1788 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1789 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1790 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1791 | } |
| 1792 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1793 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1794 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1795 | } |
| 1796 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1797 | |
| 1798 | CodeGenerator::Finalize(allocator); |
| 1799 | } |
| 1800 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1801 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1802 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1803 | blocked_core_registers_[SP] = true; |
| 1804 | blocked_core_registers_[LR] = true; |
| 1805 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1806 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1807 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1808 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1809 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1810 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1811 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1812 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1813 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1814 | // Stubs do not save callee-save floating point registers. If the graph |
| 1815 | // is debuggable, we need to deal with these registers differently. For |
| 1816 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1817 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1818 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1819 | } |
| 1820 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1823 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1824 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1825 | assembler_(codegen->GetAssembler()), |
| 1826 | codegen_(codegen) {} |
| 1827 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1828 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1829 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1830 | 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] | 1831 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1832 | // restore another arbitrary register. |
| 1833 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1834 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1835 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1836 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1837 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1838 | // but in the range. |
| 1839 | if (fpu_spill_mask_ != 0) { |
| 1840 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1841 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1842 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1843 | fpu_spill_mask_ |= (1 << i); |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1848 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1849 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1853 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1854 | } |
| 1855 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1856 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1857 | bool skip_overflow_check = |
| 1858 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1859 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1860 | __ Bind(&frame_entry_label_); |
| 1861 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1862 | if (HasEmptyFrame()) { |
| 1863 | return; |
| 1864 | } |
| 1865 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1866 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1867 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1868 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1869 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1870 | } |
| 1871 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1872 | __ PushList(core_spill_mask_); |
| 1873 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1874 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1875 | if (fpu_spill_mask_ != 0) { |
| 1876 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1877 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1878 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1879 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1880 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1881 | |
| 1882 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1883 | // Initialize should_deoptimize flag to 0. |
| 1884 | __ mov(IP, ShifterOperand(0)); |
| 1885 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1886 | } |
| 1887 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1888 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1889 | __ AddConstant(SP, -adjust); |
| 1890 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1891 | |
| 1892 | // Save the current method if we need it. Note that we do not |
| 1893 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1894 | // in the SSA graph. |
| 1895 | if (RequiresCurrentMethod()) { |
| 1896 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1897 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1901 | if (HasEmptyFrame()) { |
| 1902 | __ bx(LR); |
| 1903 | return; |
| 1904 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1905 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1906 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1907 | __ AddConstant(SP, adjust); |
| 1908 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1909 | if (fpu_spill_mask_ != 0) { |
| 1910 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1911 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1912 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1913 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1914 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1915 | // Pop LR into PC to return. |
| 1916 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1917 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1918 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1919 | __ cfi().RestoreState(); |
| 1920 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1923 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1924 | Label* label = GetLabelOf(block); |
| 1925 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1928 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1929 | switch (type) { |
| 1930 | case Primitive::kPrimBoolean: |
| 1931 | case Primitive::kPrimByte: |
| 1932 | case Primitive::kPrimChar: |
| 1933 | case Primitive::kPrimShort: |
| 1934 | case Primitive::kPrimInt: |
| 1935 | case Primitive::kPrimNot: { |
| 1936 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1937 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1938 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1939 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1940 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1941 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1942 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1943 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1944 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1945 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1946 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1947 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1948 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1949 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1950 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1951 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1952 | // Skip R1, and use R2_R3 instead. |
| 1953 | gp_index_++; |
| 1954 | index++; |
| 1955 | } |
| 1956 | } |
| 1957 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1958 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1959 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1960 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1961 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1962 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1963 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1964 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | case Primitive::kPrimFloat: { |
| 1969 | uint32_t stack_index = stack_index_++; |
| 1970 | if (float_index_ % 2 == 0) { |
| 1971 | float_index_ = std::max(double_index_, float_index_); |
| 1972 | } |
| 1973 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1974 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1975 | } else { |
| 1976 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | case Primitive::kPrimDouble: { |
| 1981 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1982 | uint32_t stack_index = stack_index_; |
| 1983 | stack_index_ += 2; |
| 1984 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1985 | uint32_t index = double_index_; |
| 1986 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1987 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1988 | calling_convention.GetFpuRegisterAt(index), |
| 1989 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1990 | DCHECK(ExpectedPairLayout(result)); |
| 1991 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1992 | } else { |
| 1993 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1997 | case Primitive::kPrimVoid: |
| 1998 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1999 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2000 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2001 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2002 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2003 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2004 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2005 | switch (type) { |
| 2006 | case Primitive::kPrimBoolean: |
| 2007 | case Primitive::kPrimByte: |
| 2008 | case Primitive::kPrimChar: |
| 2009 | case Primitive::kPrimShort: |
| 2010 | case Primitive::kPrimInt: |
| 2011 | case Primitive::kPrimNot: { |
| 2012 | return Location::RegisterLocation(R0); |
| 2013 | } |
| 2014 | |
| 2015 | case Primitive::kPrimFloat: { |
| 2016 | return Location::FpuRegisterLocation(S0); |
| 2017 | } |
| 2018 | |
| 2019 | case Primitive::kPrimLong: { |
| 2020 | return Location::RegisterPairLocation(R0, R1); |
| 2021 | } |
| 2022 | |
| 2023 | case Primitive::kPrimDouble: { |
| 2024 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2025 | } |
| 2026 | |
| 2027 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2028 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2029 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2030 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2031 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2034 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2035 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2036 | } |
| 2037 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2038 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2039 | if (source.Equals(destination)) { |
| 2040 | return; |
| 2041 | } |
| 2042 | if (destination.IsRegister()) { |
| 2043 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2044 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2045 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2046 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2047 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2048 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2049 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2050 | } else if (destination.IsFpuRegister()) { |
| 2051 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2052 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2053 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2054 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2055 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2056 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2057 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2058 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2059 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2060 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2061 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2062 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2063 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2064 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2065 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2066 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2067 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2073 | if (source.Equals(destination)) { |
| 2074 | return; |
| 2075 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2076 | if (destination.IsRegisterPair()) { |
| 2077 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2078 | EmitParallelMoves( |
| 2079 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2080 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2081 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2082 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2083 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2084 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2085 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2086 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2087 | } else if (source.IsFpuRegisterPair()) { |
| 2088 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2089 | destination.AsRegisterPairHigh<Register>(), |
| 2090 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2091 | } else { |
| 2092 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2093 | DCHECK(ExpectedPairLayout(destination)); |
| 2094 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2095 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2096 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2097 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2098 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2099 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2100 | SP, |
| 2101 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2102 | } else if (source.IsRegisterPair()) { |
| 2103 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2104 | source.AsRegisterPairLow<Register>(), |
| 2105 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2106 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2107 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2108 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2109 | } else { |
| 2110 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2111 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2112 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2113 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2114 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2115 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2116 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2117 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2118 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2119 | SP, destination.GetStackIndex()); |
| 2120 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2121 | } else if (source.IsFpuRegisterPair()) { |
| 2122 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2123 | SP, |
| 2124 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2125 | } else { |
| 2126 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2127 | EmitParallelMoves( |
| 2128 | Location::StackSlot(source.GetStackIndex()), |
| 2129 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2130 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2131 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2132 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2133 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | } |
| 2137 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2138 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2139 | DCHECK(location.IsRegister()); |
| 2140 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2141 | } |
| 2142 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2143 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2144 | HParallelMove move(GetGraph()->GetArena()); |
| 2145 | move.AddMove(src, dst, dst_type, nullptr); |
| 2146 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2150 | if (location.IsRegister()) { |
| 2151 | locations->AddTemp(location); |
| 2152 | } else if (location.IsRegisterPair()) { |
| 2153 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2154 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2155 | } else { |
| 2156 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2157 | } |
| 2158 | } |
| 2159 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2160 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2161 | HInstruction* instruction, |
| 2162 | uint32_t dex_pc, |
| 2163 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2164 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2165 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2166 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2167 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2168 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2169 | } |
| 2170 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2171 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2172 | HInstruction* instruction, |
| 2173 | SlowPathCode* slow_path) { |
| 2174 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2175 | GenerateInvokeRuntime(entry_point_offset); |
| 2176 | } |
| 2177 | |
| 2178 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2179 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2180 | __ blx(LR); |
| 2181 | } |
| 2182 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2183 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2184 | DCHECK(!successor->IsExitBlock()); |
| 2185 | |
| 2186 | HBasicBlock* block = got->GetBlock(); |
| 2187 | HInstruction* previous = got->GetPrevious(); |
| 2188 | |
| 2189 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2190 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2191 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2192 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
| 2196 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2197 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2198 | } |
| 2199 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2200 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2201 | } |
| 2202 | } |
| 2203 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2204 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2205 | got->SetLocations(nullptr); |
| 2206 | } |
| 2207 | |
| 2208 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2209 | HandleGoto(got, got->GetSuccessor()); |
| 2210 | } |
| 2211 | |
| 2212 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2213 | try_boundary->SetLocations(nullptr); |
| 2214 | } |
| 2215 | |
| 2216 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2217 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2218 | if (!successor->IsExitBlock()) { |
| 2219 | HandleGoto(try_boundary, successor); |
| 2220 | } |
| 2221 | } |
| 2222 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2223 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2224 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2227 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2230 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 2231 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2232 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2233 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2234 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 2238 | Label* true_label, |
| 2239 | Label* false_label) { |
| 2240 | LocationSummary* locations = cond->GetLocations(); |
| 2241 | Location left = locations->InAt(0); |
| 2242 | Location right = locations->InAt(1); |
| 2243 | IfCondition if_cond = cond->GetCondition(); |
| 2244 | |
| 2245 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2246 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2247 | IfCondition true_high_cond = if_cond; |
| 2248 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2249 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2250 | |
| 2251 | // Set the conditions for the test, remembering that == needs to be |
| 2252 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2253 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2254 | switch (if_cond) { |
| 2255 | case kCondEQ: |
| 2256 | case kCondNE: |
| 2257 | // Nothing to do. |
| 2258 | break; |
| 2259 | case kCondLT: |
| 2260 | false_high_cond = kCondGT; |
| 2261 | break; |
| 2262 | case kCondLE: |
| 2263 | true_high_cond = kCondLT; |
| 2264 | break; |
| 2265 | case kCondGT: |
| 2266 | false_high_cond = kCondLT; |
| 2267 | break; |
| 2268 | case kCondGE: |
| 2269 | true_high_cond = kCondGT; |
| 2270 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2271 | case kCondB: |
| 2272 | false_high_cond = kCondA; |
| 2273 | break; |
| 2274 | case kCondBE: |
| 2275 | true_high_cond = kCondB; |
| 2276 | break; |
| 2277 | case kCondA: |
| 2278 | false_high_cond = kCondB; |
| 2279 | break; |
| 2280 | case kCondAE: |
| 2281 | true_high_cond = kCondA; |
| 2282 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2283 | } |
| 2284 | if (right.IsConstant()) { |
| 2285 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2286 | int32_t val_low = Low32Bits(value); |
| 2287 | int32_t val_high = High32Bits(value); |
| 2288 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2289 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2290 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2291 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2292 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2293 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2294 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2295 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2296 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2297 | } |
| 2298 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2299 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2300 | } else { |
| 2301 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2302 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2303 | |
| 2304 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2305 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2306 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2307 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2308 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2309 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2310 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2311 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2312 | } |
| 2313 | // Must be equal high, so compare the lows. |
| 2314 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2315 | } |
| 2316 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2317 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2318 | __ b(true_label, final_condition); |
| 2319 | } |
| 2320 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2321 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2322 | Label* true_target_in, |
| 2323 | Label* false_target_in) { |
| 2324 | // Generated branching requires both targets to be explicit. If either of the |
| 2325 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2326 | Label fallthrough_target; |
| 2327 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2328 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2329 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2330 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2331 | switch (type) { |
| 2332 | case Primitive::kPrimLong: |
| 2333 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 2334 | break; |
| 2335 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2336 | case Primitive::kPrimDouble: |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2337 | GenerateVcmp(condition, codegen_); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2338 | GenerateFPJumps(condition, true_target, false_target); |
| 2339 | break; |
| 2340 | default: |
| 2341 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2342 | } |
| 2343 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2344 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2345 | __ b(false_target); |
| 2346 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2347 | |
| 2348 | if (fallthrough_target.IsLinked()) { |
| 2349 | __ Bind(&fallthrough_target); |
| 2350 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2353 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2354 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2355 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2356 | Label* false_target) { |
| 2357 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2358 | |
| 2359 | if (true_target == nullptr && false_target == nullptr) { |
| 2360 | // Nothing to do. The code always falls through. |
| 2361 | return; |
| 2362 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2363 | // Constant condition, statically compared against "true" (integer value 1). |
| 2364 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2365 | if (true_target != nullptr) { |
| 2366 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2367 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2368 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2369 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2370 | if (false_target != nullptr) { |
| 2371 | __ b(false_target); |
| 2372 | } |
| 2373 | } |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | // The following code generates these patterns: |
| 2378 | // (1) true_target == nullptr && false_target != nullptr |
| 2379 | // - opposite condition true => branch to false_target |
| 2380 | // (2) true_target != nullptr && false_target == nullptr |
| 2381 | // - condition true => branch to true_target |
| 2382 | // (3) true_target != nullptr && false_target != nullptr |
| 2383 | // - condition true => branch to true_target |
| 2384 | // - branch to false_target |
| 2385 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2386 | // Condition has been materialized, compare the output to 0. |
| 2387 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2388 | DCHECK(cond_val.IsRegister()); |
| 2389 | if (true_target == nullptr) { |
| 2390 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2391 | } else { |
| 2392 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2393 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2394 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2395 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2396 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2397 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2398 | |
| 2399 | // If this is a long or FP comparison that has been folded into |
| 2400 | // the HCondition, generate the comparison directly. |
| 2401 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2402 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2403 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2404 | return; |
| 2405 | } |
| 2406 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2407 | Label* non_fallthrough_target; |
| 2408 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2409 | LocationSummary* locations = cond->GetLocations(); |
| 2410 | DCHECK(locations->InAt(0).IsRegister()); |
| 2411 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2412 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2413 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2414 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2415 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2416 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2417 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2418 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2419 | non_fallthrough_target = true_target; |
| 2420 | } |
| 2421 | |
| 2422 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2423 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2424 | if (arm_cond == EQ) { |
| 2425 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2426 | } else { |
| 2427 | DCHECK_EQ(arm_cond, NE); |
| 2428 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2429 | } |
| 2430 | } else { |
| 2431 | if (right.IsRegister()) { |
| 2432 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2433 | } else { |
| 2434 | DCHECK(right.IsConstant()); |
| 2435 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2436 | } |
| 2437 | |
| 2438 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2439 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2440 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2441 | |
| 2442 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2443 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2444 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2445 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2449 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2450 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2451 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2452 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2457 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2458 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2459 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2460 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2461 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2462 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2463 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2467 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2468 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2469 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2470 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2471 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2476 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2477 | GenerateTestAndBranch(deoptimize, |
| 2478 | /* condition_input_index */ 0, |
| 2479 | slow_path->GetEntryLabel(), |
| 2480 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2481 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2482 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2483 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2484 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2485 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2486 | locations->SetOut(Location::RequiresRegister()); |
| 2487 | } |
| 2488 | |
| 2489 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2490 | __ LoadFromOffset(kLoadWord, |
| 2491 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2492 | SP, |
| 2493 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2494 | } |
| 2495 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2496 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2497 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2498 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2499 | |
| 2500 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2501 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2502 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2503 | } else { |
| 2504 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2505 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2506 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2507 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2508 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2509 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2510 | // The code generator handles overlap with the values, but not with the condition. |
| 2511 | locations->SetOut(Location::SameAsFirstInput()); |
| 2512 | } else if (is_floating_point) { |
| 2513 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2514 | } else { |
| 2515 | if (!locations->InAt(1).IsConstant()) { |
| 2516 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2517 | } |
| 2518 | |
| 2519 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2520 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2524 | HInstruction* const condition = select->GetCondition(); |
| 2525 | const LocationSummary* const locations = select->GetLocations(); |
| 2526 | const Primitive::Type type = select->GetType(); |
| 2527 | const Location first = locations->InAt(0); |
| 2528 | const Location out = locations->Out(); |
| 2529 | const Location second = locations->InAt(1); |
| 2530 | Location src; |
| 2531 | |
| 2532 | if (condition->IsIntConstant()) { |
| 2533 | if (condition->AsIntConstant()->IsFalse()) { |
| 2534 | src = first; |
| 2535 | } else { |
| 2536 | src = second; |
| 2537 | } |
| 2538 | |
| 2539 | codegen_->MoveLocation(out, src, type); |
| 2540 | return; |
| 2541 | } |
| 2542 | |
| 2543 | if (!Primitive::IsFloatingPointType(type) && |
| 2544 | CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2545 | bool invert = false; |
| 2546 | |
| 2547 | if (out.Equals(second)) { |
| 2548 | src = first; |
| 2549 | invert = true; |
| 2550 | } else if (out.Equals(first)) { |
| 2551 | src = second; |
| 2552 | } else if (second.IsConstant()) { |
| 2553 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2554 | src = second; |
| 2555 | } else if (first.IsConstant()) { |
| 2556 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2557 | src = first; |
| 2558 | invert = true; |
| 2559 | } else { |
| 2560 | src = second; |
| 2561 | } |
| 2562 | |
| 2563 | if (CanGenerateConditionalMove(out, src)) { |
| 2564 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2565 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2566 | } |
| 2567 | |
| 2568 | const Condition cond = GenerateTest(condition, locations->InAt(2), invert, codegen_); |
| 2569 | |
| 2570 | if (out.IsRegister()) { |
| 2571 | ShifterOperand operand; |
| 2572 | |
| 2573 | if (src.IsConstant()) { |
| 2574 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 2575 | } else { |
| 2576 | DCHECK(src.IsRegister()); |
| 2577 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 2578 | } |
| 2579 | |
| 2580 | __ it(cond); |
| 2581 | __ mov(out.AsRegister<Register>(), operand, cond); |
| 2582 | } else { |
| 2583 | DCHECK(out.IsRegisterPair()); |
| 2584 | |
| 2585 | ShifterOperand operand_high; |
| 2586 | ShifterOperand operand_low; |
| 2587 | |
| 2588 | if (src.IsConstant()) { |
| 2589 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 2590 | |
| 2591 | operand_high = ShifterOperand(High32Bits(value)); |
| 2592 | operand_low = ShifterOperand(Low32Bits(value)); |
| 2593 | } else { |
| 2594 | DCHECK(src.IsRegisterPair()); |
| 2595 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 2596 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 2597 | } |
| 2598 | |
| 2599 | __ it(cond); |
| 2600 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond); |
| 2601 | __ it(cond); |
| 2602 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond); |
| 2603 | } |
| 2604 | |
| 2605 | return; |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | Label* false_target = nullptr; |
| 2610 | Label* true_target = nullptr; |
| 2611 | Label select_end; |
| 2612 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 2613 | |
| 2614 | if (out.Equals(second)) { |
| 2615 | true_target = target; |
| 2616 | src = first; |
| 2617 | } else { |
| 2618 | false_target = target; |
| 2619 | src = second; |
| 2620 | |
| 2621 | if (!out.Equals(first)) { |
| 2622 | codegen_->MoveLocation(out, first, type); |
| 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 2627 | codegen_->MoveLocation(out, src, type); |
| 2628 | |
| 2629 | if (select_end.IsLinked()) { |
| 2630 | __ Bind(&select_end); |
| 2631 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2634 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2635 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2636 | } |
| 2637 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2638 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2639 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | void CodeGeneratorARM::GenerateNop() { |
| 2643 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2646 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2647 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2648 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2649 | // Handle the long/FP comparisons made in instruction simplification. |
| 2650 | switch (cond->InputAt(0)->GetType()) { |
| 2651 | case Primitive::kPrimLong: |
| 2652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2653 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2654 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2655 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2656 | } |
| 2657 | break; |
| 2658 | |
| 2659 | case Primitive::kPrimFloat: |
| 2660 | case Primitive::kPrimDouble: |
| 2661 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2662 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2663 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2664 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2665 | } |
| 2666 | break; |
| 2667 | |
| 2668 | default: |
| 2669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2670 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2671 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2672 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2673 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2674 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2677 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2678 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2679 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2680 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2681 | |
| 2682 | LocationSummary* locations = cond->GetLocations(); |
| 2683 | Location left = locations->InAt(0); |
| 2684 | Location right = locations->InAt(1); |
| 2685 | Register out = locations->Out().AsRegister<Register>(); |
| 2686 | Label true_label, false_label; |
| 2687 | |
| 2688 | switch (cond->InputAt(0)->GetType()) { |
| 2689 | default: { |
| 2690 | // Integer case. |
| 2691 | if (right.IsRegister()) { |
| 2692 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2693 | } else { |
| 2694 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2695 | __ CmpConstant(left.AsRegister<Register>(), |
| 2696 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2697 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2698 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2699 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2700 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2701 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2702 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2703 | return; |
| 2704 | } |
| 2705 | case Primitive::kPrimLong: |
| 2706 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2707 | break; |
| 2708 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2709 | case Primitive::kPrimDouble: |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 2710 | GenerateVcmp(cond, codegen_); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2711 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2712 | break; |
| 2713 | } |
| 2714 | |
| 2715 | // Convert the jumps into the result. |
| 2716 | Label done_label; |
| 2717 | |
| 2718 | // False case: result = 0. |
| 2719 | __ Bind(&false_label); |
| 2720 | __ LoadImmediate(out, 0); |
| 2721 | __ b(&done_label); |
| 2722 | |
| 2723 | // True case: result = 1. |
| 2724 | __ Bind(&true_label); |
| 2725 | __ LoadImmediate(out, 1); |
| 2726 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2730 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2734 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2738 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2742 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2746 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2750 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2754 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2762 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2774 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2777 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2778 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2782 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2786 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2790 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2794 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2798 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2802 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2806 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2809 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2810 | LocationSummary* locations = |
| 2811 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2812 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2815 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2816 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2819 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2820 | LocationSummary* locations = |
| 2821 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2822 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2823 | } |
| 2824 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2825 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2826 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2829 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2830 | LocationSummary* locations = |
| 2831 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2832 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2833 | } |
| 2834 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2835 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2836 | // Will be generated at use site. |
| 2837 | } |
| 2838 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2839 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2840 | LocationSummary* locations = |
| 2841 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2842 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2843 | } |
| 2844 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2845 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2846 | // Will be generated at use site. |
| 2847 | } |
| 2848 | |
| 2849 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2850 | LocationSummary* locations = |
| 2851 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2852 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2853 | } |
| 2854 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2855 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2856 | // Will be generated at use site. |
| 2857 | } |
| 2858 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2859 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2860 | memory_barrier->SetLocations(nullptr); |
| 2861 | } |
| 2862 | |
| 2863 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2864 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2865 | } |
| 2866 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2867 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2868 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2871 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2872 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2875 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2876 | LocationSummary* locations = |
| 2877 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2878 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2881 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2882 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2885 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2886 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2887 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2888 | // the method_idx. |
| 2889 | HandleInvoke(invoke); |
| 2890 | } |
| 2891 | |
| 2892 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2893 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2894 | } |
| 2895 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2896 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2897 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2898 | // art::PrepareForRegisterAllocation. |
| 2899 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2900 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2901 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2902 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2903 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2904 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2905 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2906 | return; |
| 2907 | } |
| 2908 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2909 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2910 | |
| 2911 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2912 | if (invoke->HasPcRelativeDexCache()) { |
| 2913 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2914 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2915 | } |
| 2916 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2917 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2918 | if (invoke->GetLocations()->Intrinsified()) { |
| 2919 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2920 | intrinsic.Dispatch(invoke); |
| 2921 | return true; |
| 2922 | } |
| 2923 | return false; |
| 2924 | } |
| 2925 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2926 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2927 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2928 | // art::PrepareForRegisterAllocation. |
| 2929 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2930 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2931 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2932 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2933 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2934 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2935 | LocationSummary* locations = invoke->GetLocations(); |
| 2936 | codegen_->GenerateStaticOrDirectCall( |
| 2937 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2938 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2941 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2942 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2943 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2944 | } |
| 2945 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2946 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2947 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2948 | if (intrinsic.TryDispatch(invoke)) { |
| 2949 | return; |
| 2950 | } |
| 2951 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2952 | HandleInvoke(invoke); |
| 2953 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2954 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2955 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2956 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2957 | return; |
| 2958 | } |
| 2959 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2960 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2961 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2962 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2965 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2966 | HandleInvoke(invoke); |
| 2967 | // Add the hidden argument. |
| 2968 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2969 | } |
| 2970 | |
| 2971 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2972 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2973 | LocationSummary* locations = invoke->GetLocations(); |
| 2974 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2975 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2976 | Location receiver = locations->InAt(0); |
| 2977 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2978 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2979 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2980 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2981 | DCHECK_EQ(R12, hidden_reg); |
| 2982 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2983 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2984 | if (receiver.IsStackSlot()) { |
| 2985 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2986 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2987 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2988 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2989 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2990 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2991 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2992 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2993 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2994 | // emit a read barrier for the previous class reference load. |
| 2995 | // However this is not required in practice, as this is an |
| 2996 | // intermediate/temporary reference and because the current |
| 2997 | // concurrent copying collector keeps the from-space memory |
| 2998 | // intact/accessible until the end of the marking phase (the |
| 2999 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3000 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3001 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3002 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3003 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3004 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3005 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3006 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3007 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3008 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3009 | // LR = temp->GetEntryPoint(); |
| 3010 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3011 | // LR(); |
| 3012 | __ blx(LR); |
| 3013 | DCHECK(!codegen_->IsLeafMethod()); |
| 3014 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3015 | } |
| 3016 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3017 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3018 | HandleInvoke(invoke); |
| 3019 | } |
| 3020 | |
| 3021 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3022 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3023 | } |
| 3024 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3025 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3026 | LocationSummary* locations = |
| 3027 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3028 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3029 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3030 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3032 | break; |
| 3033 | } |
| 3034 | case Primitive::kPrimLong: { |
| 3035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3036 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3037 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3038 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3039 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3040 | case Primitive::kPrimFloat: |
| 3041 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3042 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3043 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3044 | break; |
| 3045 | |
| 3046 | default: |
| 3047 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3052 | LocationSummary* locations = neg->GetLocations(); |
| 3053 | Location out = locations->Out(); |
| 3054 | Location in = locations->InAt(0); |
| 3055 | switch (neg->GetResultType()) { |
| 3056 | case Primitive::kPrimInt: |
| 3057 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3058 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3059 | break; |
| 3060 | |
| 3061 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3062 | DCHECK(in.IsRegisterPair()); |
| 3063 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3064 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3065 | in.AsRegisterPairLow<Register>(), |
| 3066 | ShifterOperand(0)); |
| 3067 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3068 | // instruction here, as it does not exist in the Thumb-2 |
| 3069 | // instruction set. We use the following approach |
| 3070 | // using SBC and SUB instead. |
| 3071 | // |
| 3072 | // out.hi = -C |
| 3073 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3074 | out.AsRegisterPairHigh<Register>(), |
| 3075 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3076 | // out.hi = out.hi - in.hi |
| 3077 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3078 | out.AsRegisterPairHigh<Register>(), |
| 3079 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3080 | break; |
| 3081 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3082 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3083 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3084 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3087 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3088 | DCHECK(in.IsFpuRegisterPair()); |
| 3089 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3090 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3091 | break; |
| 3092 | |
| 3093 | default: |
| 3094 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3095 | } |
| 3096 | } |
| 3097 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3098 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3099 | Primitive::Type result_type = conversion->GetResultType(); |
| 3100 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3101 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3102 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3103 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3104 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3105 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3106 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3107 | && result_type == Primitive::kPrimLong) |
| 3108 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3109 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3110 | : LocationSummary::kNoCall; |
| 3111 | LocationSummary* locations = |
| 3112 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3113 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3114 | // The Java language does not allow treating boolean as an integral type but |
| 3115 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3116 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3117 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3118 | case Primitive::kPrimByte: |
| 3119 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3120 | case Primitive::kPrimLong: |
| 3121 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3122 | case Primitive::kPrimBoolean: |
| 3123 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3124 | case Primitive::kPrimShort: |
| 3125 | case Primitive::kPrimInt: |
| 3126 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3127 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3128 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3129 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3130 | break; |
| 3131 | |
| 3132 | default: |
| 3133 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3134 | << " to " << result_type; |
| 3135 | } |
| 3136 | break; |
| 3137 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3138 | case Primitive::kPrimShort: |
| 3139 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3140 | case Primitive::kPrimLong: |
| 3141 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3142 | case Primitive::kPrimBoolean: |
| 3143 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3144 | case Primitive::kPrimByte: |
| 3145 | case Primitive::kPrimInt: |
| 3146 | case Primitive::kPrimChar: |
| 3147 | // Processing a Dex `int-to-short' instruction. |
| 3148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3150 | break; |
| 3151 | |
| 3152 | default: |
| 3153 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3154 | << " to " << result_type; |
| 3155 | } |
| 3156 | break; |
| 3157 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3158 | case Primitive::kPrimInt: |
| 3159 | switch (input_type) { |
| 3160 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3161 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3162 | locations->SetInAt(0, Location::Any()); |
| 3163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3164 | break; |
| 3165 | |
| 3166 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3167 | // Processing a Dex `float-to-int' instruction. |
| 3168 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3169 | locations->SetOut(Location::RequiresRegister()); |
| 3170 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3171 | break; |
| 3172 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3173 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3174 | // Processing a Dex `double-to-int' instruction. |
| 3175 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3176 | locations->SetOut(Location::RequiresRegister()); |
| 3177 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3178 | break; |
| 3179 | |
| 3180 | default: |
| 3181 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3182 | << " to " << result_type; |
| 3183 | } |
| 3184 | break; |
| 3185 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3186 | case Primitive::kPrimLong: |
| 3187 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3188 | case Primitive::kPrimBoolean: |
| 3189 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3190 | case Primitive::kPrimByte: |
| 3191 | case Primitive::kPrimShort: |
| 3192 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3193 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3194 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3196 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3197 | break; |
| 3198 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3199 | case Primitive::kPrimFloat: { |
| 3200 | // Processing a Dex `float-to-long' instruction. |
| 3201 | InvokeRuntimeCallingConvention calling_convention; |
| 3202 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3203 | calling_convention.GetFpuRegisterAt(0))); |
| 3204 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3205 | break; |
| 3206 | } |
| 3207 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3208 | case Primitive::kPrimDouble: { |
| 3209 | // Processing a Dex `double-to-long' instruction. |
| 3210 | InvokeRuntimeCallingConvention calling_convention; |
| 3211 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3212 | calling_convention.GetFpuRegisterAt(0), |
| 3213 | calling_convention.GetFpuRegisterAt(1))); |
| 3214 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3215 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3216 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3217 | |
| 3218 | default: |
| 3219 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3220 | << " to " << result_type; |
| 3221 | } |
| 3222 | break; |
| 3223 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3224 | case Primitive::kPrimChar: |
| 3225 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3226 | case Primitive::kPrimLong: |
| 3227 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3228 | case Primitive::kPrimBoolean: |
| 3229 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3230 | case Primitive::kPrimByte: |
| 3231 | case Primitive::kPrimShort: |
| 3232 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3233 | // Processing a Dex `int-to-char' instruction. |
| 3234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3235 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3236 | break; |
| 3237 | |
| 3238 | default: |
| 3239 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3240 | << " to " << result_type; |
| 3241 | } |
| 3242 | break; |
| 3243 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3244 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3245 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3246 | case Primitive::kPrimBoolean: |
| 3247 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3248 | case Primitive::kPrimByte: |
| 3249 | case Primitive::kPrimShort: |
| 3250 | case Primitive::kPrimInt: |
| 3251 | case Primitive::kPrimChar: |
| 3252 | // Processing a Dex `int-to-float' instruction. |
| 3253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3254 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3255 | break; |
| 3256 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3257 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3258 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3259 | InvokeRuntimeCallingConvention calling_convention; |
| 3260 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3261 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3262 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3263 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3264 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3265 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3266 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3267 | // Processing a Dex `double-to-float' instruction. |
| 3268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3269 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3270 | break; |
| 3271 | |
| 3272 | default: |
| 3273 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3274 | << " to " << result_type; |
| 3275 | }; |
| 3276 | break; |
| 3277 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3278 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3279 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3280 | case Primitive::kPrimBoolean: |
| 3281 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3282 | case Primitive::kPrimByte: |
| 3283 | case Primitive::kPrimShort: |
| 3284 | case Primitive::kPrimInt: |
| 3285 | case Primitive::kPrimChar: |
| 3286 | // Processing a Dex `int-to-double' instruction. |
| 3287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3288 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3289 | break; |
| 3290 | |
| 3291 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3292 | // Processing a Dex `long-to-double' instruction. |
| 3293 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3294 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3295 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3296 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3297 | break; |
| 3298 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3299 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3300 | // Processing a Dex `float-to-double' instruction. |
| 3301 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3302 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3303 | break; |
| 3304 | |
| 3305 | default: |
| 3306 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3307 | << " to " << result_type; |
| 3308 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3309 | break; |
| 3310 | |
| 3311 | default: |
| 3312 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3313 | << " to " << result_type; |
| 3314 | } |
| 3315 | } |
| 3316 | |
| 3317 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3318 | LocationSummary* locations = conversion->GetLocations(); |
| 3319 | Location out = locations->Out(); |
| 3320 | Location in = locations->InAt(0); |
| 3321 | Primitive::Type result_type = conversion->GetResultType(); |
| 3322 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3323 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3324 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3325 | case Primitive::kPrimByte: |
| 3326 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3327 | case Primitive::kPrimLong: |
| 3328 | // Type conversion from long to byte is a result of code transformations. |
| 3329 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3330 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3331 | case Primitive::kPrimBoolean: |
| 3332 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3333 | case Primitive::kPrimShort: |
| 3334 | case Primitive::kPrimInt: |
| 3335 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3336 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3337 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | |
| 3340 | default: |
| 3341 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3342 | << " to " << result_type; |
| 3343 | } |
| 3344 | break; |
| 3345 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3346 | case Primitive::kPrimShort: |
| 3347 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3348 | case Primitive::kPrimLong: |
| 3349 | // Type conversion from long to short is a result of code transformations. |
| 3350 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3351 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3352 | case Primitive::kPrimBoolean: |
| 3353 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3354 | case Primitive::kPrimByte: |
| 3355 | case Primitive::kPrimInt: |
| 3356 | case Primitive::kPrimChar: |
| 3357 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3358 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3359 | break; |
| 3360 | |
| 3361 | default: |
| 3362 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3363 | << " to " << result_type; |
| 3364 | } |
| 3365 | break; |
| 3366 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3367 | case Primitive::kPrimInt: |
| 3368 | switch (input_type) { |
| 3369 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3370 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3371 | DCHECK(out.IsRegister()); |
| 3372 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3373 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3374 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3375 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3376 | } else { |
| 3377 | DCHECK(in.IsConstant()); |
| 3378 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3379 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3380 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3381 | } |
| 3382 | break; |
| 3383 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3384 | case Primitive::kPrimFloat: { |
| 3385 | // Processing a Dex `float-to-int' instruction. |
| 3386 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3387 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3388 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 3389 | break; |
| 3390 | } |
| 3391 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3392 | case Primitive::kPrimDouble: { |
| 3393 | // Processing a Dex `double-to-int' instruction. |
| 3394 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3395 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3396 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3397 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3398 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3399 | |
| 3400 | default: |
| 3401 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3402 | << " to " << result_type; |
| 3403 | } |
| 3404 | break; |
| 3405 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3406 | case Primitive::kPrimLong: |
| 3407 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3408 | case Primitive::kPrimBoolean: |
| 3409 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3410 | case Primitive::kPrimByte: |
| 3411 | case Primitive::kPrimShort: |
| 3412 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3413 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3414 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3415 | DCHECK(out.IsRegisterPair()); |
| 3416 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3417 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3418 | // Sign extension. |
| 3419 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3420 | out.AsRegisterPairLow<Register>(), |
| 3421 | 31); |
| 3422 | break; |
| 3423 | |
| 3424 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3425 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3426 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3427 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3428 | break; |
| 3429 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3430 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3431 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3432 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3433 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3434 | break; |
| 3435 | |
| 3436 | default: |
| 3437 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3438 | << " to " << result_type; |
| 3439 | } |
| 3440 | break; |
| 3441 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3442 | case Primitive::kPrimChar: |
| 3443 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3444 | case Primitive::kPrimLong: |
| 3445 | // Type conversion from long to char is a result of code transformations. |
| 3446 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3447 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3448 | case Primitive::kPrimBoolean: |
| 3449 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3450 | case Primitive::kPrimByte: |
| 3451 | case Primitive::kPrimShort: |
| 3452 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3453 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3454 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3455 | break; |
| 3456 | |
| 3457 | default: |
| 3458 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3459 | << " to " << result_type; |
| 3460 | } |
| 3461 | break; |
| 3462 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3463 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3464 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3465 | case Primitive::kPrimBoolean: |
| 3466 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3467 | case Primitive::kPrimByte: |
| 3468 | case Primitive::kPrimShort: |
| 3469 | case Primitive::kPrimInt: |
| 3470 | case Primitive::kPrimChar: { |
| 3471 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3472 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3473 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3474 | break; |
| 3475 | } |
| 3476 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3477 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3478 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3479 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3480 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3481 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3482 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3483 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3484 | // Processing a Dex `double-to-float' instruction. |
| 3485 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3486 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3487 | break; |
| 3488 | |
| 3489 | default: |
| 3490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3491 | << " to " << result_type; |
| 3492 | }; |
| 3493 | break; |
| 3494 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3495 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3496 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3497 | case Primitive::kPrimBoolean: |
| 3498 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3499 | case Primitive::kPrimByte: |
| 3500 | case Primitive::kPrimShort: |
| 3501 | case Primitive::kPrimInt: |
| 3502 | case Primitive::kPrimChar: { |
| 3503 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3504 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3505 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3506 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3507 | break; |
| 3508 | } |
| 3509 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3510 | case Primitive::kPrimLong: { |
| 3511 | // Processing a Dex `long-to-double' instruction. |
| 3512 | Register low = in.AsRegisterPairLow<Register>(); |
| 3513 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3514 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3515 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3516 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3517 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3518 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3519 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3520 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3521 | // temp_d = int-to-double(high) |
| 3522 | __ vmovsr(temp_s, high); |
| 3523 | __ vcvtdi(temp_d, temp_s); |
| 3524 | // constant_d = k2Pow32EncodingForDouble |
| 3525 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3526 | // out_d = unsigned-to-double(low) |
| 3527 | __ vmovsr(out_s, low); |
| 3528 | __ vcvtdu(out_d, out_s); |
| 3529 | // out_d += temp_d * constant_d |
| 3530 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| 3533 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3534 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3535 | // Processing a Dex `float-to-double' instruction. |
| 3536 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3537 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3538 | break; |
| 3539 | |
| 3540 | default: |
| 3541 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3542 | << " to " << result_type; |
| 3543 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3544 | break; |
| 3545 | |
| 3546 | default: |
| 3547 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3548 | << " to " << result_type; |
| 3549 | } |
| 3550 | } |
| 3551 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3552 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3553 | LocationSummary* locations = |
| 3554 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3555 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3556 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3558 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3559 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3560 | break; |
| 3561 | } |
| 3562 | |
| 3563 | case Primitive::kPrimLong: { |
| 3564 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3565 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3566 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3567 | break; |
| 3568 | } |
| 3569 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3570 | case Primitive::kPrimFloat: |
| 3571 | case Primitive::kPrimDouble: { |
| 3572 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3573 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3574 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3575 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3576 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3577 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3578 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3579 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3580 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3584 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3585 | Location out = locations->Out(); |
| 3586 | Location first = locations->InAt(0); |
| 3587 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3588 | switch (add->GetResultType()) { |
| 3589 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3590 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3591 | __ add(out.AsRegister<Register>(), |
| 3592 | first.AsRegister<Register>(), |
| 3593 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3594 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3595 | __ AddConstant(out.AsRegister<Register>(), |
| 3596 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3597 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3598 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3599 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3600 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3601 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3602 | if (second.IsConstant()) { |
| 3603 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3604 | GenerateAddLongConst(out, first, value); |
| 3605 | } else { |
| 3606 | DCHECK(second.IsRegisterPair()); |
| 3607 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3608 | first.AsRegisterPairLow<Register>(), |
| 3609 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3610 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3611 | first.AsRegisterPairHigh<Register>(), |
| 3612 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3613 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3614 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3615 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3616 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3617 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3618 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3619 | first.AsFpuRegister<SRegister>(), |
| 3620 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3621 | break; |
| 3622 | |
| 3623 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3624 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3625 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3626 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3627 | break; |
| 3628 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3629 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3630 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3634 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3635 | LocationSummary* locations = |
| 3636 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3637 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3638 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3639 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3640 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3641 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3642 | break; |
| 3643 | } |
| 3644 | |
| 3645 | case Primitive::kPrimLong: { |
| 3646 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3647 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3648 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3649 | break; |
| 3650 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3651 | case Primitive::kPrimFloat: |
| 3652 | case Primitive::kPrimDouble: { |
| 3653 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3654 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3655 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3656 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3657 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3658 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3659 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3660 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3664 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3665 | Location out = locations->Out(); |
| 3666 | Location first = locations->InAt(0); |
| 3667 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3668 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3669 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3670 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3671 | __ sub(out.AsRegister<Register>(), |
| 3672 | first.AsRegister<Register>(), |
| 3673 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3674 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3675 | __ AddConstant(out.AsRegister<Register>(), |
| 3676 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3677 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3678 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3679 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3680 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3681 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3682 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3683 | if (second.IsConstant()) { |
| 3684 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3685 | GenerateAddLongConst(out, first, -value); |
| 3686 | } else { |
| 3687 | DCHECK(second.IsRegisterPair()); |
| 3688 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3689 | first.AsRegisterPairLow<Register>(), |
| 3690 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3691 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3692 | first.AsRegisterPairHigh<Register>(), |
| 3693 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3694 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3695 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3696 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3697 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3698 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3699 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3700 | first.AsFpuRegister<SRegister>(), |
| 3701 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3702 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3706 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3707 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3708 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3709 | break; |
| 3710 | } |
| 3711 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3712 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3713 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3714 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3718 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3719 | LocationSummary* locations = |
| 3720 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3721 | switch (mul->GetResultType()) { |
| 3722 | case Primitive::kPrimInt: |
| 3723 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3724 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3725 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3726 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3727 | break; |
| 3728 | } |
| 3729 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3730 | case Primitive::kPrimFloat: |
| 3731 | case Primitive::kPrimDouble: { |
| 3732 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3733 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3734 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3735 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3736 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3737 | |
| 3738 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3739 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3744 | LocationSummary* locations = mul->GetLocations(); |
| 3745 | Location out = locations->Out(); |
| 3746 | Location first = locations->InAt(0); |
| 3747 | Location second = locations->InAt(1); |
| 3748 | switch (mul->GetResultType()) { |
| 3749 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3750 | __ mul(out.AsRegister<Register>(), |
| 3751 | first.AsRegister<Register>(), |
| 3752 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | case Primitive::kPrimLong: { |
| 3756 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3757 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3758 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3759 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3760 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3761 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3762 | |
| 3763 | // Extra checks to protect caused by the existence of R1_R2. |
| 3764 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3765 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3766 | DCHECK_NE(out_hi, in1_lo); |
| 3767 | DCHECK_NE(out_hi, in2_lo); |
| 3768 | |
| 3769 | // input: in1 - 64 bits, in2 - 64 bits |
| 3770 | // output: out |
| 3771 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3772 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3773 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3774 | |
| 3775 | // IP <- in1.lo * in2.hi |
| 3776 | __ mul(IP, in1_lo, in2_hi); |
| 3777 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3778 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3779 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3780 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3781 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3782 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3783 | break; |
| 3784 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3785 | |
| 3786 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3787 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3788 | first.AsFpuRegister<SRegister>(), |
| 3789 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3790 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3794 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3795 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3796 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3797 | break; |
| 3798 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3799 | |
| 3800 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3801 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3805 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3806 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3807 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3808 | |
| 3809 | LocationSummary* locations = instruction->GetLocations(); |
| 3810 | Location second = locations->InAt(1); |
| 3811 | DCHECK(second.IsConstant()); |
| 3812 | |
| 3813 | Register out = locations->Out().AsRegister<Register>(); |
| 3814 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3815 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3816 | DCHECK(imm == 1 || imm == -1); |
| 3817 | |
| 3818 | if (instruction->IsRem()) { |
| 3819 | __ LoadImmediate(out, 0); |
| 3820 | } else { |
| 3821 | if (imm == 1) { |
| 3822 | __ Mov(out, dividend); |
| 3823 | } else { |
| 3824 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3825 | } |
| 3826 | } |
| 3827 | } |
| 3828 | |
| 3829 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3830 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3831 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3832 | |
| 3833 | LocationSummary* locations = instruction->GetLocations(); |
| 3834 | Location second = locations->InAt(1); |
| 3835 | DCHECK(second.IsConstant()); |
| 3836 | |
| 3837 | Register out = locations->Out().AsRegister<Register>(); |
| 3838 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3839 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3840 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3841 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3842 | int ctz_imm = CTZ(abs_imm); |
| 3843 | |
| 3844 | if (ctz_imm == 1) { |
| 3845 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3846 | } else { |
| 3847 | __ Asr(temp, dividend, 31); |
| 3848 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3849 | } |
| 3850 | __ add(out, temp, ShifterOperand(dividend)); |
| 3851 | |
| 3852 | if (instruction->IsDiv()) { |
| 3853 | __ Asr(out, out, ctz_imm); |
| 3854 | if (imm < 0) { |
| 3855 | __ rsb(out, out, ShifterOperand(0)); |
| 3856 | } |
| 3857 | } else { |
| 3858 | __ ubfx(out, out, 0, ctz_imm); |
| 3859 | __ sub(out, out, ShifterOperand(temp)); |
| 3860 | } |
| 3861 | } |
| 3862 | |
| 3863 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3864 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3865 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3866 | |
| 3867 | LocationSummary* locations = instruction->GetLocations(); |
| 3868 | Location second = locations->InAt(1); |
| 3869 | DCHECK(second.IsConstant()); |
| 3870 | |
| 3871 | Register out = locations->Out().AsRegister<Register>(); |
| 3872 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3873 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3874 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3875 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3876 | |
| 3877 | int64_t magic; |
| 3878 | int shift; |
| 3879 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3880 | |
| 3881 | __ LoadImmediate(temp1, magic); |
| 3882 | __ smull(temp2, temp1, dividend, temp1); |
| 3883 | |
| 3884 | if (imm > 0 && magic < 0) { |
| 3885 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3886 | } else if (imm < 0 && magic > 0) { |
| 3887 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3888 | } |
| 3889 | |
| 3890 | if (shift != 0) { |
| 3891 | __ Asr(temp1, temp1, shift); |
| 3892 | } |
| 3893 | |
| 3894 | if (instruction->IsDiv()) { |
| 3895 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3896 | } else { |
| 3897 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3898 | // TODO: Strength reduction for mls. |
| 3899 | __ LoadImmediate(temp2, imm); |
| 3900 | __ mls(out, temp1, temp2, dividend); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3905 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3906 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3907 | |
| 3908 | LocationSummary* locations = instruction->GetLocations(); |
| 3909 | Location second = locations->InAt(1); |
| 3910 | DCHECK(second.IsConstant()); |
| 3911 | |
| 3912 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3913 | if (imm == 0) { |
| 3914 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3915 | } else if (imm == 1 || imm == -1) { |
| 3916 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3917 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3918 | DivRemByPowerOfTwo(instruction); |
| 3919 | } else { |
| 3920 | DCHECK(imm <= -2 || imm >= 2); |
| 3921 | GenerateDivRemWithAnyConstant(instruction); |
| 3922 | } |
| 3923 | } |
| 3924 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3925 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3926 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3927 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3928 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3929 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3930 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3931 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3932 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3933 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3934 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3935 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3938 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3939 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3940 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3941 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3942 | if (div->InputAt(1)->IsConstant()) { |
| 3943 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3944 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3946 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3947 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3948 | // No temp register required. |
| 3949 | } else { |
| 3950 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3951 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3952 | locations->AddTemp(Location::RequiresRegister()); |
| 3953 | } |
| 3954 | } |
| 3955 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3956 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3957 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3958 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3959 | } else { |
| 3960 | InvokeRuntimeCallingConvention calling_convention; |
| 3961 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3962 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3963 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3964 | // we only need the former. |
| 3965 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3966 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3967 | break; |
| 3968 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3969 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3970 | InvokeRuntimeCallingConvention calling_convention; |
| 3971 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3972 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3973 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3974 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3975 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3976 | break; |
| 3977 | } |
| 3978 | case Primitive::kPrimFloat: |
| 3979 | case Primitive::kPrimDouble: { |
| 3980 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3981 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3982 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3983 | break; |
| 3984 | } |
| 3985 | |
| 3986 | default: |
| 3987 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3992 | LocationSummary* locations = div->GetLocations(); |
| 3993 | Location out = locations->Out(); |
| 3994 | Location first = locations->InAt(0); |
| 3995 | Location second = locations->InAt(1); |
| 3996 | |
| 3997 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3998 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3999 | if (second.IsConstant()) { |
| 4000 | GenerateDivRemConstantIntegral(div); |
| 4001 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4002 | __ sdiv(out.AsRegister<Register>(), |
| 4003 | first.AsRegister<Register>(), |
| 4004 | second.AsRegister<Register>()); |
| 4005 | } else { |
| 4006 | InvokeRuntimeCallingConvention calling_convention; |
| 4007 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4008 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4009 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4010 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4011 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4012 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4013 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4014 | break; |
| 4015 | } |
| 4016 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4017 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4018 | InvokeRuntimeCallingConvention calling_convention; |
| 4019 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4020 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4021 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4022 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4023 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4024 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4025 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4026 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4027 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4028 | break; |
| 4029 | } |
| 4030 | |
| 4031 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4032 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4033 | first.AsFpuRegister<SRegister>(), |
| 4034 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4035 | break; |
| 4036 | } |
| 4037 | |
| 4038 | case Primitive::kPrimDouble: { |
| 4039 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4040 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4041 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4042 | break; |
| 4043 | } |
| 4044 | |
| 4045 | default: |
| 4046 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4047 | } |
| 4048 | } |
| 4049 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4050 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4051 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4052 | |
| 4053 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4054 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4055 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4056 | // sdiv will be replaced by other instruction sequence. |
| 4057 | call_kind = LocationSummary::kNoCall; |
| 4058 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4059 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4060 | // Have hardware divide instruction for int, do it with three instructions. |
| 4061 | call_kind = LocationSummary::kNoCall; |
| 4062 | } |
| 4063 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4064 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4065 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4066 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4067 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4068 | if (rem->InputAt(1)->IsConstant()) { |
| 4069 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4070 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4071 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4072 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4073 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4074 | // No temp register required. |
| 4075 | } else { |
| 4076 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4077 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4078 | locations->AddTemp(Location::RequiresRegister()); |
| 4079 | } |
| 4080 | } |
| 4081 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4082 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4083 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4084 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4085 | locations->AddTemp(Location::RequiresRegister()); |
| 4086 | } else { |
| 4087 | InvokeRuntimeCallingConvention calling_convention; |
| 4088 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4089 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4090 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4091 | // we only need the latter. |
| 4092 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4093 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4094 | break; |
| 4095 | } |
| 4096 | case Primitive::kPrimLong: { |
| 4097 | InvokeRuntimeCallingConvention calling_convention; |
| 4098 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4099 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4100 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4101 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4102 | // The runtime helper puts the output in R2,R3. |
| 4103 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4104 | break; |
| 4105 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4106 | case Primitive::kPrimFloat: { |
| 4107 | InvokeRuntimeCallingConvention calling_convention; |
| 4108 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4109 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4110 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4111 | break; |
| 4112 | } |
| 4113 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4114 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4115 | InvokeRuntimeCallingConvention calling_convention; |
| 4116 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4117 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4118 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4119 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4120 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4121 | break; |
| 4122 | } |
| 4123 | |
| 4124 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4125 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4130 | LocationSummary* locations = rem->GetLocations(); |
| 4131 | Location out = locations->Out(); |
| 4132 | Location first = locations->InAt(0); |
| 4133 | Location second = locations->InAt(1); |
| 4134 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4135 | Primitive::Type type = rem->GetResultType(); |
| 4136 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4137 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4138 | if (second.IsConstant()) { |
| 4139 | GenerateDivRemConstantIntegral(rem); |
| 4140 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4141 | Register reg1 = first.AsRegister<Register>(); |
| 4142 | Register reg2 = second.AsRegister<Register>(); |
| 4143 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4144 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4145 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4146 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4147 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4148 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4149 | } else { |
| 4150 | InvokeRuntimeCallingConvention calling_convention; |
| 4151 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4152 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4153 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4154 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4155 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4156 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4157 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4158 | break; |
| 4159 | } |
| 4160 | |
| 4161 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4162 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4163 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4164 | break; |
| 4165 | } |
| 4166 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4167 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4168 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4169 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4170 | break; |
| 4171 | } |
| 4172 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4173 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4174 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4175 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4176 | break; |
| 4177 | } |
| 4178 | |
| 4179 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4180 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4181 | } |
| 4182 | } |
| 4183 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4184 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4185 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4186 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4190 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4191 | codegen_->AddSlowPath(slow_path); |
| 4192 | |
| 4193 | LocationSummary* locations = instruction->GetLocations(); |
| 4194 | Location value = locations->InAt(0); |
| 4195 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4196 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4197 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4198 | case Primitive::kPrimByte: |
| 4199 | case Primitive::kPrimChar: |
| 4200 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4201 | case Primitive::kPrimInt: { |
| 4202 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4203 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4204 | } else { |
| 4205 | DCHECK(value.IsConstant()) << value; |
| 4206 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4207 | __ b(slow_path->GetEntryLabel()); |
| 4208 | } |
| 4209 | } |
| 4210 | break; |
| 4211 | } |
| 4212 | case Primitive::kPrimLong: { |
| 4213 | if (value.IsRegisterPair()) { |
| 4214 | __ orrs(IP, |
| 4215 | value.AsRegisterPairLow<Register>(), |
| 4216 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4217 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4218 | } else { |
| 4219 | DCHECK(value.IsConstant()) << value; |
| 4220 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4221 | __ b(slow_path->GetEntryLabel()); |
| 4222 | } |
| 4223 | } |
| 4224 | break; |
| 4225 | default: |
| 4226 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4227 | } |
| 4228 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4229 | } |
| 4230 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4231 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4232 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4233 | Location rhs = locations->InAt(1); |
| 4234 | Register out = locations->Out().AsRegister<Register>(); |
| 4235 | |
| 4236 | if (rhs.IsConstant()) { |
| 4237 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4238 | // so map all rotations to a +ve. equivalent in that range. |
| 4239 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4240 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4241 | if (rot) { |
| 4242 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4243 | // (e.g. left by 2 bits == right by 30.) |
| 4244 | __ Ror(out, in, rot); |
| 4245 | } else if (out != in) { |
| 4246 | __ Mov(out, in); |
| 4247 | } |
| 4248 | } else { |
| 4249 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4254 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4255 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4256 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4257 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 4258 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4259 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4260 | Location rhs = locations->InAt(1); |
| 4261 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4262 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4263 | |
| 4264 | if (rhs.IsConstant()) { |
| 4265 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4266 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4267 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4268 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4269 | // logic below to a simple pair of binary orr. |
| 4270 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4271 | if (rot >= kArmBitsPerWord) { |
| 4272 | rot -= kArmBitsPerWord; |
| 4273 | std::swap(in_reg_hi, in_reg_lo); |
| 4274 | } |
| 4275 | // Rotate, or mov to out for zero or word size rotations. |
| 4276 | if (rot != 0u) { |
| 4277 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4278 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4279 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4280 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4281 | } else { |
| 4282 | __ Mov(out_reg_lo, in_reg_lo); |
| 4283 | __ Mov(out_reg_hi, in_reg_hi); |
| 4284 | } |
| 4285 | } else { |
| 4286 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4287 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4288 | Label end; |
| 4289 | Label shift_by_32_plus_shift_right; |
| 4290 | |
| 4291 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4292 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4293 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4294 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4295 | |
| 4296 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4297 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4298 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4299 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4300 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4301 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4302 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4303 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 4304 | __ b(&end); |
| 4305 | |
| 4306 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4307 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4308 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4309 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4310 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4311 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4312 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4313 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4314 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4315 | |
| 4316 | __ Bind(&end); |
| 4317 | } |
| 4318 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4319 | |
| 4320 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4321 | LocationSummary* locations = |
| 4322 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4323 | switch (ror->GetResultType()) { |
| 4324 | case Primitive::kPrimInt: { |
| 4325 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4326 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4327 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4328 | break; |
| 4329 | } |
| 4330 | case Primitive::kPrimLong: { |
| 4331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4332 | if (ror->InputAt(1)->IsConstant()) { |
| 4333 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4334 | } else { |
| 4335 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4336 | locations->AddTemp(Location::RequiresRegister()); |
| 4337 | locations->AddTemp(Location::RequiresRegister()); |
| 4338 | } |
| 4339 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4340 | break; |
| 4341 | } |
| 4342 | default: |
| 4343 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4344 | } |
| 4345 | } |
| 4346 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4347 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4348 | LocationSummary* locations = ror->GetLocations(); |
| 4349 | Primitive::Type type = ror->GetResultType(); |
| 4350 | switch (type) { |
| 4351 | case Primitive::kPrimInt: { |
| 4352 | HandleIntegerRotate(locations); |
| 4353 | break; |
| 4354 | } |
| 4355 | case Primitive::kPrimLong: { |
| 4356 | HandleLongRotate(locations); |
| 4357 | break; |
| 4358 | } |
| 4359 | default: |
| 4360 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4361 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4362 | } |
| 4363 | } |
| 4364 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4365 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 4366 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4367 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4368 | LocationSummary* locations = |
| 4369 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4370 | |
| 4371 | switch (op->GetResultType()) { |
| 4372 | case Primitive::kPrimInt: { |
| 4373 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4374 | if (op->InputAt(1)->IsConstant()) { |
| 4375 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4376 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4377 | } else { |
| 4378 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4379 | // Make the output overlap, as it will be used to hold the masked |
| 4380 | // second input. |
| 4381 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4382 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4383 | break; |
| 4384 | } |
| 4385 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4386 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4387 | if (op->InputAt(1)->IsConstant()) { |
| 4388 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4389 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4390 | // don't clash with high registers which the register allocator currently guarantees. |
| 4391 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4392 | } else { |
| 4393 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4394 | locations->AddTemp(Location::RequiresRegister()); |
| 4395 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4396 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4397 | break; |
| 4398 | } |
| 4399 | default: |
| 4400 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 4405 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4406 | |
| 4407 | LocationSummary* locations = op->GetLocations(); |
| 4408 | Location out = locations->Out(); |
| 4409 | Location first = locations->InAt(0); |
| 4410 | Location second = locations->InAt(1); |
| 4411 | |
| 4412 | Primitive::Type type = op->GetResultType(); |
| 4413 | switch (type) { |
| 4414 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4415 | Register out_reg = out.AsRegister<Register>(); |
| 4416 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4417 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4418 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4419 | // 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] | 4420 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4421 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4422 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4423 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4424 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4425 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4426 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4427 | } |
| 4428 | } else { |
| 4429 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4430 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4431 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4432 | __ Mov(out_reg, first_reg); |
| 4433 | } else if (op->IsShl()) { |
| 4434 | __ Lsl(out_reg, first_reg, shift_value); |
| 4435 | } else if (op->IsShr()) { |
| 4436 | __ Asr(out_reg, first_reg, shift_value); |
| 4437 | } else { |
| 4438 | __ Lsr(out_reg, first_reg, shift_value); |
| 4439 | } |
| 4440 | } |
| 4441 | break; |
| 4442 | } |
| 4443 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4444 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4445 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4446 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4447 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4448 | Register low = first.AsRegisterPairLow<Register>(); |
| 4449 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4450 | if (second.IsRegister()) { |
| 4451 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4452 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4453 | Register second_reg = second.AsRegister<Register>(); |
| 4454 | |
| 4455 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4456 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4457 | // Shift the high part |
| 4458 | __ Lsl(o_h, high, o_l); |
| 4459 | // Shift the low part and `or` what overflew on the high part |
| 4460 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4461 | __ Lsr(temp, low, temp); |
| 4462 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4463 | // If the shift is > 32 bits, override the high part |
| 4464 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4465 | __ it(PL); |
| 4466 | __ Lsl(o_h, low, temp, PL); |
| 4467 | // Shift the low part |
| 4468 | __ Lsl(o_l, low, o_l); |
| 4469 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4470 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4471 | // Shift the low part |
| 4472 | __ Lsr(o_l, low, o_h); |
| 4473 | // Shift the high part and `or` what underflew on the low part |
| 4474 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4475 | __ Lsl(temp, high, temp); |
| 4476 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4477 | // If the shift is > 32 bits, override the low part |
| 4478 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4479 | __ it(PL); |
| 4480 | __ Asr(o_l, high, temp, PL); |
| 4481 | // Shift the high part |
| 4482 | __ Asr(o_h, high, o_h); |
| 4483 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4484 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4485 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4486 | __ Lsr(o_l, low, o_h); |
| 4487 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4488 | __ Lsl(temp, high, temp); |
| 4489 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4490 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4491 | __ it(PL); |
| 4492 | __ Lsr(o_l, high, temp, PL); |
| 4493 | __ Lsr(o_h, high, o_h); |
| 4494 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4495 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4496 | // Register allocator doesn't create partial overlap. |
| 4497 | DCHECK_NE(o_l, high); |
| 4498 | DCHECK_NE(o_h, low); |
| 4499 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4500 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4501 | if (shift_value > 32) { |
| 4502 | if (op->IsShl()) { |
| 4503 | __ Lsl(o_h, low, shift_value - 32); |
| 4504 | __ LoadImmediate(o_l, 0); |
| 4505 | } else if (op->IsShr()) { |
| 4506 | __ Asr(o_l, high, shift_value - 32); |
| 4507 | __ Asr(o_h, high, 31); |
| 4508 | } else { |
| 4509 | __ Lsr(o_l, high, shift_value - 32); |
| 4510 | __ LoadImmediate(o_h, 0); |
| 4511 | } |
| 4512 | } else if (shift_value == 32) { |
| 4513 | if (op->IsShl()) { |
| 4514 | __ mov(o_h, ShifterOperand(low)); |
| 4515 | __ LoadImmediate(o_l, 0); |
| 4516 | } else if (op->IsShr()) { |
| 4517 | __ mov(o_l, ShifterOperand(high)); |
| 4518 | __ Asr(o_h, high, 31); |
| 4519 | } else { |
| 4520 | __ mov(o_l, ShifterOperand(high)); |
| 4521 | __ LoadImmediate(o_h, 0); |
| 4522 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4523 | } else if (shift_value == 1) { |
| 4524 | if (op->IsShl()) { |
| 4525 | __ Lsls(o_l, low, 1); |
| 4526 | __ adc(o_h, high, ShifterOperand(high)); |
| 4527 | } else if (op->IsShr()) { |
| 4528 | __ Asrs(o_h, high, 1); |
| 4529 | __ Rrx(o_l, low); |
| 4530 | } else { |
| 4531 | __ Lsrs(o_h, high, 1); |
| 4532 | __ Rrx(o_l, low); |
| 4533 | } |
| 4534 | } else { |
| 4535 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4536 | if (op->IsShl()) { |
| 4537 | __ Lsl(o_h, high, shift_value); |
| 4538 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4539 | __ Lsl(o_l, low, shift_value); |
| 4540 | } else if (op->IsShr()) { |
| 4541 | __ Lsr(o_l, low, shift_value); |
| 4542 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4543 | __ Asr(o_h, high, shift_value); |
| 4544 | } else { |
| 4545 | __ Lsr(o_l, low, shift_value); |
| 4546 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4547 | __ Lsr(o_h, high, shift_value); |
| 4548 | } |
| 4549 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4550 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4551 | break; |
| 4552 | } |
| 4553 | default: |
| 4554 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4555 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4560 | HandleShift(shl); |
| 4561 | } |
| 4562 | |
| 4563 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4564 | HandleShift(shl); |
| 4565 | } |
| 4566 | |
| 4567 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4568 | HandleShift(shr); |
| 4569 | } |
| 4570 | |
| 4571 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4572 | HandleShift(shr); |
| 4573 | } |
| 4574 | |
| 4575 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4576 | HandleShift(ushr); |
| 4577 | } |
| 4578 | |
| 4579 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4580 | HandleShift(ushr); |
| 4581 | } |
| 4582 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4583 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4584 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4585 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4586 | if (instruction->IsStringAlloc()) { |
| 4587 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4588 | } else { |
| 4589 | InvokeRuntimeCallingConvention calling_convention; |
| 4590 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4591 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4592 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4596 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4597 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4598 | if (instruction->IsStringAlloc()) { |
| 4599 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4600 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4601 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4602 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4603 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4604 | __ blx(LR); |
| 4605 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4606 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4607 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4608 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4609 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4610 | } |
| 4611 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4612 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4613 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4614 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4615 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4616 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4617 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4618 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4622 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4623 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4624 | QuickEntrypointEnum entrypoint = |
| 4625 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4626 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4627 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4628 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4629 | } |
| 4630 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4631 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4632 | LocationSummary* locations = |
| 4633 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4634 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4635 | if (location.IsStackSlot()) { |
| 4636 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4637 | } else if (location.IsDoubleStackSlot()) { |
| 4638 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4639 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4640 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4641 | } |
| 4642 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4643 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4644 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4645 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4649 | LocationSummary* locations = |
| 4650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4651 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4652 | } |
| 4653 | |
| 4654 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4655 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4656 | } |
| 4657 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4658 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4659 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4660 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4661 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4662 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4663 | } |
| 4664 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4665 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4666 | LocationSummary* locations = not_->GetLocations(); |
| 4667 | Location out = locations->Out(); |
| 4668 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4669 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4670 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4671 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4672 | break; |
| 4673 | |
| 4674 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4675 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4676 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4677 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4678 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4679 | break; |
| 4680 | |
| 4681 | default: |
| 4682 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4683 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4684 | } |
| 4685 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4686 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4687 | LocationSummary* locations = |
| 4688 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4689 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4691 | } |
| 4692 | |
| 4693 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4694 | LocationSummary* locations = bool_not->GetLocations(); |
| 4695 | Location out = locations->Out(); |
| 4696 | Location in = locations->InAt(0); |
| 4697 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4698 | } |
| 4699 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4700 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4701 | LocationSummary* locations = |
| 4702 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4703 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4704 | case Primitive::kPrimBoolean: |
| 4705 | case Primitive::kPrimByte: |
| 4706 | case Primitive::kPrimShort: |
| 4707 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4708 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4709 | case Primitive::kPrimLong: { |
| 4710 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4711 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4712 | // Output overlaps because it is written before doing the low comparison. |
| 4713 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4714 | break; |
| 4715 | } |
| 4716 | case Primitive::kPrimFloat: |
| 4717 | case Primitive::kPrimDouble: { |
| 4718 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4719 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4720 | locations->SetOut(Location::RequiresRegister()); |
| 4721 | break; |
| 4722 | } |
| 4723 | default: |
| 4724 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4725 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4726 | } |
| 4727 | |
| 4728 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4729 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4730 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4731 | Location left = locations->InAt(0); |
| 4732 | Location right = locations->InAt(1); |
| 4733 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4734 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4735 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4736 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4737 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4738 | case Primitive::kPrimBoolean: |
| 4739 | case Primitive::kPrimByte: |
| 4740 | case Primitive::kPrimShort: |
| 4741 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4742 | case Primitive::kPrimInt: { |
| 4743 | __ LoadImmediate(out, 0); |
| 4744 | __ cmp(left.AsRegister<Register>(), |
| 4745 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4746 | less_cond = LT; |
| 4747 | break; |
| 4748 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4749 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4750 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4751 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4752 | __ b(&less, LT); |
| 4753 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4754 | // 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] | 4755 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4756 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4757 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4758 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4759 | break; |
| 4760 | } |
| 4761 | case Primitive::kPrimFloat: |
| 4762 | case Primitive::kPrimDouble: { |
| 4763 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 4764 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4765 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4766 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4767 | break; |
| 4768 | } |
| 4769 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4770 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4771 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4772 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4773 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4774 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4775 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4776 | |
| 4777 | __ Bind(&greater); |
| 4778 | __ LoadImmediate(out, 1); |
| 4779 | __ b(&done); |
| 4780 | |
| 4781 | __ Bind(&less); |
| 4782 | __ LoadImmediate(out, -1); |
| 4783 | |
| 4784 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4785 | } |
| 4786 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4787 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4788 | LocationSummary* locations = |
| 4789 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4790 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4791 | locations->SetInAt(i, Location::Any()); |
| 4792 | } |
| 4793 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4794 | } |
| 4795 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4796 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4797 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4798 | } |
| 4799 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4800 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4801 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4802 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4803 | switch (kind) { |
| 4804 | case MemBarrierKind::kAnyStore: |
| 4805 | case MemBarrierKind::kLoadAny: |
| 4806 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4807 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4808 | break; |
| 4809 | } |
| 4810 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4811 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4812 | break; |
| 4813 | } |
| 4814 | default: |
| 4815 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4816 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4817 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4821 | uint32_t offset, |
| 4822 | Register out_lo, |
| 4823 | Register out_hi) { |
| 4824 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4825 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4826 | // `offset` into `out_lo` does not clutter `addr`. |
| 4827 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4828 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4829 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4830 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4831 | } |
| 4832 | __ ldrexd(out_lo, out_hi, addr); |
| 4833 | } |
| 4834 | |
| 4835 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4836 | uint32_t offset, |
| 4837 | Register value_lo, |
| 4838 | Register value_hi, |
| 4839 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4840 | Register temp2, |
| 4841 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4842 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4843 | if (offset != 0) { |
| 4844 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4845 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4846 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4847 | } |
| 4848 | __ Bind(&fail); |
| 4849 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4850 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4851 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4852 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4853 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4854 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4858 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4859 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4860 | LocationSummary* locations = |
| 4861 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4862 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4863 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4864 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4865 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4866 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4867 | } else { |
| 4868 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4869 | } |
| 4870 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4871 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4872 | bool generate_volatile = field_info.IsVolatile() |
| 4873 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4874 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4875 | bool needs_write_barrier = |
| 4876 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4877 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4878 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4879 | if (needs_write_barrier) { |
| 4880 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4881 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4882 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4883 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4884 | // - registers need to be consecutive |
| 4885 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4886 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4887 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4888 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4889 | |
| 4890 | locations->AddTemp(Location::RequiresRegister()); |
| 4891 | locations->AddTemp(Location::RequiresRegister()); |
| 4892 | if (field_type == Primitive::kPrimDouble) { |
| 4893 | // For doubles we need two more registers to copy the value. |
| 4894 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4895 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4896 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4897 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4898 | } |
| 4899 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4900 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4901 | const FieldInfo& field_info, |
| 4902 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4904 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4905 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4906 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4907 | Location value = locations->InAt(1); |
| 4908 | |
| 4909 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4910 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4911 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4912 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4913 | bool needs_write_barrier = |
| 4914 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4915 | |
| 4916 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4917 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4918 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4919 | |
| 4920 | switch (field_type) { |
| 4921 | case Primitive::kPrimBoolean: |
| 4922 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4923 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4924 | break; |
| 4925 | } |
| 4926 | |
| 4927 | case Primitive::kPrimShort: |
| 4928 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4929 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4930 | break; |
| 4931 | } |
| 4932 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4933 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4934 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4935 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4936 | // Note that in the case where `value` is a null reference, |
| 4937 | // we do not enter this block, as a null reference does not |
| 4938 | // need poisoning. |
| 4939 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4940 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4941 | __ Mov(temp, value.AsRegister<Register>()); |
| 4942 | __ PoisonHeapReference(temp); |
| 4943 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4944 | } else { |
| 4945 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4946 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4947 | break; |
| 4948 | } |
| 4949 | |
| 4950 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4951 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4952 | GenerateWideAtomicStore(base, offset, |
| 4953 | value.AsRegisterPairLow<Register>(), |
| 4954 | value.AsRegisterPairHigh<Register>(), |
| 4955 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4956 | locations->GetTemp(1).AsRegister<Register>(), |
| 4957 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4958 | } else { |
| 4959 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4960 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4961 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4962 | break; |
| 4963 | } |
| 4964 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4965 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4966 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4967 | break; |
| 4968 | } |
| 4969 | |
| 4970 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4971 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4972 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4973 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4974 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4975 | |
| 4976 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4977 | |
| 4978 | GenerateWideAtomicStore(base, offset, |
| 4979 | value_reg_lo, |
| 4980 | value_reg_hi, |
| 4981 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | locations->GetTemp(3).AsRegister<Register>(), |
| 4983 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4984 | } else { |
| 4985 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4986 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4987 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4988 | break; |
| 4989 | } |
| 4990 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4991 | case Primitive::kPrimVoid: |
| 4992 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4993 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4994 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4995 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4996 | // Longs and doubles are handled in the switch. |
| 4997 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4998 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4999 | } |
| 5000 | |
| 5001 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5002 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5003 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5004 | codegen_->MarkGCCard( |
| 5005 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5006 | } |
| 5007 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5008 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5009 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5010 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5011 | } |
| 5012 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5013 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5014 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5015 | |
| 5016 | bool object_field_get_with_read_barrier = |
| 5017 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5018 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5019 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5020 | object_field_get_with_read_barrier ? |
| 5021 | LocationSummary::kCallOnSlowPath : |
| 5022 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5023 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5024 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5025 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5026 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5027 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5028 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5029 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5030 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5031 | // The output overlaps in case of volatile long: we don't want the |
| 5032 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5033 | // object's location. Likewise, in the case of an object field get |
| 5034 | // with read barriers enabled, we do not want the load to overwrite |
| 5035 | // the object's location, as we need it to emit the read barrier. |
| 5036 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5037 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5038 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5039 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5040 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5041 | } else { |
| 5042 | locations->SetOut(Location::RequiresRegister(), |
| 5043 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5044 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5045 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5046 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5047 | // - registers need to be consecutive |
| 5048 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5049 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5050 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5051 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5052 | locations->AddTemp(Location::RequiresRegister()); |
| 5053 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5054 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5055 | // We need a temporary register for the read barrier marking slow |
| 5056 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 5057 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5058 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5059 | } |
| 5060 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5061 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5062 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5063 | << input->GetType(); |
| 5064 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5065 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5066 | return Location::ConstantLocation(input->AsConstant()); |
| 5067 | } else { |
| 5068 | return Location::RequiresFpuRegister(); |
| 5069 | } |
| 5070 | } |
| 5071 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5072 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5073 | Opcode opcode) { |
| 5074 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5075 | if (constant->IsConstant() && |
| 5076 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5077 | return Location::ConstantLocation(constant->AsConstant()); |
| 5078 | } |
| 5079 | return Location::RequiresRegister(); |
| 5080 | } |
| 5081 | |
| 5082 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5083 | Opcode opcode) { |
| 5084 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5085 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5086 | Opcode high_opcode = opcode; |
| 5087 | SetCc low_set_cc = kCcDontCare; |
| 5088 | switch (opcode) { |
| 5089 | case SUB: |
| 5090 | // Flip the operation to an ADD. |
| 5091 | value = -value; |
| 5092 | opcode = ADD; |
| 5093 | FALLTHROUGH_INTENDED; |
| 5094 | case ADD: |
| 5095 | if (Low32Bits(value) == 0u) { |
| 5096 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5097 | } |
| 5098 | high_opcode = ADC; |
| 5099 | low_set_cc = kCcSet; |
| 5100 | break; |
| 5101 | default: |
| 5102 | break; |
| 5103 | } |
| 5104 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5105 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5106 | } else { |
| 5107 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5108 | } |
| 5109 | } |
| 5110 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5111 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5112 | Opcode opcode, |
| 5113 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5114 | ShifterOperand so; |
| 5115 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5116 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5117 | return true; |
| 5118 | } |
| 5119 | Opcode neg_opcode = kNoOperand; |
| 5120 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5121 | case AND: neg_opcode = BIC; value = ~value; break; |
| 5122 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 5123 | case ADD: neg_opcode = SUB; value = -value; break; |
| 5124 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 5125 | case SUB: neg_opcode = ADD; value = -value; break; |
| 5126 | case SBC: neg_opcode = ADC; value = ~value; break; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame^] | 5127 | case MOV: neg_opcode = MVN; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5128 | default: |
| 5129 | return false; |
| 5130 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5131 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5132 | } |
| 5133 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5134 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5135 | const FieldInfo& field_info) { |
| 5136 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5137 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5138 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5139 | Location base_loc = locations->InAt(0); |
| 5140 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5141 | Location out = locations->Out(); |
| 5142 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5143 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5144 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5145 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5146 | |
| 5147 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5148 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5149 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5150 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5151 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5152 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5153 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5154 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5155 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5156 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5157 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5158 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5159 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5160 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5161 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5162 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5163 | |
| 5164 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5165 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5166 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5167 | |
| 5168 | case Primitive::kPrimNot: { |
| 5169 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5170 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5171 | Location temp_loc = locations->GetTemp(0); |
| 5172 | // Note that a potential implicit null check is handled in this |
| 5173 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5174 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5175 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5176 | if (is_volatile) { |
| 5177 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5178 | } |
| 5179 | } else { |
| 5180 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5181 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5182 | if (is_volatile) { |
| 5183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5184 | } |
| 5185 | // If read barriers are enabled, emit read barriers other than |
| 5186 | // Baker's using a slow path (and also unpoison the loaded |
| 5187 | // reference, if heap poisoning is enabled). |
| 5188 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5189 | } |
| 5190 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5191 | } |
| 5192 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5193 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5194 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5195 | GenerateWideAtomicLoad(base, offset, |
| 5196 | out.AsRegisterPairLow<Register>(), |
| 5197 | out.AsRegisterPairHigh<Register>()); |
| 5198 | } else { |
| 5199 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5200 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5201 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5202 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5203 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5204 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5205 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5206 | |
| 5207 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5208 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5209 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5210 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5211 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5212 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5213 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5214 | __ vmovdrr(out_reg, lo, hi); |
| 5215 | } else { |
| 5216 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5217 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5218 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5219 | break; |
| 5220 | } |
| 5221 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5222 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5223 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5224 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5225 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5226 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5227 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5228 | // Potential implicit null checks, in the case of reference or |
| 5229 | // double fields, are handled in the previous switch statement. |
| 5230 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5231 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5232 | } |
| 5233 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5234 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5235 | if (field_type == Primitive::kPrimNot) { |
| 5236 | // Memory barriers, in the case of references, are also handled |
| 5237 | // in the previous switch statement. |
| 5238 | } else { |
| 5239 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5240 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5241 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5245 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5246 | } |
| 5247 | |
| 5248 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5249 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5253 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5254 | } |
| 5255 | |
| 5256 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5257 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5258 | } |
| 5259 | |
| 5260 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5261 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5262 | } |
| 5263 | |
| 5264 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5265 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5266 | } |
| 5267 | |
| 5268 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5269 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5270 | } |
| 5271 | |
| 5272 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5273 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5274 | } |
| 5275 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5276 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5277 | HUnresolvedInstanceFieldGet* instruction) { |
| 5278 | FieldAccessCallingConventionARM calling_convention; |
| 5279 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5280 | instruction, instruction->GetFieldType(), calling_convention); |
| 5281 | } |
| 5282 | |
| 5283 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5284 | HUnresolvedInstanceFieldGet* instruction) { |
| 5285 | FieldAccessCallingConventionARM calling_convention; |
| 5286 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5287 | instruction->GetFieldType(), |
| 5288 | instruction->GetFieldIndex(), |
| 5289 | instruction->GetDexPc(), |
| 5290 | calling_convention); |
| 5291 | } |
| 5292 | |
| 5293 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5294 | HUnresolvedInstanceFieldSet* instruction) { |
| 5295 | FieldAccessCallingConventionARM calling_convention; |
| 5296 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5297 | instruction, instruction->GetFieldType(), calling_convention); |
| 5298 | } |
| 5299 | |
| 5300 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5301 | HUnresolvedInstanceFieldSet* instruction) { |
| 5302 | FieldAccessCallingConventionARM calling_convention; |
| 5303 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5304 | instruction->GetFieldType(), |
| 5305 | instruction->GetFieldIndex(), |
| 5306 | instruction->GetDexPc(), |
| 5307 | calling_convention); |
| 5308 | } |
| 5309 | |
| 5310 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5311 | HUnresolvedStaticFieldGet* instruction) { |
| 5312 | FieldAccessCallingConventionARM calling_convention; |
| 5313 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5314 | instruction, instruction->GetFieldType(), calling_convention); |
| 5315 | } |
| 5316 | |
| 5317 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5318 | HUnresolvedStaticFieldGet* instruction) { |
| 5319 | FieldAccessCallingConventionARM calling_convention; |
| 5320 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5321 | instruction->GetFieldType(), |
| 5322 | instruction->GetFieldIndex(), |
| 5323 | instruction->GetDexPc(), |
| 5324 | calling_convention); |
| 5325 | } |
| 5326 | |
| 5327 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 5328 | HUnresolvedStaticFieldSet* instruction) { |
| 5329 | FieldAccessCallingConventionARM calling_convention; |
| 5330 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5331 | instruction, instruction->GetFieldType(), calling_convention); |
| 5332 | } |
| 5333 | |
| 5334 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 5335 | HUnresolvedStaticFieldSet* instruction) { |
| 5336 | FieldAccessCallingConventionARM calling_convention; |
| 5337 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5338 | instruction->GetFieldType(), |
| 5339 | instruction->GetFieldIndex(), |
| 5340 | instruction->GetDexPc(), |
| 5341 | calling_convention); |
| 5342 | } |
| 5343 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5344 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5345 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5346 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5349 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5350 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5351 | return; |
| 5352 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5353 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5354 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5355 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5356 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5357 | } |
| 5358 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5359 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5360 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5361 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5362 | |
| 5363 | LocationSummary* locations = instruction->GetLocations(); |
| 5364 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5365 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5366 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5367 | } |
| 5368 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5369 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5370 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5371 | } |
| 5372 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5373 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5374 | switch (type) { |
| 5375 | case Primitive::kPrimNot: |
| 5376 | return kLoadWord; |
| 5377 | case Primitive::kPrimBoolean: |
| 5378 | return kLoadUnsignedByte; |
| 5379 | case Primitive::kPrimByte: |
| 5380 | return kLoadSignedByte; |
| 5381 | case Primitive::kPrimChar: |
| 5382 | return kLoadUnsignedHalfword; |
| 5383 | case Primitive::kPrimShort: |
| 5384 | return kLoadSignedHalfword; |
| 5385 | case Primitive::kPrimInt: |
| 5386 | return kLoadWord; |
| 5387 | case Primitive::kPrimLong: |
| 5388 | return kLoadWordPair; |
| 5389 | case Primitive::kPrimFloat: |
| 5390 | return kLoadSWord; |
| 5391 | case Primitive::kPrimDouble: |
| 5392 | return kLoadDWord; |
| 5393 | default: |
| 5394 | LOG(FATAL) << "Unreachable type " << type; |
| 5395 | UNREACHABLE(); |
| 5396 | } |
| 5397 | } |
| 5398 | |
| 5399 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5400 | switch (type) { |
| 5401 | case Primitive::kPrimNot: |
| 5402 | return kStoreWord; |
| 5403 | case Primitive::kPrimBoolean: |
| 5404 | case Primitive::kPrimByte: |
| 5405 | return kStoreByte; |
| 5406 | case Primitive::kPrimChar: |
| 5407 | case Primitive::kPrimShort: |
| 5408 | return kStoreHalfword; |
| 5409 | case Primitive::kPrimInt: |
| 5410 | return kStoreWord; |
| 5411 | case Primitive::kPrimLong: |
| 5412 | return kStoreWordPair; |
| 5413 | case Primitive::kPrimFloat: |
| 5414 | return kStoreSWord; |
| 5415 | case Primitive::kPrimDouble: |
| 5416 | return kStoreDWord; |
| 5417 | default: |
| 5418 | LOG(FATAL) << "Unreachable type " << type; |
| 5419 | UNREACHABLE(); |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5424 | Location out_loc, |
| 5425 | Register base, |
| 5426 | Register reg_offset, |
| 5427 | Condition cond) { |
| 5428 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5429 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5430 | |
| 5431 | switch (type) { |
| 5432 | case Primitive::kPrimByte: |
| 5433 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5434 | break; |
| 5435 | case Primitive::kPrimBoolean: |
| 5436 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5437 | break; |
| 5438 | case Primitive::kPrimShort: |
| 5439 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5440 | break; |
| 5441 | case Primitive::kPrimChar: |
| 5442 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5443 | break; |
| 5444 | case Primitive::kPrimNot: |
| 5445 | case Primitive::kPrimInt: |
| 5446 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5447 | break; |
| 5448 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5449 | case Primitive::kPrimLong: |
| 5450 | case Primitive::kPrimFloat: |
| 5451 | case Primitive::kPrimDouble: |
| 5452 | default: |
| 5453 | LOG(FATAL) << "Unreachable type " << type; |
| 5454 | UNREACHABLE(); |
| 5455 | } |
| 5456 | } |
| 5457 | |
| 5458 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5459 | Location loc, |
| 5460 | Register base, |
| 5461 | Register reg_offset, |
| 5462 | Condition cond) { |
| 5463 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5464 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5465 | |
| 5466 | switch (type) { |
| 5467 | case Primitive::kPrimByte: |
| 5468 | case Primitive::kPrimBoolean: |
| 5469 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5470 | break; |
| 5471 | case Primitive::kPrimShort: |
| 5472 | case Primitive::kPrimChar: |
| 5473 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5474 | break; |
| 5475 | case Primitive::kPrimNot: |
| 5476 | case Primitive::kPrimInt: |
| 5477 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5478 | break; |
| 5479 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5480 | case Primitive::kPrimLong: |
| 5481 | case Primitive::kPrimFloat: |
| 5482 | case Primitive::kPrimDouble: |
| 5483 | default: |
| 5484 | LOG(FATAL) << "Unreachable type " << type; |
| 5485 | UNREACHABLE(); |
| 5486 | } |
| 5487 | } |
| 5488 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5489 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5490 | bool object_array_get_with_read_barrier = |
| 5491 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5492 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5493 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5494 | object_array_get_with_read_barrier ? |
| 5495 | LocationSummary::kCallOnSlowPath : |
| 5496 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5497 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5498 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5499 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5500 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5501 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5502 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5503 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5504 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5505 | // The output overlaps in the case of an object array get with |
| 5506 | // read barriers enabled: we do not want the move to overwrite the |
| 5507 | // array's location, as we need it to emit the read barrier. |
| 5508 | locations->SetOut( |
| 5509 | Location::RequiresRegister(), |
| 5510 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5511 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5512 | // We need a temporary register for the read barrier marking slow |
| 5513 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5514 | // Also need for String compression feature. |
| 5515 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5516 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5517 | locations->AddTemp(Location::RequiresRegister()); |
| 5518 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5522 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5523 | Location obj_loc = locations->InAt(0); |
| 5524 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5525 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5526 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5527 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5528 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5529 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5530 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5531 | HInstruction* array_instr = instruction->GetArray(); |
| 5532 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5533 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5534 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5535 | case Primitive::kPrimBoolean: |
| 5536 | case Primitive::kPrimByte: |
| 5537 | case Primitive::kPrimShort: |
| 5538 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5539 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5540 | Register length; |
| 5541 | if (maybe_compressed_char_at) { |
| 5542 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5543 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5544 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5545 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5546 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5547 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5548 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5549 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5550 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5551 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5552 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5553 | "Expecting 0=compressed, 1=uncompressed"); |
| 5554 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5555 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5556 | out_loc.AsRegister<Register>(), |
| 5557 | obj, |
| 5558 | data_offset + const_index); |
| 5559 | __ b(&done); |
| 5560 | __ Bind(&uncompressed_load); |
| 5561 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5562 | out_loc.AsRegister<Register>(), |
| 5563 | obj, |
| 5564 | data_offset + (const_index << 1)); |
| 5565 | __ Bind(&done); |
| 5566 | } else { |
| 5567 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5568 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5569 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5570 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5571 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5572 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5573 | Register temp = IP; |
| 5574 | |
| 5575 | if (has_intermediate_address) { |
| 5576 | // We do not need to compute the intermediate address from the array: the |
| 5577 | // input instruction has done it already. See the comment in |
| 5578 | // `TryExtractArrayAccessAddress()`. |
| 5579 | if (kIsDebugBuild) { |
| 5580 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5581 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5582 | } |
| 5583 | temp = obj; |
| 5584 | } else { |
| 5585 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5586 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5587 | if (maybe_compressed_char_at) { |
| 5588 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5589 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5590 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5591 | "Expecting 0=compressed, 1=uncompressed"); |
| 5592 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5593 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5594 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 5595 | __ b(&done); |
| 5596 | __ Bind(&uncompressed_load); |
| 5597 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5598 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 5599 | __ Bind(&done); |
| 5600 | } else { |
| 5601 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5602 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5603 | } |
| 5604 | break; |
| 5605 | } |
| 5606 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5607 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5608 | // The read barrier instrumentation of object ArrayGet |
| 5609 | // instructions does not support the HIntermediateAddress |
| 5610 | // instruction. |
| 5611 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5612 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5613 | static_assert( |
| 5614 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5615 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5616 | // /* HeapReference<Object> */ out = |
| 5617 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5618 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5619 | Location temp = locations->GetTemp(0); |
| 5620 | // Note that a potential implicit null check is handled in this |
| 5621 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 5622 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5623 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5624 | } else { |
| 5625 | Register out = out_loc.AsRegister<Register>(); |
| 5626 | if (index.IsConstant()) { |
| 5627 | size_t offset = |
| 5628 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5629 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5630 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5631 | // If read barriers are enabled, emit read barriers other than |
| 5632 | // Baker's using a slow path (and also unpoison the loaded |
| 5633 | // reference, if heap poisoning is enabled). |
| 5634 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5635 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5636 | Register temp = IP; |
| 5637 | |
| 5638 | if (has_intermediate_address) { |
| 5639 | // We do not need to compute the intermediate address from the array: the |
| 5640 | // input instruction has done it already. See the comment in |
| 5641 | // `TryExtractArrayAccessAddress()`. |
| 5642 | if (kIsDebugBuild) { |
| 5643 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5644 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5645 | } |
| 5646 | temp = obj; |
| 5647 | } else { |
| 5648 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5649 | } |
| 5650 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5651 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5652 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5653 | // If read barriers are enabled, emit read barriers other than |
| 5654 | // Baker's using a slow path (and also unpoison the loaded |
| 5655 | // reference, if heap poisoning is enabled). |
| 5656 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5657 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5658 | } |
| 5659 | } |
| 5660 | break; |
| 5661 | } |
| 5662 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5663 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5664 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5665 | size_t offset = |
| 5666 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5667 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5668 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5669 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5670 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5671 | } |
| 5672 | break; |
| 5673 | } |
| 5674 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5675 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5676 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5677 | if (index.IsConstant()) { |
| 5678 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5679 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5680 | } else { |
| 5681 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5682 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5683 | } |
| 5684 | break; |
| 5685 | } |
| 5686 | |
| 5687 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5688 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5689 | if (index.IsConstant()) { |
| 5690 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5691 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5692 | } else { |
| 5693 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5694 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5695 | } |
| 5696 | break; |
| 5697 | } |
| 5698 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5699 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5700 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5701 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5702 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5703 | |
| 5704 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5705 | // Potential implicit null checks, in the case of reference |
| 5706 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5707 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5708 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5709 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5713 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5714 | |
| 5715 | bool needs_write_barrier = |
| 5716 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5717 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5718 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5719 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5720 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5721 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5722 | LocationSummary::kCallOnSlowPath : |
| 5723 | LocationSummary::kNoCall); |
| 5724 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5725 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5726 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5727 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5728 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5729 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5730 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5731 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5732 | if (needs_write_barrier) { |
| 5733 | // Temporary registers for the write barrier. |
| 5734 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5735 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5736 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5740 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5741 | Location array_loc = locations->InAt(0); |
| 5742 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5743 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5744 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5745 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5746 | bool needs_write_barrier = |
| 5747 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5748 | uint32_t data_offset = |
| 5749 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5750 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5751 | HInstruction* array_instr = instruction->GetArray(); |
| 5752 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5753 | |
| 5754 | switch (value_type) { |
| 5755 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5756 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5757 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5758 | case Primitive::kPrimChar: |
| 5759 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5760 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5761 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5762 | uint32_t full_offset = |
| 5763 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5764 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5765 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5766 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5767 | Register temp = IP; |
| 5768 | |
| 5769 | if (has_intermediate_address) { |
| 5770 | // We do not need to compute the intermediate address from the array: the |
| 5771 | // input instruction has done it already. See the comment in |
| 5772 | // `TryExtractArrayAccessAddress()`. |
| 5773 | if (kIsDebugBuild) { |
| 5774 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5775 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5776 | } |
| 5777 | temp = array; |
| 5778 | } else { |
| 5779 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5780 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5781 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5782 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5783 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5784 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5785 | } |
| 5786 | break; |
| 5787 | } |
| 5788 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5789 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5790 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5791 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5792 | // See the comment in instruction_simplifier_shared.cc. |
| 5793 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5794 | |
| 5795 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5796 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5797 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5798 | size_t offset = |
| 5799 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5800 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5801 | } else { |
| 5802 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5803 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5804 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5805 | value_loc, |
| 5806 | IP, |
| 5807 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5808 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5809 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5810 | DCHECK(!needs_write_barrier); |
| 5811 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5812 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5813 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5814 | |
| 5815 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5816 | Location temp1_loc = locations->GetTemp(0); |
| 5817 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5818 | Location temp2_loc = locations->GetTemp(1); |
| 5819 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5820 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5821 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5822 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5823 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5824 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5825 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5826 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5827 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5828 | codegen_->AddSlowPath(slow_path); |
| 5829 | if (instruction->GetValueCanBeNull()) { |
| 5830 | Label non_zero; |
| 5831 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5832 | if (index.IsConstant()) { |
| 5833 | size_t offset = |
| 5834 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5835 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5836 | } else { |
| 5837 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5838 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5839 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5840 | value_loc, |
| 5841 | IP, |
| 5842 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5843 | } |
| 5844 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5845 | __ b(&done); |
| 5846 | __ Bind(&non_zero); |
| 5847 | } |
| 5848 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5849 | // Note that when read barriers are enabled, the type checks |
| 5850 | // are performed without read barriers. This is fine, even in |
| 5851 | // the case where a class object is in the from-space after |
| 5852 | // the flip, as a comparison involving such a type would not |
| 5853 | // produce a false positive; it may of course produce a false |
| 5854 | // negative, in which case we would take the ArraySet slow |
| 5855 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5856 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5857 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5858 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5859 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5860 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5861 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5862 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5863 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5864 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5865 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5866 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5867 | // nor `temp2`, as we are comparing two poisoned references. |
| 5868 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5869 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5870 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5871 | Label do_put; |
| 5872 | __ b(&do_put, EQ); |
| 5873 | // If heap poisoning is enabled, the `temp1` reference has |
| 5874 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5875 | __ MaybeUnpoisonHeapReference(temp1); |
| 5876 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5877 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5878 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5879 | // If heap poisoning is enabled, no need to unpoison |
| 5880 | // `temp1`, as we are comparing against null below. |
| 5881 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5882 | __ Bind(&do_put); |
| 5883 | } else { |
| 5884 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5885 | } |
| 5886 | } |
| 5887 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5888 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5889 | if (kPoisonHeapReferences) { |
| 5890 | // Note that in the case where `value` is a null reference, |
| 5891 | // we do not enter this block, as a null reference does not |
| 5892 | // need poisoning. |
| 5893 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5894 | __ Mov(temp1, value); |
| 5895 | __ PoisonHeapReference(temp1); |
| 5896 | source = temp1; |
| 5897 | } |
| 5898 | |
| 5899 | if (index.IsConstant()) { |
| 5900 | size_t offset = |
| 5901 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5902 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5903 | } else { |
| 5904 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5905 | |
| 5906 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5907 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5908 | Location::RegisterLocation(source), |
| 5909 | IP, |
| 5910 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5911 | } |
| 5912 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5913 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5914 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5915 | } |
| 5916 | |
| 5917 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5918 | |
| 5919 | if (done.IsLinked()) { |
| 5920 | __ Bind(&done); |
| 5921 | } |
| 5922 | |
| 5923 | if (slow_path != nullptr) { |
| 5924 | __ Bind(slow_path->GetExitLabel()); |
| 5925 | } |
| 5926 | |
| 5927 | break; |
| 5928 | } |
| 5929 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5930 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5931 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5932 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5933 | size_t offset = |
| 5934 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5935 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5936 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5937 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5938 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5939 | } |
| 5940 | break; |
| 5941 | } |
| 5942 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5943 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5944 | Location value = locations->InAt(2); |
| 5945 | DCHECK(value.IsFpuRegister()); |
| 5946 | if (index.IsConstant()) { |
| 5947 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5948 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5949 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5950 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5951 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5952 | } |
| 5953 | break; |
| 5954 | } |
| 5955 | |
| 5956 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5957 | Location value = locations->InAt(2); |
| 5958 | DCHECK(value.IsFpuRegisterPair()); |
| 5959 | if (index.IsConstant()) { |
| 5960 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5961 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5962 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5963 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5964 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5965 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5966 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5967 | break; |
| 5968 | } |
| 5969 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5970 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5971 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5972 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5973 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5974 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5975 | // Objects are handled in the switch. |
| 5976 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5977 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5978 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5982 | LocationSummary* locations = |
| 5983 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5984 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5985 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5989 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5990 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5991 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5992 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5993 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5994 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5995 | // Mask out compression flag from String's array length. |
| 5996 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5997 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5998 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5999 | } |
| 6000 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6001 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6002 | LocationSummary* locations = |
| 6003 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6004 | |
| 6005 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6006 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6007 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6008 | } |
| 6009 | |
| 6010 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6011 | LocationSummary* locations = instruction->GetLocations(); |
| 6012 | Location out = locations->Out(); |
| 6013 | Location first = locations->InAt(0); |
| 6014 | Location second = locations->InAt(1); |
| 6015 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6016 | if (second.IsRegister()) { |
| 6017 | __ add(out.AsRegister<Register>(), |
| 6018 | first.AsRegister<Register>(), |
| 6019 | ShifterOperand(second.AsRegister<Register>())); |
| 6020 | } else { |
| 6021 | __ AddConstant(out.AsRegister<Register>(), |
| 6022 | first.AsRegister<Register>(), |
| 6023 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6024 | } |
| 6025 | } |
| 6026 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6027 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6028 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6029 | InvokeRuntimeCallingConvention calling_convention; |
| 6030 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6031 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6032 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6033 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6034 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6038 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6039 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 6040 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6041 | codegen_->AddSlowPath(slow_path); |
| 6042 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6043 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 6044 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6045 | |
| 6046 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 6047 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6048 | } |
| 6049 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6050 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6051 | Register card, |
| 6052 | Register object, |
| 6053 | Register value, |
| 6054 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6055 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6056 | if (can_be_null) { |
| 6057 | __ CompareAndBranchIfZero(value, &is_null); |
| 6058 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6059 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6060 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6061 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6062 | if (can_be_null) { |
| 6063 | __ Bind(&is_null); |
| 6064 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6065 | } |
| 6066 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6067 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6068 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6072 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6073 | } |
| 6074 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6075 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6076 | LocationSummary* locations = |
| 6077 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6078 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6082 | HBasicBlock* block = instruction->GetBlock(); |
| 6083 | if (block->GetLoopInformation() != nullptr) { |
| 6084 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6085 | // The back edge will generate the suspend check. |
| 6086 | return; |
| 6087 | } |
| 6088 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6089 | // The goto will generate the suspend check. |
| 6090 | return; |
| 6091 | } |
| 6092 | GenerateSuspendCheck(instruction, nullptr); |
| 6093 | } |
| 6094 | |
| 6095 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6096 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6097 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6098 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6099 | if (slow_path == nullptr) { |
| 6100 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6101 | instruction->SetSlowPath(slow_path); |
| 6102 | codegen_->AddSlowPath(slow_path); |
| 6103 | if (successor != nullptr) { |
| 6104 | DCHECK(successor->IsLoopHeader()); |
| 6105 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6106 | } |
| 6107 | } else { |
| 6108 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6109 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6110 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6111 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6112 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6113 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6114 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6115 | __ Bind(slow_path->GetReturnLabel()); |
| 6116 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6117 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6118 | __ b(slow_path->GetEntryLabel()); |
| 6119 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6120 | } |
| 6121 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6122 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6123 | return codegen_->GetAssembler(); |
| 6124 | } |
| 6125 | |
| 6126 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6127 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6128 | Location source = move->GetSource(); |
| 6129 | Location destination = move->GetDestination(); |
| 6130 | |
| 6131 | if (source.IsRegister()) { |
| 6132 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6133 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6134 | } else if (destination.IsFpuRegister()) { |
| 6135 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6136 | } else { |
| 6137 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6138 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6139 | SP, destination.GetStackIndex()); |
| 6140 | } |
| 6141 | } else if (source.IsStackSlot()) { |
| 6142 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6143 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6144 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6145 | } else if (destination.IsFpuRegister()) { |
| 6146 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6147 | } else { |
| 6148 | DCHECK(destination.IsStackSlot()); |
| 6149 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6150 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6151 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6152 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6153 | if (destination.IsRegister()) { |
| 6154 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6155 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6156 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6157 | } else { |
| 6158 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6159 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6160 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6161 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6162 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6163 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6164 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6165 | } else if (destination.IsRegisterPair()) { |
| 6166 | DCHECK(ExpectedPairLayout(destination)); |
| 6167 | __ LoadFromOffset( |
| 6168 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6169 | } else { |
| 6170 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6171 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6172 | SP, |
| 6173 | source.GetStackIndex()); |
| 6174 | } |
| 6175 | } else if (source.IsRegisterPair()) { |
| 6176 | if (destination.IsRegisterPair()) { |
| 6177 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6178 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6179 | } else if (destination.IsFpuRegisterPair()) { |
| 6180 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6181 | source.AsRegisterPairLow<Register>(), |
| 6182 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6183 | } else { |
| 6184 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6185 | DCHECK(ExpectedPairLayout(source)); |
| 6186 | __ StoreToOffset( |
| 6187 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6188 | } |
| 6189 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6190 | if (destination.IsRegisterPair()) { |
| 6191 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6192 | destination.AsRegisterPairHigh<Register>(), |
| 6193 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6194 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6195 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6196 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6197 | } else { |
| 6198 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6199 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6200 | SP, |
| 6201 | destination.GetStackIndex()); |
| 6202 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6203 | } else { |
| 6204 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6205 | HConstant* constant = source.GetConstant(); |
| 6206 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6207 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6208 | if (destination.IsRegister()) { |
| 6209 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6210 | } else { |
| 6211 | DCHECK(destination.IsStackSlot()); |
| 6212 | __ LoadImmediate(IP, value); |
| 6213 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6214 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6215 | } else if (constant->IsLongConstant()) { |
| 6216 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6217 | if (destination.IsRegisterPair()) { |
| 6218 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6219 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6220 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6221 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6222 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6223 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6224 | __ LoadImmediate(IP, High32Bits(value)); |
| 6225 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6226 | } |
| 6227 | } else if (constant->IsDoubleConstant()) { |
| 6228 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6229 | if (destination.IsFpuRegisterPair()) { |
| 6230 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6231 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6232 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6233 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6234 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 6235 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6236 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 6237 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6238 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6239 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6240 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6241 | float value = constant->AsFloatConstant()->GetValue(); |
| 6242 | if (destination.IsFpuRegister()) { |
| 6243 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 6244 | } else { |
| 6245 | DCHECK(destination.IsStackSlot()); |
| 6246 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 6247 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6248 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6249 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6250 | } |
| 6251 | } |
| 6252 | |
| 6253 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 6254 | __ Mov(IP, reg); |
| 6255 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 6256 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 6257 | } |
| 6258 | |
| 6259 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 6260 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 6261 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6262 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6263 | SP, mem1 + stack_offset); |
| 6264 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 6265 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6266 | SP, mem2 + stack_offset); |
| 6267 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 6268 | } |
| 6269 | |
| 6270 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6271 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6272 | Location source = move->GetSource(); |
| 6273 | Location destination = move->GetDestination(); |
| 6274 | |
| 6275 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6276 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 6277 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 6278 | __ Mov(IP, source.AsRegister<Register>()); |
| 6279 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6280 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6281 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6282 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6283 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6284 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6285 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 6286 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6287 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6288 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6289 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6290 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6291 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6292 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6293 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6294 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6295 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6296 | destination.AsRegisterPairHigh<Register>(), |
| 6297 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6298 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6299 | Register low_reg = source.IsRegisterPair() |
| 6300 | ? source.AsRegisterPairLow<Register>() |
| 6301 | : destination.AsRegisterPairLow<Register>(); |
| 6302 | int mem = source.IsRegisterPair() |
| 6303 | ? destination.GetStackIndex() |
| 6304 | : source.GetStackIndex(); |
| 6305 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6306 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6307 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6308 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6309 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6310 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 6311 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6312 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6313 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6314 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6315 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 6316 | DRegister reg = source.IsFpuRegisterPair() |
| 6317 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 6318 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 6319 | int mem = source.IsFpuRegisterPair() |
| 6320 | ? destination.GetStackIndex() |
| 6321 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6322 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6323 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6324 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6325 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 6326 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 6327 | : destination.AsFpuRegister<SRegister>(); |
| 6328 | int mem = source.IsFpuRegister() |
| 6329 | ? destination.GetStackIndex() |
| 6330 | : source.GetStackIndex(); |
| 6331 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6332 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6333 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6334 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6335 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6336 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 6337 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6338 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6339 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6340 | } |
| 6341 | } |
| 6342 | |
| 6343 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 6344 | __ Push(static_cast<Register>(reg)); |
| 6345 | } |
| 6346 | |
| 6347 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 6348 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6349 | } |
| 6350 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6351 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 6352 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6353 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6354 | case HLoadClass::LoadKind::kInvalid: |
| 6355 | LOG(FATAL) << "UNREACHABLE"; |
| 6356 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6357 | case HLoadClass::LoadKind::kReferrersClass: |
| 6358 | break; |
| 6359 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6360 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6361 | break; |
| 6362 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6363 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6364 | break; |
| 6365 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6366 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6367 | case HLoadClass::LoadKind::kBssEntry: |
| 6368 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6369 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6370 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6371 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6372 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6373 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6374 | break; |
| 6375 | } |
| 6376 | return desired_class_load_kind; |
| 6377 | } |
| 6378 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6379 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6380 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6381 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6382 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6383 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6384 | cls, |
| 6385 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6386 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6387 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6388 | return; |
| 6389 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6390 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6391 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6392 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6393 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6394 | ? LocationSummary::kCallOnSlowPath |
| 6395 | : LocationSummary::kNoCall; |
| 6396 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6397 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6398 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6399 | } |
| 6400 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6401 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6403 | } |
| 6404 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6405 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6406 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6407 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6408 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6409 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6410 | locations->AddTemp(Location::RequiresRegister()); |
| 6411 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6412 | InvokeRuntimeCallingConvention calling_convention; |
| 6413 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6414 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6415 | // that the the kPrimNot result register is the same as the first argument register. |
| 6416 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6417 | } else { |
| 6418 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6419 | } |
| 6420 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6421 | } |
| 6422 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6423 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6424 | // move. |
| 6425 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6426 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6427 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6428 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6429 | return; |
| 6430 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6431 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6432 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6433 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6434 | Location out_loc = locations->Out(); |
| 6435 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6436 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6437 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6438 | ? kWithoutReadBarrier |
| 6439 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6440 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6441 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6442 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6443 | DCHECK(!cls->CanCallRuntime()); |
| 6444 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6445 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6446 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6447 | GenerateGcRootFieldLoad(cls, |
| 6448 | out_loc, |
| 6449 | current_method, |
| 6450 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6451 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6452 | break; |
| 6453 | } |
| 6454 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6455 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6456 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6457 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6458 | cls->GetTypeIndex())); |
| 6459 | break; |
| 6460 | } |
| 6461 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6462 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6463 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6464 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6465 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6466 | __ BindTrackedLabel(&labels->movw_label); |
| 6467 | __ movw(out, /* placeholder */ 0u); |
| 6468 | __ BindTrackedLabel(&labels->movt_label); |
| 6469 | __ movt(out, /* placeholder */ 0u); |
| 6470 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6471 | __ add(out, out, ShifterOperand(PC)); |
| 6472 | break; |
| 6473 | } |
| 6474 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6475 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6476 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6477 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6478 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6479 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6480 | break; |
| 6481 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6482 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6483 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6484 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6485 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6486 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6487 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6488 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6489 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6490 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6491 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6492 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6493 | __ add(temp, temp, ShifterOperand(PC)); |
| 6494 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6495 | generate_null_check = true; |
| 6496 | break; |
| 6497 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6498 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6499 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6500 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6501 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6502 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6503 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6504 | break; |
| 6505 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6506 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6507 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6508 | LOG(FATAL) << "UNREACHABLE"; |
| 6509 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6510 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6511 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6512 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6513 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6514 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6515 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6516 | codegen_->AddSlowPath(slow_path); |
| 6517 | if (generate_null_check) { |
| 6518 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6519 | } |
| 6520 | if (cls->MustGenerateClinitCheck()) { |
| 6521 | GenerateClassInitializationCheck(slow_path, out); |
| 6522 | } else { |
| 6523 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6524 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6529 | LocationSummary* locations = |
| 6530 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6531 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6532 | if (check->HasUses()) { |
| 6533 | locations->SetOut(Location::SameAsFirstInput()); |
| 6534 | } |
| 6535 | } |
| 6536 | |
| 6537 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6538 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6539 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6540 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6541 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6542 | GenerateClassInitializationCheck(slow_path, |
| 6543 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6544 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6545 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6546 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6547 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6548 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6549 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6550 | __ b(slow_path->GetEntryLabel(), LT); |
| 6551 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6552 | // properly. Therefore, we do a memory fence. |
| 6553 | __ dmb(ISH); |
| 6554 | __ Bind(slow_path->GetExitLabel()); |
| 6555 | } |
| 6556 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6557 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6558 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6559 | switch (desired_string_load_kind) { |
| 6560 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6561 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6562 | break; |
| 6563 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6564 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6565 | break; |
| 6566 | case HLoadString::LoadKind::kBootImageAddress: |
| 6567 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6568 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6569 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6570 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6571 | case HLoadString::LoadKind::kJitTableAddress: |
| 6572 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6573 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6574 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6575 | break; |
| 6576 | } |
| 6577 | return desired_string_load_kind; |
| 6578 | } |
| 6579 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6580 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6581 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6582 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6583 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6584 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6585 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6586 | } else { |
| 6587 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6588 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6589 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6590 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6591 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6592 | // to the custom calling convention) or by marking, so we request a different temp. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6593 | locations->AddTemp(Location::RequiresRegister()); |
| 6594 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6595 | InvokeRuntimeCallingConvention calling_convention; |
| 6596 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6597 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6598 | // that the the kPrimNot result register is the same as the first argument register. |
| 6599 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6600 | } else { |
| 6601 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6602 | } |
| 6603 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6604 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6607 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6608 | // move. |
| 6609 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6610 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6611 | Location out_loc = locations->Out(); |
| 6612 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6613 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6614 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6615 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6616 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6617 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6618 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6619 | load->GetStringIndex())); |
| 6620 | return; // No dex cache slow path. |
| 6621 | } |
| 6622 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6623 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6624 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6625 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6626 | __ BindTrackedLabel(&labels->movw_label); |
| 6627 | __ movw(out, /* placeholder */ 0u); |
| 6628 | __ BindTrackedLabel(&labels->movt_label); |
| 6629 | __ movt(out, /* placeholder */ 0u); |
| 6630 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6631 | __ add(out, out, ShifterOperand(PC)); |
| 6632 | return; // No dex cache slow path. |
| 6633 | } |
| 6634 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6635 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6636 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6637 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6638 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6639 | return; // No dex cache slow path. |
| 6640 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6641 | case HLoadString::LoadKind::kBssEntry: { |
| 6642 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6643 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6644 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6645 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6646 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6647 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6648 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6649 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6650 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6651 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6652 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6653 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6654 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6655 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 6656 | codegen_->AddSlowPath(slow_path); |
| 6657 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6658 | __ Bind(slow_path->GetExitLabel()); |
| 6659 | return; |
| 6660 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6661 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6662 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6663 | load->GetStringIndex(), |
| 6664 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6665 | // /* GcRoot<mirror::String> */ out = *out |
| 6666 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6667 | return; |
| 6668 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6669 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6670 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6671 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6672 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6673 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6674 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6675 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6676 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6677 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6678 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6679 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6680 | } |
| 6681 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6682 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6683 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6684 | } |
| 6685 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6686 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6687 | LocationSummary* locations = |
| 6688 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6689 | locations->SetOut(Location::RequiresRegister()); |
| 6690 | } |
| 6691 | |
| 6692 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6693 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6694 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6695 | } |
| 6696 | |
| 6697 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6698 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6699 | } |
| 6700 | |
| 6701 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6702 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6703 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6707 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6708 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6709 | InvokeRuntimeCallingConvention calling_convention; |
| 6710 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6711 | } |
| 6712 | |
| 6713 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6714 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6715 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6716 | } |
| 6717 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6718 | // Temp is used for read barrier. |
| 6719 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6720 | if (kEmitCompilerReadBarrier && |
| 6721 | (kUseBakerReadBarrier || |
| 6722 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6723 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6724 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6725 | return 1; |
| 6726 | } |
| 6727 | return 0; |
| 6728 | } |
| 6729 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6730 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6731 | // interface pointer, one for loading the current interface. |
| 6732 | // The other checks have one temp for loading the object's class. |
| 6733 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6734 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6735 | return 3; |
| 6736 | } |
| 6737 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6738 | } |
| 6739 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6740 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6741 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6742 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6743 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6744 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6745 | case TypeCheckKind::kExactCheck: |
| 6746 | case TypeCheckKind::kAbstractClassCheck: |
| 6747 | case TypeCheckKind::kClassHierarchyCheck: |
| 6748 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6749 | call_kind = |
| 6750 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6751 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6752 | break; |
| 6753 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6754 | case TypeCheckKind::kUnresolvedCheck: |
| 6755 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6756 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6757 | break; |
| 6758 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6759 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6760 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6761 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6762 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6763 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6764 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6765 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6766 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6767 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6768 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6769 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6770 | } |
| 6771 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6772 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6773 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6774 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6775 | Location obj_loc = locations->InAt(0); |
| 6776 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6777 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6778 | Location out_loc = locations->Out(); |
| 6779 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6780 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6781 | DCHECK_LE(num_temps, 1u); |
| 6782 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6783 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6784 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6785 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6786 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6787 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6788 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6789 | |
| 6790 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6791 | // avoid null check if we know obj is not null. |
| 6792 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6793 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6794 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6795 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6796 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6797 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6798 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6799 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6800 | out_loc, |
| 6801 | obj_loc, |
| 6802 | class_offset, |
| 6803 | maybe_temp_loc, |
| 6804 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6805 | __ cmp(out, ShifterOperand(cls)); |
| 6806 | // Classes must be equal for the instanceof to succeed. |
| 6807 | __ b(&zero, NE); |
| 6808 | __ LoadImmediate(out, 1); |
| 6809 | __ b(&done); |
| 6810 | break; |
| 6811 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6812 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6813 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6814 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6815 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6816 | out_loc, |
| 6817 | obj_loc, |
| 6818 | class_offset, |
| 6819 | maybe_temp_loc, |
| 6820 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6821 | // If the class is abstract, we eagerly fetch the super class of the |
| 6822 | // object to avoid doing a comparison we know will fail. |
| 6823 | Label loop; |
| 6824 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6825 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6826 | GenerateReferenceLoadOneRegister(instruction, |
| 6827 | out_loc, |
| 6828 | super_offset, |
| 6829 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6830 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6831 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6832 | __ CompareAndBranchIfZero(out, &done); |
| 6833 | __ cmp(out, ShifterOperand(cls)); |
| 6834 | __ b(&loop, NE); |
| 6835 | __ LoadImmediate(out, 1); |
| 6836 | if (zero.IsLinked()) { |
| 6837 | __ b(&done); |
| 6838 | } |
| 6839 | break; |
| 6840 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6841 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6842 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6843 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6844 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6845 | out_loc, |
| 6846 | obj_loc, |
| 6847 | class_offset, |
| 6848 | maybe_temp_loc, |
| 6849 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6850 | // Walk over the class hierarchy to find a match. |
| 6851 | Label loop, success; |
| 6852 | __ Bind(&loop); |
| 6853 | __ cmp(out, ShifterOperand(cls)); |
| 6854 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6855 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6856 | GenerateReferenceLoadOneRegister(instruction, |
| 6857 | out_loc, |
| 6858 | super_offset, |
| 6859 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6860 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6861 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6862 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6863 | __ b(&done); |
| 6864 | __ Bind(&success); |
| 6865 | __ LoadImmediate(out, 1); |
| 6866 | if (zero.IsLinked()) { |
| 6867 | __ b(&done); |
| 6868 | } |
| 6869 | break; |
| 6870 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6871 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6872 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6873 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6874 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6875 | out_loc, |
| 6876 | obj_loc, |
| 6877 | class_offset, |
| 6878 | maybe_temp_loc, |
| 6879 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6880 | // Do an exact check. |
| 6881 | Label exact_check; |
| 6882 | __ cmp(out, ShifterOperand(cls)); |
| 6883 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6884 | // 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] | 6885 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6886 | GenerateReferenceLoadOneRegister(instruction, |
| 6887 | out_loc, |
| 6888 | component_offset, |
| 6889 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6890 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6891 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6892 | __ CompareAndBranchIfZero(out, &done); |
| 6893 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6894 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6895 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6896 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6897 | __ LoadImmediate(out, 1); |
| 6898 | __ b(&done); |
| 6899 | break; |
| 6900 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6901 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6902 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6903 | // No read barrier since the slow path will retry upon failure. |
| 6904 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6905 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6906 | out_loc, |
| 6907 | obj_loc, |
| 6908 | class_offset, |
| 6909 | maybe_temp_loc, |
| 6910 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6911 | __ cmp(out, ShifterOperand(cls)); |
| 6912 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6913 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6914 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6915 | codegen_->AddSlowPath(slow_path); |
| 6916 | __ b(slow_path->GetEntryLabel(), NE); |
| 6917 | __ LoadImmediate(out, 1); |
| 6918 | if (zero.IsLinked()) { |
| 6919 | __ b(&done); |
| 6920 | } |
| 6921 | break; |
| 6922 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6923 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6924 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6925 | case TypeCheckKind::kInterfaceCheck: { |
| 6926 | // 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] | 6927 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6928 | // cases. |
| 6929 | // |
| 6930 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6931 | // entry point without resorting to a type checking slow path |
| 6932 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6933 | // require to assign fixed registers for the inputs of this |
| 6934 | // HInstanceOf instruction (following the runtime calling |
| 6935 | // convention), which might be cluttered by the potential first |
| 6936 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6937 | // |
| 6938 | // TODO: Introduce a new runtime entry point taking the object |
| 6939 | // to test (instead of its class) as argument, and let it deal |
| 6940 | // with the read barrier issues. This will let us refactor this |
| 6941 | // case of the `switch` code as it was previously (with a direct |
| 6942 | // call to the runtime not using a type checking slow path). |
| 6943 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6944 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6945 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6946 | /* is_fatal */ false); |
| 6947 | codegen_->AddSlowPath(slow_path); |
| 6948 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6949 | if (zero.IsLinked()) { |
| 6950 | __ b(&done); |
| 6951 | } |
| 6952 | break; |
| 6953 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6954 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6955 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6956 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6957 | __ Bind(&zero); |
| 6958 | __ LoadImmediate(out, 0); |
| 6959 | } |
| 6960 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6961 | if (done.IsLinked()) { |
| 6962 | __ Bind(&done); |
| 6963 | } |
| 6964 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6965 | if (slow_path != nullptr) { |
| 6966 | __ Bind(slow_path->GetExitLabel()); |
| 6967 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6970 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6971 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6972 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6973 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6974 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6975 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6976 | case TypeCheckKind::kExactCheck: |
| 6977 | case TypeCheckKind::kAbstractClassCheck: |
| 6978 | case TypeCheckKind::kClassHierarchyCheck: |
| 6979 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6980 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6981 | LocationSummary::kCallOnSlowPath : |
| 6982 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6983 | break; |
| 6984 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6985 | case TypeCheckKind::kUnresolvedCheck: |
| 6986 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6987 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6988 | break; |
| 6989 | } |
| 6990 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6991 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6992 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6993 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6994 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6995 | } |
| 6996 | |
| 6997 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6998 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6999 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7000 | Location obj_loc = locations->InAt(0); |
| 7001 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7002 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7003 | Location temp_loc = locations->GetTemp(0); |
| 7004 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7005 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7006 | DCHECK_LE(num_temps, 3u); |
| 7007 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7008 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7009 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7010 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7011 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7012 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7013 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7014 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7015 | const uint32_t object_array_data_offset = |
| 7016 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7017 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7018 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7019 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7020 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7021 | bool is_type_check_slow_path_fatal = false; |
| 7022 | if (!kEmitCompilerReadBarrier) { |
| 7023 | is_type_check_slow_path_fatal = |
| 7024 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7025 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7026 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7027 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7028 | !instruction->CanThrowIntoCatchBlock(); |
| 7029 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7030 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7031 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7032 | is_type_check_slow_path_fatal); |
| 7033 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7034 | |
| 7035 | Label done; |
| 7036 | // Avoid null check if we know obj is not null. |
| 7037 | if (instruction->MustDoNullCheck()) { |
| 7038 | __ CompareAndBranchIfZero(obj, &done); |
| 7039 | } |
| 7040 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7041 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7042 | case TypeCheckKind::kExactCheck: |
| 7043 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7044 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7045 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7046 | temp_loc, |
| 7047 | obj_loc, |
| 7048 | class_offset, |
| 7049 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7050 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7051 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7052 | __ cmp(temp, ShifterOperand(cls)); |
| 7053 | // Jump to slow path for throwing the exception or doing a |
| 7054 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7055 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7056 | break; |
| 7057 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7058 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7059 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7060 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7061 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7062 | temp_loc, |
| 7063 | obj_loc, |
| 7064 | class_offset, |
| 7065 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7066 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7067 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7068 | // If the class is abstract, we eagerly fetch the super class of the |
| 7069 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7070 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7071 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7072 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7073 | GenerateReferenceLoadOneRegister(instruction, |
| 7074 | temp_loc, |
| 7075 | super_offset, |
| 7076 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7077 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7078 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7079 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7080 | // exception. |
| 7081 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7082 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7083 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7084 | __ cmp(temp, ShifterOperand(cls)); |
| 7085 | __ b(&loop, NE); |
| 7086 | break; |
| 7087 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7088 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7089 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7090 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7091 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7092 | temp_loc, |
| 7093 | obj_loc, |
| 7094 | class_offset, |
| 7095 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7096 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7097 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7098 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7099 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7100 | __ Bind(&loop); |
| 7101 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7102 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7103 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7104 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7105 | GenerateReferenceLoadOneRegister(instruction, |
| 7106 | temp_loc, |
| 7107 | super_offset, |
| 7108 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7109 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7110 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7111 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7112 | // exception. |
| 7113 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7114 | // Otherwise, jump to the beginning of the loop. |
| 7115 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7116 | break; |
| 7117 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7118 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7119 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7120 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7121 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7122 | temp_loc, |
| 7123 | obj_loc, |
| 7124 | class_offset, |
| 7125 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7126 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7127 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7128 | // Do an exact check. |
| 7129 | __ cmp(temp, ShifterOperand(cls)); |
| 7130 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7131 | |
| 7132 | // 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] | 7133 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7134 | GenerateReferenceLoadOneRegister(instruction, |
| 7135 | temp_loc, |
| 7136 | component_offset, |
| 7137 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7138 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7139 | // If the component type is null, jump to the slow path to throw the exception. |
| 7140 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7141 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7142 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7143 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7144 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7145 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7146 | break; |
| 7147 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7148 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7149 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7150 | // We always go into the type check slow path for the unresolved check case. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7151 | // We cannot directly call the CheckCast runtime entry point |
| 7152 | // without resorting to a type checking slow path here (i.e. by |
| 7153 | // calling InvokeRuntime directly), as it would require to |
| 7154 | // assign fixed registers for the inputs of this HInstanceOf |
| 7155 | // instruction (following the runtime calling convention), which |
| 7156 | // might be cluttered by the potential first read barrier |
| 7157 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7158 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7159 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7160 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7161 | |
| 7162 | case TypeCheckKind::kInterfaceCheck: { |
| 7163 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7164 | // positives by doing this. |
| 7165 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7166 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7167 | temp_loc, |
| 7168 | obj_loc, |
| 7169 | class_offset, |
| 7170 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7171 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7172 | |
| 7173 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7174 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7175 | temp_loc, |
| 7176 | temp_loc, |
| 7177 | iftable_offset, |
| 7178 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7179 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7180 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7181 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7182 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7183 | Label start_loop; |
| 7184 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7185 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7186 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7187 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7188 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7189 | // Go to next interface. |
| 7190 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7191 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7192 | maybe_temp2_loc.AsRegister<Register>(), |
| 7193 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7194 | // Compare the classes and continue the loop if they do not match. |
| 7195 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7196 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7197 | break; |
| 7198 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7199 | } |
| 7200 | __ Bind(&done); |
| 7201 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7202 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7203 | } |
| 7204 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7205 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7206 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7207 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7208 | InvokeRuntimeCallingConvention calling_convention; |
| 7209 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7210 | } |
| 7211 | |
| 7212 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7213 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7214 | instruction, |
| 7215 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7216 | if (instruction->IsEnter()) { |
| 7217 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7218 | } else { |
| 7219 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7220 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7223 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 7224 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 7225 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7226 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7227 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7228 | LocationSummary* locations = |
| 7229 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7230 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7231 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7232 | // 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] | 7233 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7234 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 7235 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 7239 | HandleBitwiseOperation(instruction); |
| 7240 | } |
| 7241 | |
| 7242 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 7243 | HandleBitwiseOperation(instruction); |
| 7244 | } |
| 7245 | |
| 7246 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 7247 | HandleBitwiseOperation(instruction); |
| 7248 | } |
| 7249 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 7250 | |
| 7251 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7252 | LocationSummary* locations = |
| 7253 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7254 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7255 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7256 | |
| 7257 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7258 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7259 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7260 | } |
| 7261 | |
| 7262 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7263 | LocationSummary* locations = instruction->GetLocations(); |
| 7264 | Location first = locations->InAt(0); |
| 7265 | Location second = locations->InAt(1); |
| 7266 | Location out = locations->Out(); |
| 7267 | |
| 7268 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7269 | Register first_reg = first.AsRegister<Register>(); |
| 7270 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7271 | Register out_reg = out.AsRegister<Register>(); |
| 7272 | |
| 7273 | switch (instruction->GetOpKind()) { |
| 7274 | case HInstruction::kAnd: |
| 7275 | __ bic(out_reg, first_reg, second_reg); |
| 7276 | break; |
| 7277 | case HInstruction::kOr: |
| 7278 | __ orn(out_reg, first_reg, second_reg); |
| 7279 | break; |
| 7280 | // There is no EON on arm. |
| 7281 | case HInstruction::kXor: |
| 7282 | default: |
| 7283 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7284 | UNREACHABLE(); |
| 7285 | } |
| 7286 | return; |
| 7287 | |
| 7288 | } else { |
| 7289 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7290 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7291 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7292 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7293 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7294 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7295 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7296 | |
| 7297 | switch (instruction->GetOpKind()) { |
| 7298 | case HInstruction::kAnd: |
| 7299 | __ bic(out_low, first_low, second_low); |
| 7300 | __ bic(out_high, first_high, second_high); |
| 7301 | break; |
| 7302 | case HInstruction::kOr: |
| 7303 | __ orn(out_low, first_low, second_low); |
| 7304 | __ orn(out_high, first_high, second_high); |
| 7305 | break; |
| 7306 | // There is no EON on arm. |
| 7307 | case HInstruction::kXor: |
| 7308 | default: |
| 7309 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7310 | UNREACHABLE(); |
| 7311 | } |
| 7312 | } |
| 7313 | } |
| 7314 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7315 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 7316 | HDataProcWithShifterOp* instruction) { |
| 7317 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7318 | instruction->GetType() == Primitive::kPrimLong); |
| 7319 | LocationSummary* locations = |
| 7320 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7321 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7322 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7323 | |
| 7324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7325 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7326 | locations->SetOut(Location::RequiresRegister(), |
| 7327 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7328 | } |
| 7329 | |
| 7330 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 7331 | HDataProcWithShifterOp* instruction) { |
| 7332 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7333 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7334 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7335 | const Location left = locations->InAt(0); |
| 7336 | const Location right = locations->InAt(1); |
| 7337 | const Location out = locations->Out(); |
| 7338 | |
| 7339 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7340 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7341 | |
| 7342 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7343 | ? right.AsRegisterPairLow<Register>() |
| 7344 | : right.AsRegister<Register>(); |
| 7345 | |
| 7346 | GenerateDataProcInstruction(kind, |
| 7347 | out.AsRegister<Register>(), |
| 7348 | left.AsRegister<Register>(), |
| 7349 | ShifterOperand(second, |
| 7350 | ShiftFromOpKind(op_kind), |
| 7351 | instruction->GetShiftAmount()), |
| 7352 | codegen_); |
| 7353 | } else { |
| 7354 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7355 | |
| 7356 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7357 | const Register second = right.AsRegister<Register>(); |
| 7358 | |
| 7359 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 7360 | GenerateDataProc(kind, |
| 7361 | out, |
| 7362 | left, |
| 7363 | ShifterOperand(second), |
| 7364 | ShifterOperand(second, ASR, 31), |
| 7365 | codegen_); |
| 7366 | } else { |
| 7367 | GenerateLongDataProc(instruction, codegen_); |
| 7368 | } |
| 7369 | } |
| 7370 | } |
| 7371 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7372 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 7373 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7374 | if (value == 0xffffffffu) { |
| 7375 | if (out != first) { |
| 7376 | __ mov(out, ShifterOperand(first)); |
| 7377 | } |
| 7378 | return; |
| 7379 | } |
| 7380 | if (value == 0u) { |
| 7381 | __ mov(out, ShifterOperand(0)); |
| 7382 | return; |
| 7383 | } |
| 7384 | ShifterOperand so; |
| 7385 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 7386 | __ and_(out, first, so); |
| 7387 | } else { |
| 7388 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 7389 | __ bic(out, first, ShifterOperand(~value)); |
| 7390 | } |
| 7391 | } |
| 7392 | |
| 7393 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 7394 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7395 | if (value == 0u) { |
| 7396 | if (out != first) { |
| 7397 | __ mov(out, ShifterOperand(first)); |
| 7398 | } |
| 7399 | return; |
| 7400 | } |
| 7401 | if (value == 0xffffffffu) { |
| 7402 | __ mvn(out, ShifterOperand(0)); |
| 7403 | return; |
| 7404 | } |
| 7405 | ShifterOperand so; |
| 7406 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 7407 | __ orr(out, first, so); |
| 7408 | } else { |
| 7409 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 7410 | __ orn(out, first, ShifterOperand(~value)); |
| 7411 | } |
| 7412 | } |
| 7413 | |
| 7414 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7415 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7416 | if (value == 0u) { |
| 7417 | if (out != first) { |
| 7418 | __ mov(out, ShifterOperand(first)); |
| 7419 | } |
| 7420 | return; |
| 7421 | } |
| 7422 | __ eor(out, first, ShifterOperand(value)); |
| 7423 | } |
| 7424 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7425 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7426 | Location first, |
| 7427 | uint64_t value) { |
| 7428 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7429 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7430 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7431 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7432 | uint32_t value_low = Low32Bits(value); |
| 7433 | uint32_t value_high = High32Bits(value); |
| 7434 | if (value_low == 0u) { |
| 7435 | if (out_low != first_low) { |
| 7436 | __ mov(out_low, ShifterOperand(first_low)); |
| 7437 | } |
| 7438 | __ AddConstant(out_high, first_high, value_high); |
| 7439 | return; |
| 7440 | } |
| 7441 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7442 | ShifterOperand so; |
| 7443 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7444 | __ adc(out_high, first_high, so); |
| 7445 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7446 | __ sbc(out_high, first_high, so); |
| 7447 | } else { |
| 7448 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7449 | UNREACHABLE(); |
| 7450 | } |
| 7451 | } |
| 7452 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7453 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7454 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7455 | Location first = locations->InAt(0); |
| 7456 | Location second = locations->InAt(1); |
| 7457 | Location out = locations->Out(); |
| 7458 | |
| 7459 | if (second.IsConstant()) { |
| 7460 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7461 | uint32_t value_low = Low32Bits(value); |
| 7462 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7463 | Register first_reg = first.AsRegister<Register>(); |
| 7464 | Register out_reg = out.AsRegister<Register>(); |
| 7465 | if (instruction->IsAnd()) { |
| 7466 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7467 | } else if (instruction->IsOr()) { |
| 7468 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7469 | } else { |
| 7470 | DCHECK(instruction->IsXor()); |
| 7471 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7472 | } |
| 7473 | } else { |
| 7474 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7475 | uint32_t value_high = High32Bits(value); |
| 7476 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7477 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7478 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7479 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7480 | if (instruction->IsAnd()) { |
| 7481 | GenerateAndConst(out_low, first_low, value_low); |
| 7482 | GenerateAndConst(out_high, first_high, value_high); |
| 7483 | } else if (instruction->IsOr()) { |
| 7484 | GenerateOrrConst(out_low, first_low, value_low); |
| 7485 | GenerateOrrConst(out_high, first_high, value_high); |
| 7486 | } else { |
| 7487 | DCHECK(instruction->IsXor()); |
| 7488 | GenerateEorConst(out_low, first_low, value_low); |
| 7489 | GenerateEorConst(out_high, first_high, value_high); |
| 7490 | } |
| 7491 | } |
| 7492 | return; |
| 7493 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7494 | |
| 7495 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7496 | Register first_reg = first.AsRegister<Register>(); |
| 7497 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7498 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7499 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7500 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7501 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7502 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7503 | } else { |
| 7504 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7505 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7506 | } |
| 7507 | } else { |
| 7508 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7509 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7510 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7511 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7512 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7513 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7514 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7515 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7516 | __ and_(out_low, first_low, second_low); |
| 7517 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7518 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7519 | __ orr(out_low, first_low, second_low); |
| 7520 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7521 | } else { |
| 7522 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7523 | __ eor(out_low, first_low, second_low); |
| 7524 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7525 | } |
| 7526 | } |
| 7527 | } |
| 7528 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7529 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7530 | HInstruction* instruction, |
| 7531 | Location out, |
| 7532 | uint32_t offset, |
| 7533 | Location maybe_temp, |
| 7534 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7535 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7536 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7537 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7538 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7539 | if (kUseBakerReadBarrier) { |
| 7540 | // Load with fast path based Baker's read barrier. |
| 7541 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7542 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7543 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7544 | } else { |
| 7545 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7546 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7547 | // in the following move operation, as we will need it for the |
| 7548 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7549 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7550 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7551 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7552 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7553 | } |
| 7554 | } else { |
| 7555 | // Plain load with no read barrier. |
| 7556 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7557 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7558 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7559 | } |
| 7560 | } |
| 7561 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7562 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7563 | HInstruction* instruction, |
| 7564 | Location out, |
| 7565 | Location obj, |
| 7566 | uint32_t offset, |
| 7567 | Location maybe_temp, |
| 7568 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7569 | Register out_reg = out.AsRegister<Register>(); |
| 7570 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7571 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7572 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7573 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7574 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7575 | // Load with fast path based Baker's read barrier. |
| 7576 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7577 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7578 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7579 | } else { |
| 7580 | // Load with slow path based read barrier. |
| 7581 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7582 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7583 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7584 | } |
| 7585 | } else { |
| 7586 | // Plain load with no read barrier. |
| 7587 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7588 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7589 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7590 | } |
| 7591 | } |
| 7592 | |
| 7593 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7594 | Location root, |
| 7595 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7596 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7597 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7598 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7599 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7600 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7601 | if (kUseBakerReadBarrier) { |
| 7602 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7603 | // Baker's read barrier are used: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7604 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7605 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7606 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7607 | // if (temp != null) { |
| 7608 | // root = temp(root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7609 | // } |
| 7610 | |
| 7611 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7612 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7613 | static_assert( |
| 7614 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7615 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7616 | "have different sizes."); |
| 7617 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7618 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7619 | "have different sizes."); |
| 7620 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7621 | // Slow path marking the GC root `root`. |
| 7622 | Location temp = Location::RegisterLocation(LR); |
| 7623 | SlowPathCodeARM* slow_path = |
| 7624 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 7625 | instruction, |
| 7626 | root, |
| 7627 | /*entrypoint*/ temp); |
| 7628 | codegen_->AddSlowPath(slow_path); |
| 7629 | |
| 7630 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7631 | const int32_t entry_point_offset = |
| 7632 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 7633 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7634 | // threads are suspended or running a checkpoint. |
| 7635 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7636 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 7637 | // checking GetIsGcMarking. |
| 7638 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7639 | __ Bind(slow_path->GetExitLabel()); |
| 7640 | } else { |
| 7641 | // GC root loaded through a slow path for read barriers other |
| 7642 | // than Baker's. |
| 7643 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7644 | __ AddConstant(root_reg, obj, offset); |
| 7645 | // /* mirror::Object* */ root = root->Read() |
| 7646 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7647 | } |
| 7648 | } else { |
| 7649 | // Plain GC root load with no read barrier. |
| 7650 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7651 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7652 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7653 | // do not have to unpoison `root_reg` here. |
| 7654 | } |
| 7655 | } |
| 7656 | |
| 7657 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7658 | Location ref, |
| 7659 | Register obj, |
| 7660 | uint32_t offset, |
| 7661 | Location temp, |
| 7662 | bool needs_null_check) { |
| 7663 | DCHECK(kEmitCompilerReadBarrier); |
| 7664 | DCHECK(kUseBakerReadBarrier); |
| 7665 | |
| 7666 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7667 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7668 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7669 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7670 | 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] | 7671 | } |
| 7672 | |
| 7673 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7674 | Location ref, |
| 7675 | Register obj, |
| 7676 | uint32_t data_offset, |
| 7677 | Location index, |
| 7678 | Location temp, |
| 7679 | bool needs_null_check) { |
| 7680 | DCHECK(kEmitCompilerReadBarrier); |
| 7681 | DCHECK(kUseBakerReadBarrier); |
| 7682 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7683 | static_assert( |
| 7684 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7685 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7686 | // /* HeapReference<Object> */ ref = |
| 7687 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7688 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7689 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7690 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7691 | } |
| 7692 | |
| 7693 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7694 | Location ref, |
| 7695 | Register obj, |
| 7696 | uint32_t offset, |
| 7697 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7698 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7699 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7700 | bool needs_null_check, |
| 7701 | bool always_update_field, |
| 7702 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7703 | DCHECK(kEmitCompilerReadBarrier); |
| 7704 | DCHECK(kUseBakerReadBarrier); |
| 7705 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7706 | // In slow path based read barriers, the read barrier call is |
| 7707 | // inserted after the original load. However, in fast path based |
| 7708 | // Baker's read barriers, we need to perform the load of |
| 7709 | // mirror::Object::monitor_ *before* the original reference load. |
| 7710 | // This load-load ordering is required by the read barrier. |
| 7711 | // The fast path/slow path (for Baker's algorithm) should look like: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7712 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7713 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7714 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7715 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7716 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7717 | // if (is_gray) { |
| 7718 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7719 | // } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7720 | // |
| 7721 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7722 | // slightly more complex as it performs additional checks that we do |
| 7723 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7724 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7725 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7726 | Register temp_reg = temp.AsRegister<Register>(); |
| 7727 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7728 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7729 | // /* int32_t */ monitor = obj->monitor_ |
| 7730 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7731 | if (needs_null_check) { |
| 7732 | MaybeRecordImplicitNullCheck(instruction); |
| 7733 | } |
| 7734 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7735 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7736 | "art::LockWord and int32_t have different sizes."); |
| 7737 | |
| 7738 | // Introduce a dependency on the lock_word including the rb_state, |
| 7739 | // which shall prevent load-load reordering without using |
| 7740 | // a memory barrier (which would be more expensive). |
| 7741 | // `obj` is unchanged by this operation, but its value now depends |
| 7742 | // on `temp_reg`. |
| 7743 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
| 7744 | |
| 7745 | // The actual reference load. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7746 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7747 | // Load types involving an "index": ArrayGet, |
| 7748 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7749 | // intrinsics. |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7750 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7751 | if (index.IsConstant()) { |
| 7752 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7753 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7754 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7755 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7756 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7757 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7758 | // intrinsics, which use a register pair as index ("long |
| 7759 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7760 | Register index_reg = index.IsRegisterPair() |
| 7761 | ? index.AsRegisterPairLow<Register>() |
| 7762 | : index.AsRegister<Register>(); |
| 7763 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7764 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7765 | } |
| 7766 | } else { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7767 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7768 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7769 | } |
| 7770 | |
| 7771 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7772 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7773 | |
| 7774 | // Slow path marking the object `ref` when it is gray. |
| 7775 | SlowPathCodeARM* slow_path; |
| 7776 | if (always_update_field) { |
| 7777 | DCHECK(temp2 != nullptr); |
| 7778 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 7779 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7780 | // `field_offset` is a register pair (of which only the lower half |
| 7781 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7782 | // to be null in this code path. |
| 7783 | DCHECK_EQ(offset, 0u); |
| 7784 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7785 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 7786 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7787 | } else { |
| 7788 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 7789 | } |
| 7790 | AddSlowPath(slow_path); |
| 7791 | |
| 7792 | // if (rb_state == ReadBarrier::GrayState()) |
| 7793 | // ref = ReadBarrier::Mark(ref); |
| 7794 | // Given the numeric representation, it's enough to check the low bit of the |
| 7795 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7796 | // which can be a 16-bit instruction unlike the TST immediate. |
| 7797 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7798 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7799 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7800 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
| 7801 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7802 | } |
| 7803 | |
| 7804 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7805 | Location out, |
| 7806 | Location ref, |
| 7807 | Location obj, |
| 7808 | uint32_t offset, |
| 7809 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7810 | DCHECK(kEmitCompilerReadBarrier); |
| 7811 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7812 | // Insert a slow path based read barrier *after* the reference load. |
| 7813 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7814 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7815 | // reference will be carried out by the runtime within the slow |
| 7816 | // path. |
| 7817 | // |
| 7818 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7819 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7820 | // not used by the artReadBarrierSlow entry point. |
| 7821 | // |
| 7822 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7823 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7824 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7825 | AddSlowPath(slow_path); |
| 7826 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7827 | __ b(slow_path->GetEntryLabel()); |
| 7828 | __ Bind(slow_path->GetExitLabel()); |
| 7829 | } |
| 7830 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7831 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7832 | Location out, |
| 7833 | Location ref, |
| 7834 | Location obj, |
| 7835 | uint32_t offset, |
| 7836 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7837 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7838 | // Baker's read barriers shall be handled by the fast path |
| 7839 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7840 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7841 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7842 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7843 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7844 | } else if (kPoisonHeapReferences) { |
| 7845 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7846 | } |
| 7847 | } |
| 7848 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7849 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7850 | Location out, |
| 7851 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7852 | DCHECK(kEmitCompilerReadBarrier); |
| 7853 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7854 | // Insert a slow path based read barrier *after* the GC root load. |
| 7855 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7856 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7857 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7858 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7859 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7860 | AddSlowPath(slow_path); |
| 7861 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7862 | __ b(slow_path->GetEntryLabel()); |
| 7863 | __ Bind(slow_path->GetExitLabel()); |
| 7864 | } |
| 7865 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7866 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7867 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7868 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 7869 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7870 | } |
| 7871 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7872 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7873 | Register temp) { |
| 7874 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7875 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7876 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7877 | return location.AsRegister<Register>(); |
| 7878 | } |
| 7879 | // For intrinsics we allow any location, so it may be on the stack. |
| 7880 | if (!location.IsRegister()) { |
| 7881 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7882 | return temp; |
| 7883 | } |
| 7884 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7885 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7886 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7887 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7888 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7889 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7890 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7891 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7892 | return temp; |
| 7893 | } |
| 7894 | return location.AsRegister<Register>(); |
| 7895 | } |
| 7896 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7897 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 7898 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7899 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7900 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7901 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7902 | uint32_t offset = |
| 7903 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7904 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7905 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7906 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7907 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7908 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7909 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7910 | break; |
| 7911 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7912 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7913 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7914 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7915 | HArmDexCacheArraysBase* base = |
| 7916 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7917 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7918 | temp.AsRegister<Register>()); |
| 7919 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7920 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7921 | break; |
| 7922 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7923 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7924 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7925 | Register method_reg; |
| 7926 | Register reg = temp.AsRegister<Register>(); |
| 7927 | if (current_method.IsRegister()) { |
| 7928 | method_reg = current_method.AsRegister<Register>(); |
| 7929 | } else { |
| 7930 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7931 | DCHECK(!current_method.IsValid()); |
| 7932 | method_reg = reg; |
| 7933 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7934 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7935 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7936 | __ LoadFromOffset(kLoadWord, |
| 7937 | reg, |
| 7938 | method_reg, |
| 7939 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7940 | // temp = temp[index_in_cache]; |
| 7941 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7942 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7943 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7944 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7945 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7946 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7947 | return callee_method; |
| 7948 | } |
| 7949 | |
| 7950 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 7951 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7952 | |
| 7953 | switch (invoke->GetCodePtrLocation()) { |
| 7954 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7955 | __ bl(GetFrameEntryLabel()); |
| 7956 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7957 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7958 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7959 | __ LoadFromOffset( |
| 7960 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7961 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7962 | // LR() |
| 7963 | __ blx(LR); |
| 7964 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7965 | } |
| 7966 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7967 | DCHECK(!IsLeafMethod()); |
| 7968 | } |
| 7969 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7970 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7971 | Register temp = temp_location.AsRegister<Register>(); |
| 7972 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7973 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7974 | |
| 7975 | // Use the calling convention instead of the location of the receiver, as |
| 7976 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7977 | // slow path, the arguments have been moved to the right place, so here we are |
| 7978 | // guaranteed that the receiver is the first register of the calling convention. |
| 7979 | InvokeDexCallingConvention calling_convention; |
| 7980 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7981 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7982 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7983 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7984 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7985 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7986 | // emit a read barrier for the previous class reference load. |
| 7987 | // However this is not required in practice, as this is an |
| 7988 | // intermediate/temporary reference and because the current |
| 7989 | // concurrent copying collector keeps the from-space memory |
| 7990 | // intact/accessible until the end of the marking phase (the |
| 7991 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7992 | __ MaybeUnpoisonHeapReference(temp); |
| 7993 | // temp = temp->GetMethodAt(method_offset); |
| 7994 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7995 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7996 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7997 | // LR = temp->GetEntryPoint(); |
| 7998 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7999 | // LR(); |
| 8000 | __ blx(LR); |
| 8001 | } |
| 8002 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8003 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8004 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8005 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8006 | } |
| 8007 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8008 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8009 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8010 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8011 | } |
| 8012 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8013 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 8014 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8015 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8016 | } |
| 8017 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8018 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 8019 | const DexFile& dex_file, uint32_t element_offset) { |
| 8020 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8021 | } |
| 8022 | |
| 8023 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 8024 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8025 | patches->emplace_back(dex_file, offset_or_index); |
| 8026 | return &patches->back(); |
| 8027 | } |
| 8028 | |
| 8029 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8030 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8031 | return boot_image_string_patches_.GetOrCreate( |
| 8032 | StringReference(&dex_file, string_index), |
| 8033 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8034 | } |
| 8035 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8036 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8037 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8038 | return boot_image_type_patches_.GetOrCreate( |
| 8039 | TypeReference(&dex_file, type_index), |
| 8040 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8041 | } |
| 8042 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8043 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 8044 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 8045 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 8046 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 8047 | } |
| 8048 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8049 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8050 | dex::StringIndex string_index, |
| 8051 | Handle<mirror::String> handle) { |
| 8052 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8053 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8054 | return jit_string_patches_.GetOrCreate( |
| 8055 | StringReference(&dex_file, string_index), |
| 8056 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8057 | } |
| 8058 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8059 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8060 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8061 | Handle<mirror::Class> handle) { |
| 8062 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8063 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8064 | return jit_class_patches_.GetOrCreate( |
| 8065 | TypeReference(&dex_file, type_index), |
| 8066 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8067 | } |
| 8068 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8069 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8070 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 8071 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8072 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8073 | for (const PcRelativePatchInfo& info : infos) { |
| 8074 | const DexFile& dex_file = info.target_dex_file; |
| 8075 | size_t offset_or_index = info.offset_or_index; |
| 8076 | DCHECK(info.add_pc_label.IsBound()); |
| 8077 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 8078 | // Add MOVW patch. |
| 8079 | DCHECK(info.movw_label.IsBound()); |
| 8080 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 8081 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8082 | // Add MOVT patch. |
| 8083 | DCHECK(info.movt_label.IsBound()); |
| 8084 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 8085 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8086 | } |
| 8087 | } |
| 8088 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8089 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8090 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8091 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8092 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8093 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8094 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8095 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8096 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8097 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8098 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8099 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8100 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8101 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8102 | for (const auto& entry : boot_image_string_patches_) { |
| 8103 | const StringReference& target_string = entry.first; |
| 8104 | Literal* literal = entry.second; |
| 8105 | DCHECK(literal->GetLabel()->IsBound()); |
| 8106 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8107 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 8108 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8109 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8110 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8111 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8112 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8113 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8114 | linker_patches); |
| 8115 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8116 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8117 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8118 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8119 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8120 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8121 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8122 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8123 | for (const auto& entry : boot_image_type_patches_) { |
| 8124 | const TypeReference& target_type = entry.first; |
| 8125 | Literal* literal = entry.second; |
| 8126 | DCHECK(literal->GetLabel()->IsBound()); |
| 8127 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8128 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 8129 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8130 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8131 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8132 | for (const auto& entry : boot_image_address_patches_) { |
| 8133 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 8134 | Literal* literal = entry.second; |
| 8135 | DCHECK(literal->GetLabel()->IsBound()); |
| 8136 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8137 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 8138 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8139 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8140 | } |
| 8141 | |
| 8142 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 8143 | return map->GetOrCreate( |
| 8144 | value, |
| 8145 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8146 | } |
| 8147 | |
| 8148 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 8149 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8150 | return map->GetOrCreate( |
| 8151 | target_method, |
| 8152 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8153 | } |
| 8154 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8155 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8156 | LocationSummary* locations = |
| 8157 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8158 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8159 | Location::RequiresRegister()); |
| 8160 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8161 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8162 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8163 | } |
| 8164 | |
| 8165 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8166 | LocationSummary* locations = instr->GetLocations(); |
| 8167 | Register res = locations->Out().AsRegister<Register>(); |
| 8168 | Register accumulator = |
| 8169 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 8170 | Register mul_left = |
| 8171 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 8172 | Register mul_right = |
| 8173 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 8174 | |
| 8175 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8176 | __ mla(res, mul_left, mul_right, accumulator); |
| 8177 | } else { |
| 8178 | __ mls(res, mul_left, mul_right, accumulator); |
| 8179 | } |
| 8180 | } |
| 8181 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8182 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8183 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8184 | LOG(FATAL) << "Unreachable"; |
| 8185 | } |
| 8186 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8187 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8188 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8189 | LOG(FATAL) << "Unreachable"; |
| 8190 | } |
| 8191 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8192 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8193 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8194 | LocationSummary* locations = |
| 8195 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8196 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8197 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8198 | codegen_->GetAssembler()->IsThumb()) { |
| 8199 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8200 | if (switch_instr->GetStartValue() != 0) { |
| 8201 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8202 | } |
| 8203 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8204 | } |
| 8205 | |
| 8206 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8207 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8208 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8209 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8210 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8211 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8212 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8213 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8214 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8215 | Register temp_reg = IP; |
| 8216 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8217 | // the immediate, because IP is used as the destination register. For the other |
| 8218 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8219 | // and they can be encoded in the instruction without making use of IP register. |
| 8220 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 8221 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8222 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8223 | // Jump to successors[0] if value == lower_bound. |
| 8224 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 8225 | int32_t last_index = 0; |
| 8226 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8227 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 8228 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8229 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 8230 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8231 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 8232 | } |
| 8233 | if (num_entries - last_index == 2) { |
| 8234 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 8235 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8236 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8237 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8238 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8239 | // And the default for any other value. |
| 8240 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8241 | __ b(codegen_->GetLabelOf(default_block)); |
| 8242 | } |
| 8243 | } else { |
| 8244 | // Create a table lookup. |
| 8245 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8246 | |
| 8247 | // Materialize a pointer to the switch table |
| 8248 | std::vector<Label*> labels(num_entries); |
| 8249 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8250 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8251 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8252 | } |
| 8253 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 8254 | |
| 8255 | // Remove the bias. |
| 8256 | Register key_reg; |
| 8257 | if (lower_bound != 0) { |
| 8258 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 8259 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 8260 | } else { |
| 8261 | key_reg = value_reg; |
| 8262 | } |
| 8263 | |
| 8264 | // Check whether the value is in the table, jump to default block if not. |
| 8265 | __ CmpConstant(key_reg, num_entries - 1); |
| 8266 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 8267 | |
| 8268 | // Load the displacement from the table. |
| 8269 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 8270 | |
| 8271 | // Dispatch is a direct add to the PC (for Thumb2). |
| 8272 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8273 | } |
| 8274 | } |
| 8275 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8276 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8277 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8278 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8282 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8283 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 8284 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8285 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8286 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8287 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8288 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8289 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8290 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 8291 | } |
| 8292 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8293 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8294 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8295 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8296 | return; |
| 8297 | } |
| 8298 | |
| 8299 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8300 | |
| 8301 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 8302 | if (return_loc.Equals(trg)) { |
| 8303 | return; |
| 8304 | } |
| 8305 | |
| 8306 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8307 | // with the last branch. |
| 8308 | if (type == Primitive::kPrimLong) { |
| 8309 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8310 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 8311 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 8312 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8313 | } else if (type == Primitive::kPrimDouble) { |
| 8314 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8315 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 8316 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 8317 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8318 | } else { |
| 8319 | // Let the parallel move resolver take care of all of this. |
| 8320 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8321 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8322 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8323 | } |
| 8324 | } |
| 8325 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8326 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8327 | LocationSummary* locations = |
| 8328 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8329 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8330 | locations->SetOut(Location::RequiresRegister()); |
| 8331 | } |
| 8332 | |
| 8333 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8334 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8335 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8336 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8337 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8338 | __ LoadFromOffset(kLoadWord, |
| 8339 | locations->Out().AsRegister<Register>(), |
| 8340 | locations->InAt(0).AsRegister<Register>(), |
| 8341 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8342 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8343 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 8344 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8345 | __ LoadFromOffset(kLoadWord, |
| 8346 | locations->Out().AsRegister<Register>(), |
| 8347 | locations->InAt(0).AsRegister<Register>(), |
| 8348 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8349 | __ LoadFromOffset(kLoadWord, |
| 8350 | locations->Out().AsRegister<Register>(), |
| 8351 | locations->Out().AsRegister<Register>(), |
| 8352 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8353 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8354 | } |
| 8355 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8356 | static void PatchJitRootUse(uint8_t* code, |
| 8357 | const uint8_t* roots_data, |
| 8358 | Literal* literal, |
| 8359 | uint64_t index_in_table) { |
| 8360 | DCHECK(literal->GetLabel()->IsBound()); |
| 8361 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8362 | uintptr_t address = |
| 8363 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8364 | uint8_t* data = code + literal_offset; |
| 8365 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8366 | } |
| 8367 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8368 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8369 | for (const auto& entry : jit_string_patches_) { |
| 8370 | const auto& it = jit_string_roots_.find(entry.first); |
| 8371 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8372 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8373 | } |
| 8374 | for (const auto& entry : jit_class_patches_) { |
| 8375 | const auto& it = jit_class_roots_.find(entry.first); |
| 8376 | DCHECK(it != jit_class_roots_.end()); |
| 8377 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8378 | } |
| 8379 | } |
| 8380 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8381 | #undef __ |
| 8382 | #undef QUICK_ENTRY_POINT |
| 8383 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8384 | } // namespace arm |
| 8385 | } // namespace art |