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 | |
| 1378 | #undef __ |
| 1379 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1380 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1381 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1382 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1383 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1387 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1390 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1391 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1392 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1395 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1396 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1397 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1400 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1401 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1402 | return kArmWordSize; |
| 1403 | } |
| 1404 | |
| 1405 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1406 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1407 | return kArmWordSize; |
| 1408 | } |
| 1409 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1410 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1411 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1412 | const CompilerOptions& compiler_options, |
| 1413 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1414 | : CodeGenerator(graph, |
| 1415 | kNumberOfCoreRegisters, |
| 1416 | kNumberOfSRegisters, |
| 1417 | kNumberOfRegisterPairs, |
| 1418 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1419 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1420 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1421 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1422 | compiler_options, |
| 1423 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1424 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1425 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1426 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1427 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1428 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1429 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1430 | uint32_literals_(std::less<uint32_t>(), |
| 1431 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1432 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1433 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1434 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1435 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1436 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1437 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1438 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1439 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1440 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1441 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1442 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1443 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1444 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1445 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1446 | // Always save the LR register to mimic Quick. |
| 1447 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1448 | } |
| 1449 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1450 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1451 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1452 | __ FinalizeCode(); |
| 1453 | |
| 1454 | // Adjust native pc offsets in stack maps. |
| 1455 | 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] | 1456 | uint32_t old_position = |
| 1457 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1458 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1459 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1460 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1461 | // Adjust pc offsets for the disassembly information. |
| 1462 | if (disasm_info_ != nullptr) { |
| 1463 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1464 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1465 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1466 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1467 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1468 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1469 | } |
| 1470 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1471 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1472 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1473 | } |
| 1474 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1475 | |
| 1476 | CodeGenerator::Finalize(allocator); |
| 1477 | } |
| 1478 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1479 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1480 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1481 | blocked_core_registers_[SP] = true; |
| 1482 | blocked_core_registers_[LR] = true; |
| 1483 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1484 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1485 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1486 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1487 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1488 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1489 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1490 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1491 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1492 | // Stubs do not save callee-save floating point registers. If the graph |
| 1493 | // is debuggable, we need to deal with these registers differently. For |
| 1494 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1495 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1496 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1497 | } |
| 1498 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1501 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1502 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1503 | assembler_(codegen->GetAssembler()), |
| 1504 | codegen_(codegen) {} |
| 1505 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1506 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1507 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1508 | 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] | 1509 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1510 | // restore another arbitrary register. |
| 1511 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1512 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1513 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1514 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1515 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1516 | // but in the range. |
| 1517 | if (fpu_spill_mask_ != 0) { |
| 1518 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1519 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1520 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1521 | fpu_spill_mask_ |= (1 << i); |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1526 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1527 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1531 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1532 | } |
| 1533 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1534 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1535 | bool skip_overflow_check = |
| 1536 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1537 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1538 | __ Bind(&frame_entry_label_); |
| 1539 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1540 | if (HasEmptyFrame()) { |
| 1541 | return; |
| 1542 | } |
| 1543 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1544 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1545 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1546 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1547 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1548 | } |
| 1549 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1550 | __ PushList(core_spill_mask_); |
| 1551 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1552 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1553 | if (fpu_spill_mask_ != 0) { |
| 1554 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1555 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1556 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1557 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1558 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1559 | |
| 1560 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1561 | // Initialize should_deoptimize flag to 0. |
| 1562 | __ mov(IP, ShifterOperand(0)); |
| 1563 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1564 | } |
| 1565 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1566 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1567 | __ AddConstant(SP, -adjust); |
| 1568 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1569 | |
| 1570 | // Save the current method if we need it. Note that we do not |
| 1571 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1572 | // in the SSA graph. |
| 1573 | if (RequiresCurrentMethod()) { |
| 1574 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1575 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1579 | if (HasEmptyFrame()) { |
| 1580 | __ bx(LR); |
| 1581 | return; |
| 1582 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1583 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1584 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1585 | __ AddConstant(SP, adjust); |
| 1586 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1587 | if (fpu_spill_mask_ != 0) { |
| 1588 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1589 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1590 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1591 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1592 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1593 | // Pop LR into PC to return. |
| 1594 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1595 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1596 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1597 | __ cfi().RestoreState(); |
| 1598 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1601 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1602 | Label* label = GetLabelOf(block); |
| 1603 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1606 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1607 | switch (type) { |
| 1608 | case Primitive::kPrimBoolean: |
| 1609 | case Primitive::kPrimByte: |
| 1610 | case Primitive::kPrimChar: |
| 1611 | case Primitive::kPrimShort: |
| 1612 | case Primitive::kPrimInt: |
| 1613 | case Primitive::kPrimNot: { |
| 1614 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1615 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1616 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1617 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1618 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1619 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1620 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1621 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1622 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1623 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1624 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1625 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1626 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1627 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1628 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1629 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1630 | // Skip R1, and use R2_R3 instead. |
| 1631 | gp_index_++; |
| 1632 | index++; |
| 1633 | } |
| 1634 | } |
| 1635 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1636 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1637 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1638 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1639 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1640 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1641 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1642 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | case Primitive::kPrimFloat: { |
| 1647 | uint32_t stack_index = stack_index_++; |
| 1648 | if (float_index_ % 2 == 0) { |
| 1649 | float_index_ = std::max(double_index_, float_index_); |
| 1650 | } |
| 1651 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1652 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1653 | } else { |
| 1654 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | case Primitive::kPrimDouble: { |
| 1659 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1660 | uint32_t stack_index = stack_index_; |
| 1661 | stack_index_ += 2; |
| 1662 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1663 | uint32_t index = double_index_; |
| 1664 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1665 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1666 | calling_convention.GetFpuRegisterAt(index), |
| 1667 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1668 | DCHECK(ExpectedPairLayout(result)); |
| 1669 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1670 | } else { |
| 1671 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1675 | case Primitive::kPrimVoid: |
| 1676 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1677 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1678 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1679 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1680 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1681 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1682 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1683 | switch (type) { |
| 1684 | case Primitive::kPrimBoolean: |
| 1685 | case Primitive::kPrimByte: |
| 1686 | case Primitive::kPrimChar: |
| 1687 | case Primitive::kPrimShort: |
| 1688 | case Primitive::kPrimInt: |
| 1689 | case Primitive::kPrimNot: { |
| 1690 | return Location::RegisterLocation(R0); |
| 1691 | } |
| 1692 | |
| 1693 | case Primitive::kPrimFloat: { |
| 1694 | return Location::FpuRegisterLocation(S0); |
| 1695 | } |
| 1696 | |
| 1697 | case Primitive::kPrimLong: { |
| 1698 | return Location::RegisterPairLocation(R0, R1); |
| 1699 | } |
| 1700 | |
| 1701 | case Primitive::kPrimDouble: { |
| 1702 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1703 | } |
| 1704 | |
| 1705 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1706 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1707 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1708 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1709 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1712 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1713 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1714 | } |
| 1715 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1716 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1717 | if (source.Equals(destination)) { |
| 1718 | return; |
| 1719 | } |
| 1720 | if (destination.IsRegister()) { |
| 1721 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1722 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1723 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1724 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1725 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1726 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1727 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1728 | } else if (destination.IsFpuRegister()) { |
| 1729 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1730 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1731 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1732 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1733 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1734 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1735 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1736 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1737 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1738 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1739 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1740 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1741 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1742 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1743 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1744 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1745 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1751 | if (source.Equals(destination)) { |
| 1752 | return; |
| 1753 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1754 | if (destination.IsRegisterPair()) { |
| 1755 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1756 | EmitParallelMoves( |
| 1757 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1758 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1759 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1760 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1761 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1762 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1763 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1764 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1765 | } else if (source.IsFpuRegisterPair()) { |
| 1766 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1767 | destination.AsRegisterPairHigh<Register>(), |
| 1768 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1769 | } else { |
| 1770 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1771 | DCHECK(ExpectedPairLayout(destination)); |
| 1772 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1773 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1774 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1775 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1776 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1777 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1778 | SP, |
| 1779 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1780 | } else if (source.IsRegisterPair()) { |
| 1781 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1782 | source.AsRegisterPairLow<Register>(), |
| 1783 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1784 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1785 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1786 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1787 | } else { |
| 1788 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1789 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1790 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1791 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1792 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1793 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1794 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1795 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1796 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1797 | SP, destination.GetStackIndex()); |
| 1798 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1799 | } else if (source.IsFpuRegisterPair()) { |
| 1800 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1801 | SP, |
| 1802 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1803 | } else { |
| 1804 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1805 | EmitParallelMoves( |
| 1806 | Location::StackSlot(source.GetStackIndex()), |
| 1807 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1808 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1809 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1810 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1811 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | } |
| 1815 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1816 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1817 | DCHECK(location.IsRegister()); |
| 1818 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1819 | } |
| 1820 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1821 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1822 | HParallelMove move(GetGraph()->GetArena()); |
| 1823 | move.AddMove(src, dst, dst_type, nullptr); |
| 1824 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1828 | if (location.IsRegister()) { |
| 1829 | locations->AddTemp(location); |
| 1830 | } else if (location.IsRegisterPair()) { |
| 1831 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1832 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1833 | } else { |
| 1834 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1835 | } |
| 1836 | } |
| 1837 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1838 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1839 | HInstruction* instruction, |
| 1840 | uint32_t dex_pc, |
| 1841 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1842 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1843 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1844 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1845 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1846 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1847 | } |
| 1848 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1849 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1850 | HInstruction* instruction, |
| 1851 | SlowPathCode* slow_path) { |
| 1852 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1853 | GenerateInvokeRuntime(entry_point_offset); |
| 1854 | } |
| 1855 | |
| 1856 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1857 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1858 | __ blx(LR); |
| 1859 | } |
| 1860 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1861 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1862 | DCHECK(!successor->IsExitBlock()); |
| 1863 | |
| 1864 | HBasicBlock* block = got->GetBlock(); |
| 1865 | HInstruction* previous = got->GetPrevious(); |
| 1866 | |
| 1867 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1868 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1869 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1870 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1871 | return; |
| 1872 | } |
| 1873 | |
| 1874 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1875 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1876 | } |
| 1877 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1878 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1882 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1883 | got->SetLocations(nullptr); |
| 1884 | } |
| 1885 | |
| 1886 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1887 | HandleGoto(got, got->GetSuccessor()); |
| 1888 | } |
| 1889 | |
| 1890 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1891 | try_boundary->SetLocations(nullptr); |
| 1892 | } |
| 1893 | |
| 1894 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1895 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1896 | if (!successor->IsExitBlock()) { |
| 1897 | HandleGoto(try_boundary, successor); |
| 1898 | } |
| 1899 | } |
| 1900 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1901 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1902 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1905 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1906 | } |
| 1907 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1908 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1909 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1910 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1911 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1912 | if (rhs_loc.IsConstant()) { |
| 1913 | // 0.0 is the only immediate that can be encoded directly in |
| 1914 | // a VCMP instruction. |
| 1915 | // |
| 1916 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1917 | // specify that in a floating-point comparison, positive zero |
| 1918 | // and negative zero are considered equal, so we can use the |
| 1919 | // literal 0.0 for both cases here. |
| 1920 | // |
| 1921 | // Note however that some methods (Float.equal, Float.compare, |
| 1922 | // Float.compareTo, Double.equal, Double.compare, |
| 1923 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1924 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1925 | // -0.0. So if we ever translate calls to these methods into a |
| 1926 | // HCompare instruction, we must handle the -0.0 case with |
| 1927 | // care here. |
| 1928 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1929 | if (type == Primitive::kPrimFloat) { |
| 1930 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1931 | } else { |
| 1932 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1933 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1934 | } |
| 1935 | } else { |
| 1936 | if (type == Primitive::kPrimFloat) { |
| 1937 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1938 | } else { |
| 1939 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1940 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1941 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1942 | } |
| 1943 | } |
| 1944 | } |
| 1945 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1946 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1947 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1948 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1949 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1950 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1954 | Label* true_label, |
| 1955 | Label* false_label) { |
| 1956 | LocationSummary* locations = cond->GetLocations(); |
| 1957 | Location left = locations->InAt(0); |
| 1958 | Location right = locations->InAt(1); |
| 1959 | IfCondition if_cond = cond->GetCondition(); |
| 1960 | |
| 1961 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1962 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1963 | IfCondition true_high_cond = if_cond; |
| 1964 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1965 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1966 | |
| 1967 | // Set the conditions for the test, remembering that == needs to be |
| 1968 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1969 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1970 | switch (if_cond) { |
| 1971 | case kCondEQ: |
| 1972 | case kCondNE: |
| 1973 | // Nothing to do. |
| 1974 | break; |
| 1975 | case kCondLT: |
| 1976 | false_high_cond = kCondGT; |
| 1977 | break; |
| 1978 | case kCondLE: |
| 1979 | true_high_cond = kCondLT; |
| 1980 | break; |
| 1981 | case kCondGT: |
| 1982 | false_high_cond = kCondLT; |
| 1983 | break; |
| 1984 | case kCondGE: |
| 1985 | true_high_cond = kCondGT; |
| 1986 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1987 | case kCondB: |
| 1988 | false_high_cond = kCondA; |
| 1989 | break; |
| 1990 | case kCondBE: |
| 1991 | true_high_cond = kCondB; |
| 1992 | break; |
| 1993 | case kCondA: |
| 1994 | false_high_cond = kCondB; |
| 1995 | break; |
| 1996 | case kCondAE: |
| 1997 | true_high_cond = kCondA; |
| 1998 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1999 | } |
| 2000 | if (right.IsConstant()) { |
| 2001 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2002 | int32_t val_low = Low32Bits(value); |
| 2003 | int32_t val_high = High32Bits(value); |
| 2004 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2005 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2006 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2007 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2008 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2009 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2010 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2011 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2012 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2013 | } |
| 2014 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2015 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2016 | } else { |
| 2017 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2018 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2019 | |
| 2020 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2021 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2022 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2023 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2024 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2025 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2026 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2027 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2028 | } |
| 2029 | // Must be equal high, so compare the lows. |
| 2030 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2031 | } |
| 2032 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2033 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2034 | __ b(true_label, final_condition); |
| 2035 | } |
| 2036 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2037 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2038 | Label* true_target_in, |
| 2039 | Label* false_target_in) { |
| 2040 | // Generated branching requires both targets to be explicit. If either of the |
| 2041 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2042 | Label fallthrough_target; |
| 2043 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2044 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2045 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2046 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2047 | switch (type) { |
| 2048 | case Primitive::kPrimLong: |
| 2049 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 2050 | break; |
| 2051 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2052 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2053 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2054 | GenerateFPJumps(condition, true_target, false_target); |
| 2055 | break; |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2058 | } |
| 2059 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2060 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2061 | __ b(false_target); |
| 2062 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2063 | |
| 2064 | if (fallthrough_target.IsLinked()) { |
| 2065 | __ Bind(&fallthrough_target); |
| 2066 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2067 | } |
| 2068 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2069 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2070 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2071 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2072 | Label* false_target) { |
| 2073 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2074 | |
| 2075 | if (true_target == nullptr && false_target == nullptr) { |
| 2076 | // Nothing to do. The code always falls through. |
| 2077 | return; |
| 2078 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2079 | // Constant condition, statically compared against "true" (integer value 1). |
| 2080 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2081 | if (true_target != nullptr) { |
| 2082 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2083 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2084 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2085 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2086 | if (false_target != nullptr) { |
| 2087 | __ b(false_target); |
| 2088 | } |
| 2089 | } |
| 2090 | return; |
| 2091 | } |
| 2092 | |
| 2093 | // The following code generates these patterns: |
| 2094 | // (1) true_target == nullptr && false_target != nullptr |
| 2095 | // - opposite condition true => branch to false_target |
| 2096 | // (2) true_target != nullptr && false_target == nullptr |
| 2097 | // - condition true => branch to true_target |
| 2098 | // (3) true_target != nullptr && false_target != nullptr |
| 2099 | // - condition true => branch to true_target |
| 2100 | // - branch to false_target |
| 2101 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2102 | // Condition has been materialized, compare the output to 0. |
| 2103 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2104 | DCHECK(cond_val.IsRegister()); |
| 2105 | if (true_target == nullptr) { |
| 2106 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2107 | } else { |
| 2108 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2109 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2110 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2111 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2112 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2113 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2114 | |
| 2115 | // If this is a long or FP comparison that has been folded into |
| 2116 | // the HCondition, generate the comparison directly. |
| 2117 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2118 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2119 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2120 | return; |
| 2121 | } |
| 2122 | |
| 2123 | LocationSummary* locations = cond->GetLocations(); |
| 2124 | DCHECK(locations->InAt(0).IsRegister()); |
| 2125 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2126 | Location right = locations->InAt(1); |
| 2127 | if (right.IsRegister()) { |
| 2128 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2129 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2130 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2131 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2132 | } |
| 2133 | if (true_target == nullptr) { |
| 2134 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 2135 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2136 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2137 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2138 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2139 | |
| 2140 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2141 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2142 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2143 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2147 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2148 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2149 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2155 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2156 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2157 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2158 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2159 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2160 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2161 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2165 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2166 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2167 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2168 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2169 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2174 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2175 | GenerateTestAndBranch(deoptimize, |
| 2176 | /* condition_input_index */ 0, |
| 2177 | slow_path->GetEntryLabel(), |
| 2178 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2179 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2180 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2181 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2182 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2183 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2184 | locations->SetOut(Location::RequiresRegister()); |
| 2185 | } |
| 2186 | |
| 2187 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2188 | __ LoadFromOffset(kLoadWord, |
| 2189 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2190 | SP, |
| 2191 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2192 | } |
| 2193 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2194 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2195 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 2196 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2197 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2198 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2199 | } else { |
| 2200 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2201 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2202 | } |
| 2203 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2204 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2205 | } |
| 2206 | locations->SetOut(Location::SameAsFirstInput()); |
| 2207 | } |
| 2208 | |
| 2209 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 2210 | LocationSummary* locations = select->GetLocations(); |
| 2211 | Label false_target; |
| 2212 | GenerateTestAndBranch(select, |
| 2213 | /* condition_input_index */ 2, |
| 2214 | /* true_target */ nullptr, |
| 2215 | &false_target); |
| 2216 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2217 | __ Bind(&false_target); |
| 2218 | } |
| 2219 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2220 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2221 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2222 | } |
| 2223 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2224 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2225 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | void CodeGeneratorARM::GenerateNop() { |
| 2229 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2232 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2233 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2234 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2235 | // Handle the long/FP comparisons made in instruction simplification. |
| 2236 | switch (cond->InputAt(0)->GetType()) { |
| 2237 | case Primitive::kPrimLong: |
| 2238 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2239 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2240 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2241 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2242 | } |
| 2243 | break; |
| 2244 | |
| 2245 | case Primitive::kPrimFloat: |
| 2246 | case Primitive::kPrimDouble: |
| 2247 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2248 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2249 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2250 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2251 | } |
| 2252 | break; |
| 2253 | |
| 2254 | default: |
| 2255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2256 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2257 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2259 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2260 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2263 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2264 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2265 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2266 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2267 | |
| 2268 | LocationSummary* locations = cond->GetLocations(); |
| 2269 | Location left = locations->InAt(0); |
| 2270 | Location right = locations->InAt(1); |
| 2271 | Register out = locations->Out().AsRegister<Register>(); |
| 2272 | Label true_label, false_label; |
| 2273 | |
| 2274 | switch (cond->InputAt(0)->GetType()) { |
| 2275 | default: { |
| 2276 | // Integer case. |
| 2277 | if (right.IsRegister()) { |
| 2278 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2279 | } else { |
| 2280 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2281 | __ CmpConstant(left.AsRegister<Register>(), |
| 2282 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2283 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2284 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2285 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2286 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2287 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2288 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2289 | return; |
| 2290 | } |
| 2291 | case Primitive::kPrimLong: |
| 2292 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2293 | break; |
| 2294 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2295 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2296 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2297 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2298 | break; |
| 2299 | } |
| 2300 | |
| 2301 | // Convert the jumps into the result. |
| 2302 | Label done_label; |
| 2303 | |
| 2304 | // False case: result = 0. |
| 2305 | __ Bind(&false_label); |
| 2306 | __ LoadImmediate(out, 0); |
| 2307 | __ b(&done_label); |
| 2308 | |
| 2309 | // True case: result = 1. |
| 2310 | __ Bind(&true_label); |
| 2311 | __ LoadImmediate(out, 1); |
| 2312 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2316 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2320 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2324 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2328 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2332 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2336 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2340 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2344 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2348 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2352 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2356 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2360 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2363 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2364 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2368 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2372 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2376 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2380 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2384 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2388 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2392 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2395 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2396 | LocationSummary* locations = |
| 2397 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2398 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2401 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2402 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2405 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2406 | LocationSummary* locations = |
| 2407 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2408 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2409 | } |
| 2410 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2411 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2412 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2415 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2416 | LocationSummary* locations = |
| 2417 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2418 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2419 | } |
| 2420 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2421 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2422 | // Will be generated at use site. |
| 2423 | } |
| 2424 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2425 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2426 | LocationSummary* locations = |
| 2427 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2428 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2429 | } |
| 2430 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2431 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2432 | // Will be generated at use site. |
| 2433 | } |
| 2434 | |
| 2435 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2436 | LocationSummary* locations = |
| 2437 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2438 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2439 | } |
| 2440 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2441 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2442 | // Will be generated at use site. |
| 2443 | } |
| 2444 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2445 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2446 | memory_barrier->SetLocations(nullptr); |
| 2447 | } |
| 2448 | |
| 2449 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2450 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2453 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2454 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2457 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2458 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2461 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2462 | LocationSummary* locations = |
| 2463 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2464 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2467 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2468 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2471 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2472 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2473 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2474 | // the method_idx. |
| 2475 | HandleInvoke(invoke); |
| 2476 | } |
| 2477 | |
| 2478 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2479 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2480 | } |
| 2481 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2482 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2483 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2484 | // art::PrepareForRegisterAllocation. |
| 2485 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2486 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2487 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2488 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2489 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2490 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2491 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2492 | return; |
| 2493 | } |
| 2494 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2495 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2496 | |
| 2497 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2498 | if (invoke->HasPcRelativeDexCache()) { |
| 2499 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2500 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2501 | } |
| 2502 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2503 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2504 | if (invoke->GetLocations()->Intrinsified()) { |
| 2505 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2506 | intrinsic.Dispatch(invoke); |
| 2507 | return true; |
| 2508 | } |
| 2509 | return false; |
| 2510 | } |
| 2511 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2512 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2513 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2514 | // art::PrepareForRegisterAllocation. |
| 2515 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2516 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2517 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2518 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2519 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2520 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2521 | LocationSummary* locations = invoke->GetLocations(); |
| 2522 | codegen_->GenerateStaticOrDirectCall( |
| 2523 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2524 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2525 | } |
| 2526 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2527 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2528 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2529 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2532 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2533 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2534 | if (intrinsic.TryDispatch(invoke)) { |
| 2535 | return; |
| 2536 | } |
| 2537 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2538 | HandleInvoke(invoke); |
| 2539 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2540 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2541 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2542 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2543 | return; |
| 2544 | } |
| 2545 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2546 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2547 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2548 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2551 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2552 | HandleInvoke(invoke); |
| 2553 | // Add the hidden argument. |
| 2554 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2555 | } |
| 2556 | |
| 2557 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2558 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2559 | LocationSummary* locations = invoke->GetLocations(); |
| 2560 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2561 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2562 | Location receiver = locations->InAt(0); |
| 2563 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2564 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2565 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2566 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2567 | DCHECK_EQ(R12, hidden_reg); |
| 2568 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2569 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2570 | if (receiver.IsStackSlot()) { |
| 2571 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2572 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2573 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2574 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2575 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2576 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2577 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2578 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2579 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2580 | // emit a read barrier for the previous class reference load. |
| 2581 | // However this is not required in practice, as this is an |
| 2582 | // intermediate/temporary reference and because the current |
| 2583 | // concurrent copying collector keeps the from-space memory |
| 2584 | // intact/accessible until the end of the marking phase (the |
| 2585 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2586 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2587 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2588 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2589 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2590 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2591 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2592 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2593 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2594 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2595 | // LR = temp->GetEntryPoint(); |
| 2596 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2597 | // LR(); |
| 2598 | __ blx(LR); |
| 2599 | DCHECK(!codegen_->IsLeafMethod()); |
| 2600 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2601 | } |
| 2602 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2603 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2604 | HandleInvoke(invoke); |
| 2605 | } |
| 2606 | |
| 2607 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2608 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2609 | } |
| 2610 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2611 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2612 | LocationSummary* locations = |
| 2613 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2614 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2615 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2616 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2617 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2618 | break; |
| 2619 | } |
| 2620 | case Primitive::kPrimLong: { |
| 2621 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2622 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2623 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2624 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2625 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2626 | case Primitive::kPrimFloat: |
| 2627 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2628 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2629 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2630 | break; |
| 2631 | |
| 2632 | default: |
| 2633 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2638 | LocationSummary* locations = neg->GetLocations(); |
| 2639 | Location out = locations->Out(); |
| 2640 | Location in = locations->InAt(0); |
| 2641 | switch (neg->GetResultType()) { |
| 2642 | case Primitive::kPrimInt: |
| 2643 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2644 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2645 | break; |
| 2646 | |
| 2647 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2648 | DCHECK(in.IsRegisterPair()); |
| 2649 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2650 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2651 | in.AsRegisterPairLow<Register>(), |
| 2652 | ShifterOperand(0)); |
| 2653 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2654 | // instruction here, as it does not exist in the Thumb-2 |
| 2655 | // instruction set. We use the following approach |
| 2656 | // using SBC and SUB instead. |
| 2657 | // |
| 2658 | // out.hi = -C |
| 2659 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2660 | out.AsRegisterPairHigh<Register>(), |
| 2661 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2662 | // out.hi = out.hi - in.hi |
| 2663 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2664 | out.AsRegisterPairHigh<Register>(), |
| 2665 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2666 | break; |
| 2667 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2668 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2669 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2670 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2671 | break; |
| 2672 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2673 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2674 | DCHECK(in.IsFpuRegisterPair()); |
| 2675 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2676 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2677 | break; |
| 2678 | |
| 2679 | default: |
| 2680 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2681 | } |
| 2682 | } |
| 2683 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2684 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2685 | Primitive::Type result_type = conversion->GetResultType(); |
| 2686 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2687 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2688 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2689 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2690 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2691 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2692 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2693 | && result_type == Primitive::kPrimLong) |
| 2694 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2695 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2696 | : LocationSummary::kNoCall; |
| 2697 | LocationSummary* locations = |
| 2698 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2699 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2700 | // The Java language does not allow treating boolean as an integral type but |
| 2701 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2702 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2703 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2704 | case Primitive::kPrimByte: |
| 2705 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2706 | case Primitive::kPrimLong: |
| 2707 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2708 | case Primitive::kPrimBoolean: |
| 2709 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2710 | case Primitive::kPrimShort: |
| 2711 | case Primitive::kPrimInt: |
| 2712 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2713 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2714 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2715 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2716 | break; |
| 2717 | |
| 2718 | default: |
| 2719 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2720 | << " to " << result_type; |
| 2721 | } |
| 2722 | break; |
| 2723 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2724 | case Primitive::kPrimShort: |
| 2725 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimLong: |
| 2727 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2728 | case Primitive::kPrimBoolean: |
| 2729 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2730 | case Primitive::kPrimByte: |
| 2731 | case Primitive::kPrimInt: |
| 2732 | case Primitive::kPrimChar: |
| 2733 | // Processing a Dex `int-to-short' instruction. |
| 2734 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2735 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2736 | break; |
| 2737 | |
| 2738 | default: |
| 2739 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2740 | << " to " << result_type; |
| 2741 | } |
| 2742 | break; |
| 2743 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2744 | case Primitive::kPrimInt: |
| 2745 | switch (input_type) { |
| 2746 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2747 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2748 | locations->SetInAt(0, Location::Any()); |
| 2749 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2750 | break; |
| 2751 | |
| 2752 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2753 | // Processing a Dex `float-to-int' instruction. |
| 2754 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2755 | locations->SetOut(Location::RequiresRegister()); |
| 2756 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2757 | break; |
| 2758 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2759 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2760 | // Processing a Dex `double-to-int' instruction. |
| 2761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2762 | locations->SetOut(Location::RequiresRegister()); |
| 2763 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2764 | break; |
| 2765 | |
| 2766 | default: |
| 2767 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2768 | << " to " << result_type; |
| 2769 | } |
| 2770 | break; |
| 2771 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2772 | case Primitive::kPrimLong: |
| 2773 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2774 | case Primitive::kPrimBoolean: |
| 2775 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2776 | case Primitive::kPrimByte: |
| 2777 | case Primitive::kPrimShort: |
| 2778 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2779 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2780 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2782 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2783 | break; |
| 2784 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2785 | case Primitive::kPrimFloat: { |
| 2786 | // Processing a Dex `float-to-long' instruction. |
| 2787 | InvokeRuntimeCallingConvention calling_convention; |
| 2788 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2789 | calling_convention.GetFpuRegisterAt(0))); |
| 2790 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2791 | break; |
| 2792 | } |
| 2793 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2794 | case Primitive::kPrimDouble: { |
| 2795 | // Processing a Dex `double-to-long' instruction. |
| 2796 | InvokeRuntimeCallingConvention calling_convention; |
| 2797 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2798 | calling_convention.GetFpuRegisterAt(0), |
| 2799 | calling_convention.GetFpuRegisterAt(1))); |
| 2800 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2801 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2802 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2803 | |
| 2804 | default: |
| 2805 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2806 | << " to " << result_type; |
| 2807 | } |
| 2808 | break; |
| 2809 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2810 | case Primitive::kPrimChar: |
| 2811 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2812 | case Primitive::kPrimLong: |
| 2813 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2814 | case Primitive::kPrimBoolean: |
| 2815 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2816 | case Primitive::kPrimByte: |
| 2817 | case Primitive::kPrimShort: |
| 2818 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2819 | // Processing a Dex `int-to-char' instruction. |
| 2820 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2821 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2822 | break; |
| 2823 | |
| 2824 | default: |
| 2825 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2826 | << " to " << result_type; |
| 2827 | } |
| 2828 | break; |
| 2829 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2830 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2831 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2832 | case Primitive::kPrimBoolean: |
| 2833 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2834 | case Primitive::kPrimByte: |
| 2835 | case Primitive::kPrimShort: |
| 2836 | case Primitive::kPrimInt: |
| 2837 | case Primitive::kPrimChar: |
| 2838 | // Processing a Dex `int-to-float' instruction. |
| 2839 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2840 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2841 | break; |
| 2842 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2843 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2844 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2845 | InvokeRuntimeCallingConvention calling_convention; |
| 2846 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2847 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2848 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2849 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2850 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2851 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2852 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2853 | // Processing a Dex `double-to-float' instruction. |
| 2854 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2855 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | |
| 2858 | default: |
| 2859 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2860 | << " to " << result_type; |
| 2861 | }; |
| 2862 | break; |
| 2863 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2864 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2865 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2866 | case Primitive::kPrimBoolean: |
| 2867 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2868 | case Primitive::kPrimByte: |
| 2869 | case Primitive::kPrimShort: |
| 2870 | case Primitive::kPrimInt: |
| 2871 | case Primitive::kPrimChar: |
| 2872 | // Processing a Dex `int-to-double' instruction. |
| 2873 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2874 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2875 | break; |
| 2876 | |
| 2877 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2878 | // Processing a Dex `long-to-double' instruction. |
| 2879 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2880 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2881 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2882 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2883 | break; |
| 2884 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2885 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2886 | // Processing a Dex `float-to-double' instruction. |
| 2887 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2888 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | |
| 2891 | default: |
| 2892 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2893 | << " to " << result_type; |
| 2894 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2895 | break; |
| 2896 | |
| 2897 | default: |
| 2898 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2899 | << " to " << result_type; |
| 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2904 | LocationSummary* locations = conversion->GetLocations(); |
| 2905 | Location out = locations->Out(); |
| 2906 | Location in = locations->InAt(0); |
| 2907 | Primitive::Type result_type = conversion->GetResultType(); |
| 2908 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2909 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2910 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2911 | case Primitive::kPrimByte: |
| 2912 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2913 | case Primitive::kPrimLong: |
| 2914 | // Type conversion from long to byte is a result of code transformations. |
| 2915 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2916 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2917 | case Primitive::kPrimBoolean: |
| 2918 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2919 | case Primitive::kPrimShort: |
| 2920 | case Primitive::kPrimInt: |
| 2921 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2922 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2923 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2924 | break; |
| 2925 | |
| 2926 | default: |
| 2927 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2928 | << " to " << result_type; |
| 2929 | } |
| 2930 | break; |
| 2931 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2932 | case Primitive::kPrimShort: |
| 2933 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2934 | case Primitive::kPrimLong: |
| 2935 | // Type conversion from long to short is a result of code transformations. |
| 2936 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2937 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2938 | case Primitive::kPrimBoolean: |
| 2939 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2940 | case Primitive::kPrimByte: |
| 2941 | case Primitive::kPrimInt: |
| 2942 | case Primitive::kPrimChar: |
| 2943 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2944 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2945 | break; |
| 2946 | |
| 2947 | default: |
| 2948 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2949 | << " to " << result_type; |
| 2950 | } |
| 2951 | break; |
| 2952 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2953 | case Primitive::kPrimInt: |
| 2954 | switch (input_type) { |
| 2955 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2956 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2957 | DCHECK(out.IsRegister()); |
| 2958 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2959 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2960 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2961 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2962 | } else { |
| 2963 | DCHECK(in.IsConstant()); |
| 2964 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2965 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2966 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2967 | } |
| 2968 | break; |
| 2969 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2970 | case Primitive::kPrimFloat: { |
| 2971 | // Processing a Dex `float-to-int' instruction. |
| 2972 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2973 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2974 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2975 | break; |
| 2976 | } |
| 2977 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2978 | case Primitive::kPrimDouble: { |
| 2979 | // Processing a Dex `double-to-int' instruction. |
| 2980 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2981 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2982 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2983 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2984 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2985 | |
| 2986 | default: |
| 2987 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2988 | << " to " << result_type; |
| 2989 | } |
| 2990 | break; |
| 2991 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2992 | case Primitive::kPrimLong: |
| 2993 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2994 | case Primitive::kPrimBoolean: |
| 2995 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2996 | case Primitive::kPrimByte: |
| 2997 | case Primitive::kPrimShort: |
| 2998 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2999 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3000 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3001 | DCHECK(out.IsRegisterPair()); |
| 3002 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3003 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3004 | // Sign extension. |
| 3005 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3006 | out.AsRegisterPairLow<Register>(), |
| 3007 | 31); |
| 3008 | break; |
| 3009 | |
| 3010 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3011 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3012 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3013 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3014 | break; |
| 3015 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3016 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3017 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3018 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3019 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3020 | break; |
| 3021 | |
| 3022 | default: |
| 3023 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3024 | << " to " << result_type; |
| 3025 | } |
| 3026 | break; |
| 3027 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3028 | case Primitive::kPrimChar: |
| 3029 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3030 | case Primitive::kPrimLong: |
| 3031 | // Type conversion from long to char is a result of code transformations. |
| 3032 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3033 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3034 | case Primitive::kPrimBoolean: |
| 3035 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3036 | case Primitive::kPrimByte: |
| 3037 | case Primitive::kPrimShort: |
| 3038 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3039 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3040 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3041 | break; |
| 3042 | |
| 3043 | default: |
| 3044 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3045 | << " to " << result_type; |
| 3046 | } |
| 3047 | break; |
| 3048 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3049 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3050 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3051 | case Primitive::kPrimBoolean: |
| 3052 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3053 | case Primitive::kPrimByte: |
| 3054 | case Primitive::kPrimShort: |
| 3055 | case Primitive::kPrimInt: |
| 3056 | case Primitive::kPrimChar: { |
| 3057 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3058 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3059 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3060 | break; |
| 3061 | } |
| 3062 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3063 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3064 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3065 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3066 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3067 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3068 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3069 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3070 | // Processing a Dex `double-to-float' instruction. |
| 3071 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3072 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3073 | break; |
| 3074 | |
| 3075 | default: |
| 3076 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3077 | << " to " << result_type; |
| 3078 | }; |
| 3079 | break; |
| 3080 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3081 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3082 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3083 | case Primitive::kPrimBoolean: |
| 3084 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3085 | case Primitive::kPrimByte: |
| 3086 | case Primitive::kPrimShort: |
| 3087 | case Primitive::kPrimInt: |
| 3088 | case Primitive::kPrimChar: { |
| 3089 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3090 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3091 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3092 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3093 | break; |
| 3094 | } |
| 3095 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3096 | case Primitive::kPrimLong: { |
| 3097 | // Processing a Dex `long-to-double' instruction. |
| 3098 | Register low = in.AsRegisterPairLow<Register>(); |
| 3099 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3100 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3101 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3102 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3103 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3104 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3105 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3106 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3107 | // temp_d = int-to-double(high) |
| 3108 | __ vmovsr(temp_s, high); |
| 3109 | __ vcvtdi(temp_d, temp_s); |
| 3110 | // constant_d = k2Pow32EncodingForDouble |
| 3111 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3112 | // out_d = unsigned-to-double(low) |
| 3113 | __ vmovsr(out_s, low); |
| 3114 | __ vcvtdu(out_d, out_s); |
| 3115 | // out_d += temp_d * constant_d |
| 3116 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3120 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3121 | // Processing a Dex `float-to-double' instruction. |
| 3122 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3123 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3124 | break; |
| 3125 | |
| 3126 | default: |
| 3127 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3128 | << " to " << result_type; |
| 3129 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3130 | break; |
| 3131 | |
| 3132 | default: |
| 3133 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3134 | << " to " << result_type; |
| 3135 | } |
| 3136 | } |
| 3137 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3138 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3139 | LocationSummary* locations = |
| 3140 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3141 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3142 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3143 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3144 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3145 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3146 | break; |
| 3147 | } |
| 3148 | |
| 3149 | case Primitive::kPrimLong: { |
| 3150 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3151 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3152 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3153 | break; |
| 3154 | } |
| 3155 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3156 | case Primitive::kPrimFloat: |
| 3157 | case Primitive::kPrimDouble: { |
| 3158 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3159 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3160 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3161 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3162 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3163 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3164 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3165 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3166 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3170 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3171 | Location out = locations->Out(); |
| 3172 | Location first = locations->InAt(0); |
| 3173 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3174 | switch (add->GetResultType()) { |
| 3175 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3176 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3177 | __ add(out.AsRegister<Register>(), |
| 3178 | first.AsRegister<Register>(), |
| 3179 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3180 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3181 | __ AddConstant(out.AsRegister<Register>(), |
| 3182 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3183 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3184 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3185 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3186 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3187 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3188 | if (second.IsConstant()) { |
| 3189 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3190 | GenerateAddLongConst(out, first, value); |
| 3191 | } else { |
| 3192 | DCHECK(second.IsRegisterPair()); |
| 3193 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3194 | first.AsRegisterPairLow<Register>(), |
| 3195 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3196 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3197 | first.AsRegisterPairHigh<Register>(), |
| 3198 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3199 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3200 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3201 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3202 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3203 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3204 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3205 | first.AsFpuRegister<SRegister>(), |
| 3206 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3207 | break; |
| 3208 | |
| 3209 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3210 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3211 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3212 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3213 | break; |
| 3214 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3215 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3216 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3220 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3221 | LocationSummary* locations = |
| 3222 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3223 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3224 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3225 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3226 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3227 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3228 | break; |
| 3229 | } |
| 3230 | |
| 3231 | case Primitive::kPrimLong: { |
| 3232 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3233 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3234 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3235 | break; |
| 3236 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3237 | case Primitive::kPrimFloat: |
| 3238 | case Primitive::kPrimDouble: { |
| 3239 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3240 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3241 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3242 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3243 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3244 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3245 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3246 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3250 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3251 | Location out = locations->Out(); |
| 3252 | Location first = locations->InAt(0); |
| 3253 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3254 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3255 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3256 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3257 | __ sub(out.AsRegister<Register>(), |
| 3258 | first.AsRegister<Register>(), |
| 3259 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3260 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3261 | __ AddConstant(out.AsRegister<Register>(), |
| 3262 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3263 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3264 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3265 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3266 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3267 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3268 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3269 | if (second.IsConstant()) { |
| 3270 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3271 | GenerateAddLongConst(out, first, -value); |
| 3272 | } else { |
| 3273 | DCHECK(second.IsRegisterPair()); |
| 3274 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3275 | first.AsRegisterPairLow<Register>(), |
| 3276 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3277 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3278 | first.AsRegisterPairHigh<Register>(), |
| 3279 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3280 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3281 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3282 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3283 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3284 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3285 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3286 | first.AsFpuRegister<SRegister>(), |
| 3287 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3288 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3292 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3293 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3294 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3295 | break; |
| 3296 | } |
| 3297 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3298 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3299 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3300 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3301 | } |
| 3302 | } |
| 3303 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3304 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3305 | LocationSummary* locations = |
| 3306 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3307 | switch (mul->GetResultType()) { |
| 3308 | case Primitive::kPrimInt: |
| 3309 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3310 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3311 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3312 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3313 | break; |
| 3314 | } |
| 3315 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3316 | case Primitive::kPrimFloat: |
| 3317 | case Primitive::kPrimDouble: { |
| 3318 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3319 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3320 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3321 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3322 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3323 | |
| 3324 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3325 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3330 | LocationSummary* locations = mul->GetLocations(); |
| 3331 | Location out = locations->Out(); |
| 3332 | Location first = locations->InAt(0); |
| 3333 | Location second = locations->InAt(1); |
| 3334 | switch (mul->GetResultType()) { |
| 3335 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3336 | __ mul(out.AsRegister<Register>(), |
| 3337 | first.AsRegister<Register>(), |
| 3338 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3339 | break; |
| 3340 | } |
| 3341 | case Primitive::kPrimLong: { |
| 3342 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3343 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3344 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3345 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3346 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3347 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3348 | |
| 3349 | // Extra checks to protect caused by the existence of R1_R2. |
| 3350 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3351 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3352 | DCHECK_NE(out_hi, in1_lo); |
| 3353 | DCHECK_NE(out_hi, in2_lo); |
| 3354 | |
| 3355 | // input: in1 - 64 bits, in2 - 64 bits |
| 3356 | // output: out |
| 3357 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3358 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3359 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3360 | |
| 3361 | // IP <- in1.lo * in2.hi |
| 3362 | __ mul(IP, in1_lo, in2_hi); |
| 3363 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3364 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3365 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3366 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3367 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3368 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3369 | break; |
| 3370 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3371 | |
| 3372 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3373 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3374 | first.AsFpuRegister<SRegister>(), |
| 3375 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3376 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3380 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3381 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3382 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3383 | break; |
| 3384 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3385 | |
| 3386 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3387 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3388 | } |
| 3389 | } |
| 3390 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3391 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3392 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3393 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3394 | |
| 3395 | LocationSummary* locations = instruction->GetLocations(); |
| 3396 | Location second = locations->InAt(1); |
| 3397 | DCHECK(second.IsConstant()); |
| 3398 | |
| 3399 | Register out = locations->Out().AsRegister<Register>(); |
| 3400 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3401 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3402 | DCHECK(imm == 1 || imm == -1); |
| 3403 | |
| 3404 | if (instruction->IsRem()) { |
| 3405 | __ LoadImmediate(out, 0); |
| 3406 | } else { |
| 3407 | if (imm == 1) { |
| 3408 | __ Mov(out, dividend); |
| 3409 | } else { |
| 3410 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3411 | } |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3416 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3417 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3418 | |
| 3419 | LocationSummary* locations = instruction->GetLocations(); |
| 3420 | Location second = locations->InAt(1); |
| 3421 | DCHECK(second.IsConstant()); |
| 3422 | |
| 3423 | Register out = locations->Out().AsRegister<Register>(); |
| 3424 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3425 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3426 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3427 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3428 | int ctz_imm = CTZ(abs_imm); |
| 3429 | |
| 3430 | if (ctz_imm == 1) { |
| 3431 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3432 | } else { |
| 3433 | __ Asr(temp, dividend, 31); |
| 3434 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3435 | } |
| 3436 | __ add(out, temp, ShifterOperand(dividend)); |
| 3437 | |
| 3438 | if (instruction->IsDiv()) { |
| 3439 | __ Asr(out, out, ctz_imm); |
| 3440 | if (imm < 0) { |
| 3441 | __ rsb(out, out, ShifterOperand(0)); |
| 3442 | } |
| 3443 | } else { |
| 3444 | __ ubfx(out, out, 0, ctz_imm); |
| 3445 | __ sub(out, out, ShifterOperand(temp)); |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3450 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3451 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3452 | |
| 3453 | LocationSummary* locations = instruction->GetLocations(); |
| 3454 | Location second = locations->InAt(1); |
| 3455 | DCHECK(second.IsConstant()); |
| 3456 | |
| 3457 | Register out = locations->Out().AsRegister<Register>(); |
| 3458 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3459 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3460 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3461 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3462 | |
| 3463 | int64_t magic; |
| 3464 | int shift; |
| 3465 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3466 | |
| 3467 | __ LoadImmediate(temp1, magic); |
| 3468 | __ smull(temp2, temp1, dividend, temp1); |
| 3469 | |
| 3470 | if (imm > 0 && magic < 0) { |
| 3471 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3472 | } else if (imm < 0 && magic > 0) { |
| 3473 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3474 | } |
| 3475 | |
| 3476 | if (shift != 0) { |
| 3477 | __ Asr(temp1, temp1, shift); |
| 3478 | } |
| 3479 | |
| 3480 | if (instruction->IsDiv()) { |
| 3481 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3482 | } else { |
| 3483 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3484 | // TODO: Strength reduction for mls. |
| 3485 | __ LoadImmediate(temp2, imm); |
| 3486 | __ mls(out, temp1, temp2, dividend); |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3491 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3492 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3493 | |
| 3494 | LocationSummary* locations = instruction->GetLocations(); |
| 3495 | Location second = locations->InAt(1); |
| 3496 | DCHECK(second.IsConstant()); |
| 3497 | |
| 3498 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3499 | if (imm == 0) { |
| 3500 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3501 | } else if (imm == 1 || imm == -1) { |
| 3502 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3503 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3504 | DivRemByPowerOfTwo(instruction); |
| 3505 | } else { |
| 3506 | DCHECK(imm <= -2 || imm >= 2); |
| 3507 | GenerateDivRemWithAnyConstant(instruction); |
| 3508 | } |
| 3509 | } |
| 3510 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3511 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3512 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3513 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3514 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3515 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3516 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3517 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3518 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3519 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3520 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3521 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3524 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3525 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3526 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3527 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3528 | if (div->InputAt(1)->IsConstant()) { |
| 3529 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3530 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3531 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3532 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3533 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3534 | // No temp register required. |
| 3535 | } else { |
| 3536 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3537 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3538 | locations->AddTemp(Location::RequiresRegister()); |
| 3539 | } |
| 3540 | } |
| 3541 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3543 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3545 | } else { |
| 3546 | InvokeRuntimeCallingConvention calling_convention; |
| 3547 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3548 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3549 | // 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] | 3550 | // we only need the former. |
| 3551 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3552 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3553 | break; |
| 3554 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3555 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3556 | InvokeRuntimeCallingConvention calling_convention; |
| 3557 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3558 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3559 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3560 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3561 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3562 | break; |
| 3563 | } |
| 3564 | case Primitive::kPrimFloat: |
| 3565 | case Primitive::kPrimDouble: { |
| 3566 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3567 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3568 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3569 | break; |
| 3570 | } |
| 3571 | |
| 3572 | default: |
| 3573 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3578 | LocationSummary* locations = div->GetLocations(); |
| 3579 | Location out = locations->Out(); |
| 3580 | Location first = locations->InAt(0); |
| 3581 | Location second = locations->InAt(1); |
| 3582 | |
| 3583 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3584 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3585 | if (second.IsConstant()) { |
| 3586 | GenerateDivRemConstantIntegral(div); |
| 3587 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3588 | __ sdiv(out.AsRegister<Register>(), |
| 3589 | first.AsRegister<Register>(), |
| 3590 | second.AsRegister<Register>()); |
| 3591 | } else { |
| 3592 | InvokeRuntimeCallingConvention calling_convention; |
| 3593 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3594 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3595 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3596 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3597 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3598 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3599 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3600 | break; |
| 3601 | } |
| 3602 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3603 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3604 | InvokeRuntimeCallingConvention calling_convention; |
| 3605 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3606 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3607 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3608 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3609 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3610 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3611 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3612 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3613 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
| 3616 | |
| 3617 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3618 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3619 | first.AsFpuRegister<SRegister>(), |
| 3620 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | } |
| 3623 | |
| 3624 | case Primitive::kPrimDouble: { |
| 3625 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3626 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3627 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3628 | break; |
| 3629 | } |
| 3630 | |
| 3631 | default: |
| 3632 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3633 | } |
| 3634 | } |
| 3635 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3636 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3637 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3638 | |
| 3639 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3640 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3641 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3642 | // sdiv will be replaced by other instruction sequence. |
| 3643 | call_kind = LocationSummary::kNoCall; |
| 3644 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3645 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3646 | // Have hardware divide instruction for int, do it with three instructions. |
| 3647 | call_kind = LocationSummary::kNoCall; |
| 3648 | } |
| 3649 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3650 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3651 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3652 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3653 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3654 | if (rem->InputAt(1)->IsConstant()) { |
| 3655 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3656 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3657 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3658 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3659 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3660 | // No temp register required. |
| 3661 | } else { |
| 3662 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3663 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3664 | locations->AddTemp(Location::RequiresRegister()); |
| 3665 | } |
| 3666 | } |
| 3667 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3668 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3669 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3670 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3671 | locations->AddTemp(Location::RequiresRegister()); |
| 3672 | } else { |
| 3673 | InvokeRuntimeCallingConvention calling_convention; |
| 3674 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3675 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3676 | // 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] | 3677 | // we only need the latter. |
| 3678 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3679 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3680 | break; |
| 3681 | } |
| 3682 | case Primitive::kPrimLong: { |
| 3683 | InvokeRuntimeCallingConvention calling_convention; |
| 3684 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3685 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3686 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3687 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3688 | // The runtime helper puts the output in R2,R3. |
| 3689 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3690 | break; |
| 3691 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3692 | case Primitive::kPrimFloat: { |
| 3693 | InvokeRuntimeCallingConvention calling_convention; |
| 3694 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3695 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3696 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3697 | break; |
| 3698 | } |
| 3699 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3700 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3701 | InvokeRuntimeCallingConvention calling_convention; |
| 3702 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3703 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3704 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3705 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3706 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3707 | break; |
| 3708 | } |
| 3709 | |
| 3710 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3711 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3716 | LocationSummary* locations = rem->GetLocations(); |
| 3717 | Location out = locations->Out(); |
| 3718 | Location first = locations->InAt(0); |
| 3719 | Location second = locations->InAt(1); |
| 3720 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3721 | Primitive::Type type = rem->GetResultType(); |
| 3722 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3723 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3724 | if (second.IsConstant()) { |
| 3725 | GenerateDivRemConstantIntegral(rem); |
| 3726 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3727 | Register reg1 = first.AsRegister<Register>(); |
| 3728 | Register reg2 = second.AsRegister<Register>(); |
| 3729 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3730 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3731 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3732 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3733 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3734 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3735 | } else { |
| 3736 | InvokeRuntimeCallingConvention calling_convention; |
| 3737 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3738 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3739 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3740 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3741 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3742 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3743 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3744 | break; |
| 3745 | } |
| 3746 | |
| 3747 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3748 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3749 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3750 | break; |
| 3751 | } |
| 3752 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3753 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3754 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3755 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3756 | break; |
| 3757 | } |
| 3758 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3759 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3760 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3761 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3762 | break; |
| 3763 | } |
| 3764 | |
| 3765 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3766 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3767 | } |
| 3768 | } |
| 3769 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3770 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3771 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3772 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3776 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3777 | codegen_->AddSlowPath(slow_path); |
| 3778 | |
| 3779 | LocationSummary* locations = instruction->GetLocations(); |
| 3780 | Location value = locations->InAt(0); |
| 3781 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3782 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3783 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3784 | case Primitive::kPrimByte: |
| 3785 | case Primitive::kPrimChar: |
| 3786 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3787 | case Primitive::kPrimInt: { |
| 3788 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3789 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3790 | } else { |
| 3791 | DCHECK(value.IsConstant()) << value; |
| 3792 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3793 | __ b(slow_path->GetEntryLabel()); |
| 3794 | } |
| 3795 | } |
| 3796 | break; |
| 3797 | } |
| 3798 | case Primitive::kPrimLong: { |
| 3799 | if (value.IsRegisterPair()) { |
| 3800 | __ orrs(IP, |
| 3801 | value.AsRegisterPairLow<Register>(), |
| 3802 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3803 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3804 | } else { |
| 3805 | DCHECK(value.IsConstant()) << value; |
| 3806 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3807 | __ b(slow_path->GetEntryLabel()); |
| 3808 | } |
| 3809 | } |
| 3810 | break; |
| 3811 | default: |
| 3812 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3813 | } |
| 3814 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3817 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3818 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3819 | Location rhs = locations->InAt(1); |
| 3820 | Register out = locations->Out().AsRegister<Register>(); |
| 3821 | |
| 3822 | if (rhs.IsConstant()) { |
| 3823 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3824 | // so map all rotations to a +ve. equivalent in that range. |
| 3825 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3826 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3827 | if (rot) { |
| 3828 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3829 | // (e.g. left by 2 bits == right by 30.) |
| 3830 | __ Ror(out, in, rot); |
| 3831 | } else if (out != in) { |
| 3832 | __ Mov(out, in); |
| 3833 | } |
| 3834 | } else { |
| 3835 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3840 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3841 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3842 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3843 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3844 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3845 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3846 | Location rhs = locations->InAt(1); |
| 3847 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3848 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3849 | |
| 3850 | if (rhs.IsConstant()) { |
| 3851 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3852 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3853 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3854 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3855 | // logic below to a simple pair of binary orr. |
| 3856 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3857 | if (rot >= kArmBitsPerWord) { |
| 3858 | rot -= kArmBitsPerWord; |
| 3859 | std::swap(in_reg_hi, in_reg_lo); |
| 3860 | } |
| 3861 | // Rotate, or mov to out for zero or word size rotations. |
| 3862 | if (rot != 0u) { |
| 3863 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3864 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3865 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3866 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3867 | } else { |
| 3868 | __ Mov(out_reg_lo, in_reg_lo); |
| 3869 | __ Mov(out_reg_hi, in_reg_hi); |
| 3870 | } |
| 3871 | } else { |
| 3872 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3873 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3874 | Label end; |
| 3875 | Label shift_by_32_plus_shift_right; |
| 3876 | |
| 3877 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3878 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3879 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3880 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3881 | |
| 3882 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3883 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3884 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3885 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3886 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3887 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3888 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3889 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3890 | __ b(&end); |
| 3891 | |
| 3892 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3893 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3894 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3895 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3896 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3897 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3898 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3899 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3900 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3901 | |
| 3902 | __ Bind(&end); |
| 3903 | } |
| 3904 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3905 | |
| 3906 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3907 | LocationSummary* locations = |
| 3908 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3909 | switch (ror->GetResultType()) { |
| 3910 | case Primitive::kPrimInt: { |
| 3911 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3912 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3913 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3914 | break; |
| 3915 | } |
| 3916 | case Primitive::kPrimLong: { |
| 3917 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3918 | if (ror->InputAt(1)->IsConstant()) { |
| 3919 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3920 | } else { |
| 3921 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3922 | locations->AddTemp(Location::RequiresRegister()); |
| 3923 | locations->AddTemp(Location::RequiresRegister()); |
| 3924 | } |
| 3925 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3926 | break; |
| 3927 | } |
| 3928 | default: |
| 3929 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3930 | } |
| 3931 | } |
| 3932 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3933 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3934 | LocationSummary* locations = ror->GetLocations(); |
| 3935 | Primitive::Type type = ror->GetResultType(); |
| 3936 | switch (type) { |
| 3937 | case Primitive::kPrimInt: { |
| 3938 | HandleIntegerRotate(locations); |
| 3939 | break; |
| 3940 | } |
| 3941 | case Primitive::kPrimLong: { |
| 3942 | HandleLongRotate(locations); |
| 3943 | break; |
| 3944 | } |
| 3945 | default: |
| 3946 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3947 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3948 | } |
| 3949 | } |
| 3950 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3951 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3952 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3953 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3954 | LocationSummary* locations = |
| 3955 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3956 | |
| 3957 | switch (op->GetResultType()) { |
| 3958 | case Primitive::kPrimInt: { |
| 3959 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3960 | if (op->InputAt(1)->IsConstant()) { |
| 3961 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3962 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3963 | } else { |
| 3964 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3965 | // Make the output overlap, as it will be used to hold the masked |
| 3966 | // second input. |
| 3967 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3968 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3969 | break; |
| 3970 | } |
| 3971 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3972 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3973 | if (op->InputAt(1)->IsConstant()) { |
| 3974 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3975 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3976 | // don't clash with high registers which the register allocator currently guarantees. |
| 3977 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3978 | } else { |
| 3979 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3980 | locations->AddTemp(Location::RequiresRegister()); |
| 3981 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3982 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3983 | break; |
| 3984 | } |
| 3985 | default: |
| 3986 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3991 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3992 | |
| 3993 | LocationSummary* locations = op->GetLocations(); |
| 3994 | Location out = locations->Out(); |
| 3995 | Location first = locations->InAt(0); |
| 3996 | Location second = locations->InAt(1); |
| 3997 | |
| 3998 | Primitive::Type type = op->GetResultType(); |
| 3999 | switch (type) { |
| 4000 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4001 | Register out_reg = out.AsRegister<Register>(); |
| 4002 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4003 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4004 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4005 | // 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] | 4006 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4007 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4008 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4009 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4010 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4011 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4012 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4013 | } |
| 4014 | } else { |
| 4015 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4016 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4017 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4018 | __ Mov(out_reg, first_reg); |
| 4019 | } else if (op->IsShl()) { |
| 4020 | __ Lsl(out_reg, first_reg, shift_value); |
| 4021 | } else if (op->IsShr()) { |
| 4022 | __ Asr(out_reg, first_reg, shift_value); |
| 4023 | } else { |
| 4024 | __ Lsr(out_reg, first_reg, shift_value); |
| 4025 | } |
| 4026 | } |
| 4027 | break; |
| 4028 | } |
| 4029 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4030 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4031 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4032 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4033 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4034 | Register low = first.AsRegisterPairLow<Register>(); |
| 4035 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4036 | if (second.IsRegister()) { |
| 4037 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4038 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4039 | Register second_reg = second.AsRegister<Register>(); |
| 4040 | |
| 4041 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4042 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4043 | // Shift the high part |
| 4044 | __ Lsl(o_h, high, o_l); |
| 4045 | // Shift the low part and `or` what overflew on the high part |
| 4046 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4047 | __ Lsr(temp, low, temp); |
| 4048 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4049 | // If the shift is > 32 bits, override the high part |
| 4050 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4051 | __ it(PL); |
| 4052 | __ Lsl(o_h, low, temp, PL); |
| 4053 | // Shift the low part |
| 4054 | __ Lsl(o_l, low, o_l); |
| 4055 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4056 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4057 | // Shift the low part |
| 4058 | __ Lsr(o_l, low, o_h); |
| 4059 | // Shift the high part and `or` what underflew on the low part |
| 4060 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4061 | __ Lsl(temp, high, temp); |
| 4062 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4063 | // If the shift is > 32 bits, override the low part |
| 4064 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4065 | __ it(PL); |
| 4066 | __ Asr(o_l, high, temp, PL); |
| 4067 | // Shift the high part |
| 4068 | __ Asr(o_h, high, o_h); |
| 4069 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4070 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4071 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4072 | __ Lsr(o_l, low, o_h); |
| 4073 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4074 | __ Lsl(temp, high, temp); |
| 4075 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4076 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4077 | __ it(PL); |
| 4078 | __ Lsr(o_l, high, temp, PL); |
| 4079 | __ Lsr(o_h, high, o_h); |
| 4080 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4081 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4082 | // Register allocator doesn't create partial overlap. |
| 4083 | DCHECK_NE(o_l, high); |
| 4084 | DCHECK_NE(o_h, low); |
| 4085 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4086 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4087 | if (shift_value > 32) { |
| 4088 | if (op->IsShl()) { |
| 4089 | __ Lsl(o_h, low, shift_value - 32); |
| 4090 | __ LoadImmediate(o_l, 0); |
| 4091 | } else if (op->IsShr()) { |
| 4092 | __ Asr(o_l, high, shift_value - 32); |
| 4093 | __ Asr(o_h, high, 31); |
| 4094 | } else { |
| 4095 | __ Lsr(o_l, high, shift_value - 32); |
| 4096 | __ LoadImmediate(o_h, 0); |
| 4097 | } |
| 4098 | } else if (shift_value == 32) { |
| 4099 | if (op->IsShl()) { |
| 4100 | __ mov(o_h, ShifterOperand(low)); |
| 4101 | __ LoadImmediate(o_l, 0); |
| 4102 | } else if (op->IsShr()) { |
| 4103 | __ mov(o_l, ShifterOperand(high)); |
| 4104 | __ Asr(o_h, high, 31); |
| 4105 | } else { |
| 4106 | __ mov(o_l, ShifterOperand(high)); |
| 4107 | __ LoadImmediate(o_h, 0); |
| 4108 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4109 | } else if (shift_value == 1) { |
| 4110 | if (op->IsShl()) { |
| 4111 | __ Lsls(o_l, low, 1); |
| 4112 | __ adc(o_h, high, ShifterOperand(high)); |
| 4113 | } else if (op->IsShr()) { |
| 4114 | __ Asrs(o_h, high, 1); |
| 4115 | __ Rrx(o_l, low); |
| 4116 | } else { |
| 4117 | __ Lsrs(o_h, high, 1); |
| 4118 | __ Rrx(o_l, low); |
| 4119 | } |
| 4120 | } else { |
| 4121 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4122 | if (op->IsShl()) { |
| 4123 | __ Lsl(o_h, high, shift_value); |
| 4124 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4125 | __ Lsl(o_l, low, shift_value); |
| 4126 | } else if (op->IsShr()) { |
| 4127 | __ Lsr(o_l, low, shift_value); |
| 4128 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4129 | __ Asr(o_h, high, shift_value); |
| 4130 | } else { |
| 4131 | __ Lsr(o_l, low, shift_value); |
| 4132 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4133 | __ Lsr(o_h, high, shift_value); |
| 4134 | } |
| 4135 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4136 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4137 | break; |
| 4138 | } |
| 4139 | default: |
| 4140 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4141 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | |
| 4145 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4146 | HandleShift(shl); |
| 4147 | } |
| 4148 | |
| 4149 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4150 | HandleShift(shl); |
| 4151 | } |
| 4152 | |
| 4153 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4154 | HandleShift(shr); |
| 4155 | } |
| 4156 | |
| 4157 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4158 | HandleShift(shr); |
| 4159 | } |
| 4160 | |
| 4161 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4162 | HandleShift(ushr); |
| 4163 | } |
| 4164 | |
| 4165 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4166 | HandleShift(ushr); |
| 4167 | } |
| 4168 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4169 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4170 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4171 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4172 | if (instruction->IsStringAlloc()) { |
| 4173 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4174 | } else { |
| 4175 | InvokeRuntimeCallingConvention calling_convention; |
| 4176 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4177 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4178 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4182 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4183 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4184 | if (instruction->IsStringAlloc()) { |
| 4185 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4186 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4187 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4188 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4189 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4190 | __ blx(LR); |
| 4191 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4192 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4193 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4194 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4195 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4198 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4199 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4200 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4201 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4202 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4203 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4204 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4208 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4209 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4210 | QuickEntrypointEnum entrypoint = |
| 4211 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4212 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4213 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4214 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4215 | } |
| 4216 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4217 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4218 | LocationSummary* locations = |
| 4219 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4220 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4221 | if (location.IsStackSlot()) { |
| 4222 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4223 | } else if (location.IsDoubleStackSlot()) { |
| 4224 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4225 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4226 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4227 | } |
| 4228 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4229 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4230 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4231 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4235 | LocationSummary* locations = |
| 4236 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4237 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4238 | } |
| 4239 | |
| 4240 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4241 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4242 | } |
| 4243 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4244 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4245 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4246 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4247 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4248 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4251 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4252 | LocationSummary* locations = not_->GetLocations(); |
| 4253 | Location out = locations->Out(); |
| 4254 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4255 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4256 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4257 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4258 | break; |
| 4259 | |
| 4260 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4261 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4262 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4263 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4264 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4265 | break; |
| 4266 | |
| 4267 | default: |
| 4268 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4269 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4272 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4273 | LocationSummary* locations = |
| 4274 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4276 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4277 | } |
| 4278 | |
| 4279 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4280 | LocationSummary* locations = bool_not->GetLocations(); |
| 4281 | Location out = locations->Out(); |
| 4282 | Location in = locations->InAt(0); |
| 4283 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4284 | } |
| 4285 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4286 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4287 | LocationSummary* locations = |
| 4288 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4289 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4290 | case Primitive::kPrimBoolean: |
| 4291 | case Primitive::kPrimByte: |
| 4292 | case Primitive::kPrimShort: |
| 4293 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4294 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4295 | case Primitive::kPrimLong: { |
| 4296 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4297 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4298 | // Output overlaps because it is written before doing the low comparison. |
| 4299 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4300 | break; |
| 4301 | } |
| 4302 | case Primitive::kPrimFloat: |
| 4303 | case Primitive::kPrimDouble: { |
| 4304 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4305 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4306 | locations->SetOut(Location::RequiresRegister()); |
| 4307 | break; |
| 4308 | } |
| 4309 | default: |
| 4310 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4311 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4315 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4316 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4317 | Location left = locations->InAt(0); |
| 4318 | Location right = locations->InAt(1); |
| 4319 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4320 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4321 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4322 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4323 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4324 | case Primitive::kPrimBoolean: |
| 4325 | case Primitive::kPrimByte: |
| 4326 | case Primitive::kPrimShort: |
| 4327 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4328 | case Primitive::kPrimInt: { |
| 4329 | __ LoadImmediate(out, 0); |
| 4330 | __ cmp(left.AsRegister<Register>(), |
| 4331 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4332 | less_cond = LT; |
| 4333 | break; |
| 4334 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4335 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4336 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4337 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4338 | __ b(&less, LT); |
| 4339 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4340 | // 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] | 4341 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4342 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4343 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4344 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4345 | break; |
| 4346 | } |
| 4347 | case Primitive::kPrimFloat: |
| 4348 | case Primitive::kPrimDouble: { |
| 4349 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4350 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4351 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4352 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4353 | break; |
| 4354 | } |
| 4355 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4356 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4357 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4358 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4359 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4360 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4361 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4362 | |
| 4363 | __ Bind(&greater); |
| 4364 | __ LoadImmediate(out, 1); |
| 4365 | __ b(&done); |
| 4366 | |
| 4367 | __ Bind(&less); |
| 4368 | __ LoadImmediate(out, -1); |
| 4369 | |
| 4370 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4371 | } |
| 4372 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4373 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4374 | LocationSummary* locations = |
| 4375 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4376 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4377 | locations->SetInAt(i, Location::Any()); |
| 4378 | } |
| 4379 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4380 | } |
| 4381 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4382 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4383 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4384 | } |
| 4385 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4386 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4387 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4388 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4389 | switch (kind) { |
| 4390 | case MemBarrierKind::kAnyStore: |
| 4391 | case MemBarrierKind::kLoadAny: |
| 4392 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4393 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4394 | break; |
| 4395 | } |
| 4396 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4397 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4398 | break; |
| 4399 | } |
| 4400 | default: |
| 4401 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4402 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4403 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4407 | uint32_t offset, |
| 4408 | Register out_lo, |
| 4409 | Register out_hi) { |
| 4410 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4411 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4412 | // `offset` into `out_lo` does not clutter `addr`. |
| 4413 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4414 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4415 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4416 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4417 | } |
| 4418 | __ ldrexd(out_lo, out_hi, addr); |
| 4419 | } |
| 4420 | |
| 4421 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4422 | uint32_t offset, |
| 4423 | Register value_lo, |
| 4424 | Register value_hi, |
| 4425 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4426 | Register temp2, |
| 4427 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4428 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4429 | if (offset != 0) { |
| 4430 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4431 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4432 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4433 | } |
| 4434 | __ Bind(&fail); |
| 4435 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4436 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4437 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4438 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4439 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4440 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4444 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4445 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4446 | LocationSummary* locations = |
| 4447 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4448 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4449 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4450 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4451 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4452 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4453 | } else { |
| 4454 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4455 | } |
| 4456 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4457 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4458 | bool generate_volatile = field_info.IsVolatile() |
| 4459 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4460 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4461 | bool needs_write_barrier = |
| 4462 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4463 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4464 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4465 | if (needs_write_barrier) { |
| 4466 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4467 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4468 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4469 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4470 | // - registers need to be consecutive |
| 4471 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4472 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4473 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4474 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4475 | |
| 4476 | locations->AddTemp(Location::RequiresRegister()); |
| 4477 | locations->AddTemp(Location::RequiresRegister()); |
| 4478 | if (field_type == Primitive::kPrimDouble) { |
| 4479 | // For doubles we need two more registers to copy the value. |
| 4480 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4481 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4482 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4483 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4484 | } |
| 4485 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4486 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4487 | const FieldInfo& field_info, |
| 4488 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4489 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4490 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4491 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4492 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4493 | Location value = locations->InAt(1); |
| 4494 | |
| 4495 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4496 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4497 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4498 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4499 | bool needs_write_barrier = |
| 4500 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4501 | |
| 4502 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4503 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4504 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4505 | |
| 4506 | switch (field_type) { |
| 4507 | case Primitive::kPrimBoolean: |
| 4508 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4509 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4510 | break; |
| 4511 | } |
| 4512 | |
| 4513 | case Primitive::kPrimShort: |
| 4514 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4515 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4516 | break; |
| 4517 | } |
| 4518 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4519 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4520 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4521 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4522 | // Note that in the case where `value` is a null reference, |
| 4523 | // we do not enter this block, as a null reference does not |
| 4524 | // need poisoning. |
| 4525 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4526 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4527 | __ Mov(temp, value.AsRegister<Register>()); |
| 4528 | __ PoisonHeapReference(temp); |
| 4529 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4530 | } else { |
| 4531 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4532 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4533 | break; |
| 4534 | } |
| 4535 | |
| 4536 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4537 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4538 | GenerateWideAtomicStore(base, offset, |
| 4539 | value.AsRegisterPairLow<Register>(), |
| 4540 | value.AsRegisterPairHigh<Register>(), |
| 4541 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4542 | locations->GetTemp(1).AsRegister<Register>(), |
| 4543 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4544 | } else { |
| 4545 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4546 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4547 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4548 | break; |
| 4549 | } |
| 4550 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4551 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4552 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4553 | break; |
| 4554 | } |
| 4555 | |
| 4556 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4557 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4558 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4560 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4561 | |
| 4562 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4563 | |
| 4564 | GenerateWideAtomicStore(base, offset, |
| 4565 | value_reg_lo, |
| 4566 | value_reg_hi, |
| 4567 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4568 | locations->GetTemp(3).AsRegister<Register>(), |
| 4569 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4570 | } else { |
| 4571 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4572 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4573 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4574 | break; |
| 4575 | } |
| 4576 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4577 | case Primitive::kPrimVoid: |
| 4578 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4579 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4580 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4581 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4582 | // Longs and doubles are handled in the switch. |
| 4583 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4584 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4585 | } |
| 4586 | |
| 4587 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4588 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4589 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4590 | codegen_->MarkGCCard( |
| 4591 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4592 | } |
| 4593 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4594 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4595 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4596 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4597 | } |
| 4598 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4599 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4600 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4601 | |
| 4602 | bool object_field_get_with_read_barrier = |
| 4603 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4604 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4605 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4606 | object_field_get_with_read_barrier ? |
| 4607 | LocationSummary::kCallOnSlowPath : |
| 4608 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4609 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4610 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4611 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4612 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4613 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4614 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4615 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4616 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4617 | // The output overlaps in case of volatile long: we don't want the |
| 4618 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4619 | // object's location. Likewise, in the case of an object field get |
| 4620 | // with read barriers enabled, we do not want the load to overwrite |
| 4621 | // the object's location, as we need it to emit the read barrier. |
| 4622 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4623 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4624 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4625 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4626 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4627 | } else { |
| 4628 | locations->SetOut(Location::RequiresRegister(), |
| 4629 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4630 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4631 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4632 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | // - registers need to be consecutive |
| 4634 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4635 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4636 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4637 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4638 | locations->AddTemp(Location::RequiresRegister()); |
| 4639 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4640 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4641 | // We need a temporary register for the read barrier marking slow |
| 4642 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4643 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4645 | } |
| 4646 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4647 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4648 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4649 | << input->GetType(); |
| 4650 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4651 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4652 | return Location::ConstantLocation(input->AsConstant()); |
| 4653 | } else { |
| 4654 | return Location::RequiresFpuRegister(); |
| 4655 | } |
| 4656 | } |
| 4657 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4658 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4659 | Opcode opcode) { |
| 4660 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4661 | if (constant->IsConstant() && |
| 4662 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4663 | return Location::ConstantLocation(constant->AsConstant()); |
| 4664 | } |
| 4665 | return Location::RequiresRegister(); |
| 4666 | } |
| 4667 | |
| 4668 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4669 | Opcode opcode) { |
| 4670 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4671 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4672 | Opcode high_opcode = opcode; |
| 4673 | SetCc low_set_cc = kCcDontCare; |
| 4674 | switch (opcode) { |
| 4675 | case SUB: |
| 4676 | // Flip the operation to an ADD. |
| 4677 | value = -value; |
| 4678 | opcode = ADD; |
| 4679 | FALLTHROUGH_INTENDED; |
| 4680 | case ADD: |
| 4681 | if (Low32Bits(value) == 0u) { |
| 4682 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4683 | } |
| 4684 | high_opcode = ADC; |
| 4685 | low_set_cc = kCcSet; |
| 4686 | break; |
| 4687 | default: |
| 4688 | break; |
| 4689 | } |
| 4690 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4691 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4692 | } else { |
| 4693 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4694 | } |
| 4695 | } |
| 4696 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4697 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4698 | Opcode opcode, |
| 4699 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4700 | ShifterOperand so; |
| 4701 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4702 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4703 | return true; |
| 4704 | } |
| 4705 | Opcode neg_opcode = kNoOperand; |
| 4706 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4707 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4708 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4709 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4710 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4711 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4712 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4713 | default: |
| 4714 | return false; |
| 4715 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4716 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4717 | } |
| 4718 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4720 | const FieldInfo& field_info) { |
| 4721 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4722 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4723 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4724 | Location base_loc = locations->InAt(0); |
| 4725 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4726 | Location out = locations->Out(); |
| 4727 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4728 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4729 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4730 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4731 | |
| 4732 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4733 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4734 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4735 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4736 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4737 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4738 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4739 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4740 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4741 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4742 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4743 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4744 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4745 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4746 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4747 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4748 | |
| 4749 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4751 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4752 | |
| 4753 | case Primitive::kPrimNot: { |
| 4754 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4755 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4756 | Location temp_loc = locations->GetTemp(0); |
| 4757 | // Note that a potential implicit null check is handled in this |
| 4758 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4759 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4760 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4761 | if (is_volatile) { |
| 4762 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4763 | } |
| 4764 | } else { |
| 4765 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4766 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4767 | if (is_volatile) { |
| 4768 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4769 | } |
| 4770 | // If read barriers are enabled, emit read barriers other than |
| 4771 | // Baker's using a slow path (and also unpoison the loaded |
| 4772 | // reference, if heap poisoning is enabled). |
| 4773 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4774 | } |
| 4775 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4776 | } |
| 4777 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4778 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4779 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4780 | GenerateWideAtomicLoad(base, offset, |
| 4781 | out.AsRegisterPairLow<Register>(), |
| 4782 | out.AsRegisterPairHigh<Register>()); |
| 4783 | } else { |
| 4784 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4785 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4786 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4787 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4788 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4789 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4790 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4791 | |
| 4792 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4793 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4794 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4795 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4796 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4797 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4798 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4799 | __ vmovdrr(out_reg, lo, hi); |
| 4800 | } else { |
| 4801 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4802 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4803 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4804 | break; |
| 4805 | } |
| 4806 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4807 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4808 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4809 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4810 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4811 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4812 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4813 | // Potential implicit null checks, in the case of reference or |
| 4814 | // double fields, are handled in the previous switch statement. |
| 4815 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4816 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4817 | } |
| 4818 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4819 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4820 | if (field_type == Primitive::kPrimNot) { |
| 4821 | // Memory barriers, in the case of references, are also handled |
| 4822 | // in the previous switch statement. |
| 4823 | } else { |
| 4824 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4825 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4826 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4830 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4831 | } |
| 4832 | |
| 4833 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4834 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4838 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4839 | } |
| 4840 | |
| 4841 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4842 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4843 | } |
| 4844 | |
| 4845 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4846 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4847 | } |
| 4848 | |
| 4849 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4850 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4851 | } |
| 4852 | |
| 4853 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4854 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4855 | } |
| 4856 | |
| 4857 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4858 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4859 | } |
| 4860 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4861 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4862 | HUnresolvedInstanceFieldGet* instruction) { |
| 4863 | FieldAccessCallingConventionARM calling_convention; |
| 4864 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4865 | instruction, instruction->GetFieldType(), calling_convention); |
| 4866 | } |
| 4867 | |
| 4868 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4869 | HUnresolvedInstanceFieldGet* instruction) { |
| 4870 | FieldAccessCallingConventionARM calling_convention; |
| 4871 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4872 | instruction->GetFieldType(), |
| 4873 | instruction->GetFieldIndex(), |
| 4874 | instruction->GetDexPc(), |
| 4875 | calling_convention); |
| 4876 | } |
| 4877 | |
| 4878 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4879 | HUnresolvedInstanceFieldSet* instruction) { |
| 4880 | FieldAccessCallingConventionARM calling_convention; |
| 4881 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4882 | instruction, instruction->GetFieldType(), calling_convention); |
| 4883 | } |
| 4884 | |
| 4885 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4886 | HUnresolvedInstanceFieldSet* instruction) { |
| 4887 | FieldAccessCallingConventionARM calling_convention; |
| 4888 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4889 | instruction->GetFieldType(), |
| 4890 | instruction->GetFieldIndex(), |
| 4891 | instruction->GetDexPc(), |
| 4892 | calling_convention); |
| 4893 | } |
| 4894 | |
| 4895 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4896 | HUnresolvedStaticFieldGet* instruction) { |
| 4897 | FieldAccessCallingConventionARM calling_convention; |
| 4898 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4899 | instruction, instruction->GetFieldType(), calling_convention); |
| 4900 | } |
| 4901 | |
| 4902 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4903 | HUnresolvedStaticFieldGet* instruction) { |
| 4904 | FieldAccessCallingConventionARM calling_convention; |
| 4905 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4906 | instruction->GetFieldType(), |
| 4907 | instruction->GetFieldIndex(), |
| 4908 | instruction->GetDexPc(), |
| 4909 | calling_convention); |
| 4910 | } |
| 4911 | |
| 4912 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4913 | HUnresolvedStaticFieldSet* instruction) { |
| 4914 | FieldAccessCallingConventionARM calling_convention; |
| 4915 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4916 | instruction, instruction->GetFieldType(), calling_convention); |
| 4917 | } |
| 4918 | |
| 4919 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4920 | HUnresolvedStaticFieldSet* instruction) { |
| 4921 | FieldAccessCallingConventionARM calling_convention; |
| 4922 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4923 | instruction->GetFieldType(), |
| 4924 | instruction->GetFieldIndex(), |
| 4925 | instruction->GetDexPc(), |
| 4926 | calling_convention); |
| 4927 | } |
| 4928 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4929 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4930 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4931 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4932 | } |
| 4933 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4934 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4935 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4936 | return; |
| 4937 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4938 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4939 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4940 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4941 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4944 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4945 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4946 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4947 | |
| 4948 | LocationSummary* locations = instruction->GetLocations(); |
| 4949 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4950 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4951 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4952 | } |
| 4953 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4954 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4955 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4958 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4959 | switch (type) { |
| 4960 | case Primitive::kPrimNot: |
| 4961 | return kLoadWord; |
| 4962 | case Primitive::kPrimBoolean: |
| 4963 | return kLoadUnsignedByte; |
| 4964 | case Primitive::kPrimByte: |
| 4965 | return kLoadSignedByte; |
| 4966 | case Primitive::kPrimChar: |
| 4967 | return kLoadUnsignedHalfword; |
| 4968 | case Primitive::kPrimShort: |
| 4969 | return kLoadSignedHalfword; |
| 4970 | case Primitive::kPrimInt: |
| 4971 | return kLoadWord; |
| 4972 | case Primitive::kPrimLong: |
| 4973 | return kLoadWordPair; |
| 4974 | case Primitive::kPrimFloat: |
| 4975 | return kLoadSWord; |
| 4976 | case Primitive::kPrimDouble: |
| 4977 | return kLoadDWord; |
| 4978 | default: |
| 4979 | LOG(FATAL) << "Unreachable type " << type; |
| 4980 | UNREACHABLE(); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4985 | switch (type) { |
| 4986 | case Primitive::kPrimNot: |
| 4987 | return kStoreWord; |
| 4988 | case Primitive::kPrimBoolean: |
| 4989 | case Primitive::kPrimByte: |
| 4990 | return kStoreByte; |
| 4991 | case Primitive::kPrimChar: |
| 4992 | case Primitive::kPrimShort: |
| 4993 | return kStoreHalfword; |
| 4994 | case Primitive::kPrimInt: |
| 4995 | return kStoreWord; |
| 4996 | case Primitive::kPrimLong: |
| 4997 | return kStoreWordPair; |
| 4998 | case Primitive::kPrimFloat: |
| 4999 | return kStoreSWord; |
| 5000 | case Primitive::kPrimDouble: |
| 5001 | return kStoreDWord; |
| 5002 | default: |
| 5003 | LOG(FATAL) << "Unreachable type " << type; |
| 5004 | UNREACHABLE(); |
| 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5009 | Location out_loc, |
| 5010 | Register base, |
| 5011 | Register reg_offset, |
| 5012 | Condition cond) { |
| 5013 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5014 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5015 | |
| 5016 | switch (type) { |
| 5017 | case Primitive::kPrimByte: |
| 5018 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5019 | break; |
| 5020 | case Primitive::kPrimBoolean: |
| 5021 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5022 | break; |
| 5023 | case Primitive::kPrimShort: |
| 5024 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5025 | break; |
| 5026 | case Primitive::kPrimChar: |
| 5027 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5028 | break; |
| 5029 | case Primitive::kPrimNot: |
| 5030 | case Primitive::kPrimInt: |
| 5031 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5032 | break; |
| 5033 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5034 | case Primitive::kPrimLong: |
| 5035 | case Primitive::kPrimFloat: |
| 5036 | case Primitive::kPrimDouble: |
| 5037 | default: |
| 5038 | LOG(FATAL) << "Unreachable type " << type; |
| 5039 | UNREACHABLE(); |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5044 | Location loc, |
| 5045 | Register base, |
| 5046 | Register reg_offset, |
| 5047 | Condition cond) { |
| 5048 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5049 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5050 | |
| 5051 | switch (type) { |
| 5052 | case Primitive::kPrimByte: |
| 5053 | case Primitive::kPrimBoolean: |
| 5054 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5055 | break; |
| 5056 | case Primitive::kPrimShort: |
| 5057 | case Primitive::kPrimChar: |
| 5058 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5059 | break; |
| 5060 | case Primitive::kPrimNot: |
| 5061 | case Primitive::kPrimInt: |
| 5062 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5063 | break; |
| 5064 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5065 | case Primitive::kPrimLong: |
| 5066 | case Primitive::kPrimFloat: |
| 5067 | case Primitive::kPrimDouble: |
| 5068 | default: |
| 5069 | LOG(FATAL) << "Unreachable type " << type; |
| 5070 | UNREACHABLE(); |
| 5071 | } |
| 5072 | } |
| 5073 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5075 | bool object_array_get_with_read_barrier = |
| 5076 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5077 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5078 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5079 | object_array_get_with_read_barrier ? |
| 5080 | LocationSummary::kCallOnSlowPath : |
| 5081 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5082 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5083 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5084 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5085 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5086 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5087 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5088 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5089 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5090 | // The output overlaps in the case of an object array get with |
| 5091 | // read barriers enabled: we do not want the move to overwrite the |
| 5092 | // array's location, as we need it to emit the read barrier. |
| 5093 | locations->SetOut( |
| 5094 | Location::RequiresRegister(), |
| 5095 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5096 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5097 | // We need a temporary register for the read barrier marking slow |
| 5098 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5099 | // Also need for String compression feature. |
| 5100 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5101 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5102 | locations->AddTemp(Location::RequiresRegister()); |
| 5103 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5107 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5108 | Location obj_loc = locations->InAt(0); |
| 5109 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5110 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5111 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5112 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5113 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5114 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5115 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5116 | HInstruction* array_instr = instruction->GetArray(); |
| 5117 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5118 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5119 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5120 | case Primitive::kPrimBoolean: |
| 5121 | case Primitive::kPrimByte: |
| 5122 | case Primitive::kPrimShort: |
| 5123 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5124 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5125 | Register length; |
| 5126 | if (maybe_compressed_char_at) { |
| 5127 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5128 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5129 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5130 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5131 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5133 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5134 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5135 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5136 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5137 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5138 | "Expecting 0=compressed, 1=uncompressed"); |
| 5139 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5140 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5141 | out_loc.AsRegister<Register>(), |
| 5142 | obj, |
| 5143 | data_offset + const_index); |
| 5144 | __ b(&done); |
| 5145 | __ Bind(&uncompressed_load); |
| 5146 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5147 | out_loc.AsRegister<Register>(), |
| 5148 | obj, |
| 5149 | data_offset + (const_index << 1)); |
| 5150 | __ Bind(&done); |
| 5151 | } else { |
| 5152 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5153 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5154 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5155 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5156 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5158 | Register temp = IP; |
| 5159 | |
| 5160 | if (has_intermediate_address) { |
| 5161 | // We do not need to compute the intermediate address from the array: the |
| 5162 | // input instruction has done it already. See the comment in |
| 5163 | // `TryExtractArrayAccessAddress()`. |
| 5164 | if (kIsDebugBuild) { |
| 5165 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5166 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5167 | } |
| 5168 | temp = obj; |
| 5169 | } else { |
| 5170 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5171 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5172 | if (maybe_compressed_char_at) { |
| 5173 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5174 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5175 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5176 | "Expecting 0=compressed, 1=uncompressed"); |
| 5177 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5178 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5179 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 5180 | __ b(&done); |
| 5181 | __ Bind(&uncompressed_load); |
| 5182 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5183 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 5184 | __ Bind(&done); |
| 5185 | } else { |
| 5186 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5187 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5188 | } |
| 5189 | break; |
| 5190 | } |
| 5191 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5192 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5193 | // The read barrier instrumentation of object ArrayGet |
| 5194 | // instructions does not support the HIntermediateAddress |
| 5195 | // instruction. |
| 5196 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5197 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5198 | static_assert( |
| 5199 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5200 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5201 | // /* HeapReference<Object> */ out = |
| 5202 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5203 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5204 | Location temp = locations->GetTemp(0); |
| 5205 | // Note that a potential implicit null check is handled in this |
| 5206 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 5207 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5208 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5209 | } else { |
| 5210 | Register out = out_loc.AsRegister<Register>(); |
| 5211 | if (index.IsConstant()) { |
| 5212 | size_t offset = |
| 5213 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5214 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5215 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5216 | // If read barriers are enabled, emit read barriers other than |
| 5217 | // Baker's using a slow path (and also unpoison the loaded |
| 5218 | // reference, if heap poisoning is enabled). |
| 5219 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5220 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5221 | Register temp = IP; |
| 5222 | |
| 5223 | if (has_intermediate_address) { |
| 5224 | // We do not need to compute the intermediate address from the array: the |
| 5225 | // input instruction has done it already. See the comment in |
| 5226 | // `TryExtractArrayAccessAddress()`. |
| 5227 | if (kIsDebugBuild) { |
| 5228 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5229 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5230 | } |
| 5231 | temp = obj; |
| 5232 | } else { |
| 5233 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5234 | } |
| 5235 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5236 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5237 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5238 | // If read barriers are enabled, emit read barriers other than |
| 5239 | // Baker's using a slow path (and also unpoison the loaded |
| 5240 | // reference, if heap poisoning is enabled). |
| 5241 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5242 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5243 | } |
| 5244 | } |
| 5245 | break; |
| 5246 | } |
| 5247 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5248 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5249 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5250 | size_t offset = |
| 5251 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5252 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5253 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5254 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5255 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | } |
| 5257 | break; |
| 5258 | } |
| 5259 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5260 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5261 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5262 | if (index.IsConstant()) { |
| 5263 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5264 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5265 | } else { |
| 5266 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5267 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5268 | } |
| 5269 | break; |
| 5270 | } |
| 5271 | |
| 5272 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5273 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5274 | if (index.IsConstant()) { |
| 5275 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5276 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5277 | } else { |
| 5278 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5279 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5280 | } |
| 5281 | break; |
| 5282 | } |
| 5283 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5284 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5285 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5286 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5287 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5288 | |
| 5289 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5290 | // Potential implicit null checks, in the case of reference |
| 5291 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5292 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5294 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5298 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5299 | |
| 5300 | bool needs_write_barrier = |
| 5301 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5302 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5303 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5304 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5306 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5307 | LocationSummary::kCallOnSlowPath : |
| 5308 | LocationSummary::kNoCall); |
| 5309 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5310 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5311 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5312 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5313 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5314 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5315 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5316 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5317 | if (needs_write_barrier) { |
| 5318 | // Temporary registers for the write barrier. |
| 5319 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5320 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5325 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5326 | Location array_loc = locations->InAt(0); |
| 5327 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5329 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5330 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5331 | bool needs_write_barrier = |
| 5332 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5333 | uint32_t data_offset = |
| 5334 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5335 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5336 | HInstruction* array_instr = instruction->GetArray(); |
| 5337 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5338 | |
| 5339 | switch (value_type) { |
| 5340 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5341 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5342 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5343 | case Primitive::kPrimChar: |
| 5344 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5345 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5346 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5347 | uint32_t full_offset = |
| 5348 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5349 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5350 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5351 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5352 | Register temp = IP; |
| 5353 | |
| 5354 | if (has_intermediate_address) { |
| 5355 | // We do not need to compute the intermediate address from the array: the |
| 5356 | // input instruction has done it already. See the comment in |
| 5357 | // `TryExtractArrayAccessAddress()`. |
| 5358 | if (kIsDebugBuild) { |
| 5359 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5360 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5361 | } |
| 5362 | temp = array; |
| 5363 | } else { |
| 5364 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5365 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5366 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5367 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5368 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5369 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5370 | } |
| 5371 | break; |
| 5372 | } |
| 5373 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5374 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5375 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5376 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5377 | // See the comment in instruction_simplifier_shared.cc. |
| 5378 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5379 | |
| 5380 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5381 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5382 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5383 | size_t offset = |
| 5384 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5385 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5386 | } else { |
| 5387 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5388 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5389 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5390 | value_loc, |
| 5391 | IP, |
| 5392 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5393 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5394 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5395 | DCHECK(!needs_write_barrier); |
| 5396 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5397 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5398 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5399 | |
| 5400 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5401 | Location temp1_loc = locations->GetTemp(0); |
| 5402 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5403 | Location temp2_loc = locations->GetTemp(1); |
| 5404 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5405 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5406 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5407 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5408 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5409 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5410 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5411 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5412 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5413 | codegen_->AddSlowPath(slow_path); |
| 5414 | if (instruction->GetValueCanBeNull()) { |
| 5415 | Label non_zero; |
| 5416 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5417 | if (index.IsConstant()) { |
| 5418 | size_t offset = |
| 5419 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5420 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5421 | } else { |
| 5422 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5423 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5424 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5425 | value_loc, |
| 5426 | IP, |
| 5427 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5428 | } |
| 5429 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5430 | __ b(&done); |
| 5431 | __ Bind(&non_zero); |
| 5432 | } |
| 5433 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5434 | // Note that when read barriers are enabled, the type checks |
| 5435 | // are performed without read barriers. This is fine, even in |
| 5436 | // the case where a class object is in the from-space after |
| 5437 | // the flip, as a comparison involving such a type would not |
| 5438 | // produce a false positive; it may of course produce a false |
| 5439 | // negative, in which case we would take the ArraySet slow |
| 5440 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5441 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5442 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5443 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5444 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5445 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5446 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5447 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5448 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5449 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5450 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5451 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5452 | // nor `temp2`, as we are comparing two poisoned references. |
| 5453 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5454 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5455 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5456 | Label do_put; |
| 5457 | __ b(&do_put, EQ); |
| 5458 | // If heap poisoning is enabled, the `temp1` reference has |
| 5459 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5460 | __ MaybeUnpoisonHeapReference(temp1); |
| 5461 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5462 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5463 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5464 | // If heap poisoning is enabled, no need to unpoison |
| 5465 | // `temp1`, as we are comparing against null below. |
| 5466 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5467 | __ Bind(&do_put); |
| 5468 | } else { |
| 5469 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5470 | } |
| 5471 | } |
| 5472 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5473 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5474 | if (kPoisonHeapReferences) { |
| 5475 | // Note that in the case where `value` is a null reference, |
| 5476 | // we do not enter this block, as a null reference does not |
| 5477 | // need poisoning. |
| 5478 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5479 | __ Mov(temp1, value); |
| 5480 | __ PoisonHeapReference(temp1); |
| 5481 | source = temp1; |
| 5482 | } |
| 5483 | |
| 5484 | if (index.IsConstant()) { |
| 5485 | size_t offset = |
| 5486 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5487 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5488 | } else { |
| 5489 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5490 | |
| 5491 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5492 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5493 | Location::RegisterLocation(source), |
| 5494 | IP, |
| 5495 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5496 | } |
| 5497 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5498 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5500 | } |
| 5501 | |
| 5502 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5503 | |
| 5504 | if (done.IsLinked()) { |
| 5505 | __ Bind(&done); |
| 5506 | } |
| 5507 | |
| 5508 | if (slow_path != nullptr) { |
| 5509 | __ Bind(slow_path->GetExitLabel()); |
| 5510 | } |
| 5511 | |
| 5512 | break; |
| 5513 | } |
| 5514 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5515 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5516 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5517 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5518 | size_t offset = |
| 5519 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5520 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5521 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5522 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5523 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5524 | } |
| 5525 | break; |
| 5526 | } |
| 5527 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5528 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5529 | Location value = locations->InAt(2); |
| 5530 | DCHECK(value.IsFpuRegister()); |
| 5531 | if (index.IsConstant()) { |
| 5532 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5533 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5534 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5535 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5536 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5537 | } |
| 5538 | break; |
| 5539 | } |
| 5540 | |
| 5541 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5542 | Location value = locations->InAt(2); |
| 5543 | DCHECK(value.IsFpuRegisterPair()); |
| 5544 | if (index.IsConstant()) { |
| 5545 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5546 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5547 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5548 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5549 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5550 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5551 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5552 | break; |
| 5553 | } |
| 5554 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5555 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5556 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5557 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5558 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5559 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5560 | // Objects are handled in the switch. |
| 5561 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5562 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5563 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5567 | LocationSummary* locations = |
| 5568 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5570 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5574 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5575 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5576 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5577 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5578 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5579 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5580 | // Mask out compression flag from String's array length. |
| 5581 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5582 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5583 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5586 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5587 | LocationSummary* locations = |
| 5588 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5589 | |
| 5590 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5591 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5592 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5593 | } |
| 5594 | |
| 5595 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5596 | LocationSummary* locations = instruction->GetLocations(); |
| 5597 | Location out = locations->Out(); |
| 5598 | Location first = locations->InAt(0); |
| 5599 | Location second = locations->InAt(1); |
| 5600 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5601 | if (second.IsRegister()) { |
| 5602 | __ add(out.AsRegister<Register>(), |
| 5603 | first.AsRegister<Register>(), |
| 5604 | ShifterOperand(second.AsRegister<Register>())); |
| 5605 | } else { |
| 5606 | __ AddConstant(out.AsRegister<Register>(), |
| 5607 | first.AsRegister<Register>(), |
| 5608 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5609 | } |
| 5610 | } |
| 5611 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5612 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5613 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5614 | InvokeRuntimeCallingConvention calling_convention; |
| 5615 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5616 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5617 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5619 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5623 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5624 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5625 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5626 | codegen_->AddSlowPath(slow_path); |
| 5627 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5628 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5629 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5630 | |
| 5631 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5632 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5633 | } |
| 5634 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5635 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5636 | Register card, |
| 5637 | Register object, |
| 5638 | Register value, |
| 5639 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5640 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5641 | if (can_be_null) { |
| 5642 | __ CompareAndBranchIfZero(value, &is_null); |
| 5643 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5644 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5645 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5646 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5647 | if (can_be_null) { |
| 5648 | __ Bind(&is_null); |
| 5649 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5650 | } |
| 5651 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5652 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5653 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5657 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5658 | } |
| 5659 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5660 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5661 | LocationSummary* locations = |
| 5662 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5663 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
| 5666 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5667 | HBasicBlock* block = instruction->GetBlock(); |
| 5668 | if (block->GetLoopInformation() != nullptr) { |
| 5669 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5670 | // The back edge will generate the suspend check. |
| 5671 | return; |
| 5672 | } |
| 5673 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5674 | // The goto will generate the suspend check. |
| 5675 | return; |
| 5676 | } |
| 5677 | GenerateSuspendCheck(instruction, nullptr); |
| 5678 | } |
| 5679 | |
| 5680 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5681 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5682 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5683 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5684 | if (slow_path == nullptr) { |
| 5685 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5686 | instruction->SetSlowPath(slow_path); |
| 5687 | codegen_->AddSlowPath(slow_path); |
| 5688 | if (successor != nullptr) { |
| 5689 | DCHECK(successor->IsLoopHeader()); |
| 5690 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5691 | } |
| 5692 | } else { |
| 5693 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5694 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5695 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5696 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5697 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5698 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5699 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5700 | __ Bind(slow_path->GetReturnLabel()); |
| 5701 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5702 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5703 | __ b(slow_path->GetEntryLabel()); |
| 5704 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5707 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5708 | return codegen_->GetAssembler(); |
| 5709 | } |
| 5710 | |
| 5711 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5712 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5713 | Location source = move->GetSource(); |
| 5714 | Location destination = move->GetDestination(); |
| 5715 | |
| 5716 | if (source.IsRegister()) { |
| 5717 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5718 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5719 | } else if (destination.IsFpuRegister()) { |
| 5720 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5721 | } else { |
| 5722 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5723 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5724 | SP, destination.GetStackIndex()); |
| 5725 | } |
| 5726 | } else if (source.IsStackSlot()) { |
| 5727 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5728 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5729 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5730 | } else if (destination.IsFpuRegister()) { |
| 5731 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5732 | } else { |
| 5733 | DCHECK(destination.IsStackSlot()); |
| 5734 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5735 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5736 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5737 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5738 | if (destination.IsRegister()) { |
| 5739 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5740 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5741 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5742 | } else { |
| 5743 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5744 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5745 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5746 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5747 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5748 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5749 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5750 | } else if (destination.IsRegisterPair()) { |
| 5751 | DCHECK(ExpectedPairLayout(destination)); |
| 5752 | __ LoadFromOffset( |
| 5753 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5754 | } else { |
| 5755 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5756 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5757 | SP, |
| 5758 | source.GetStackIndex()); |
| 5759 | } |
| 5760 | } else if (source.IsRegisterPair()) { |
| 5761 | if (destination.IsRegisterPair()) { |
| 5762 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5763 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5764 | } else if (destination.IsFpuRegisterPair()) { |
| 5765 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5766 | source.AsRegisterPairLow<Register>(), |
| 5767 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5768 | } else { |
| 5769 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5770 | DCHECK(ExpectedPairLayout(source)); |
| 5771 | __ StoreToOffset( |
| 5772 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5773 | } |
| 5774 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5775 | if (destination.IsRegisterPair()) { |
| 5776 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5777 | destination.AsRegisterPairHigh<Register>(), |
| 5778 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5779 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5780 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5781 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5782 | } else { |
| 5783 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5784 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5785 | SP, |
| 5786 | destination.GetStackIndex()); |
| 5787 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5788 | } else { |
| 5789 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5790 | HConstant* constant = source.GetConstant(); |
| 5791 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5792 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5793 | if (destination.IsRegister()) { |
| 5794 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5795 | } else { |
| 5796 | DCHECK(destination.IsStackSlot()); |
| 5797 | __ LoadImmediate(IP, value); |
| 5798 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5799 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5800 | } else if (constant->IsLongConstant()) { |
| 5801 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5802 | if (destination.IsRegisterPair()) { |
| 5803 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5804 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5805 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5806 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5807 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5808 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5809 | __ LoadImmediate(IP, High32Bits(value)); |
| 5810 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5811 | } |
| 5812 | } else if (constant->IsDoubleConstant()) { |
| 5813 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5814 | if (destination.IsFpuRegisterPair()) { |
| 5815 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5816 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5817 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5818 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5819 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5820 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5821 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5822 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5823 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5824 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5825 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5826 | float value = constant->AsFloatConstant()->GetValue(); |
| 5827 | if (destination.IsFpuRegister()) { |
| 5828 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5829 | } else { |
| 5830 | DCHECK(destination.IsStackSlot()); |
| 5831 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5832 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5833 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5834 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5835 | } |
| 5836 | } |
| 5837 | |
| 5838 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5839 | __ Mov(IP, reg); |
| 5840 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5841 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5842 | } |
| 5843 | |
| 5844 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5845 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5846 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5847 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5848 | SP, mem1 + stack_offset); |
| 5849 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5850 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5851 | SP, mem2 + stack_offset); |
| 5852 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5853 | } |
| 5854 | |
| 5855 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5856 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5857 | Location source = move->GetSource(); |
| 5858 | Location destination = move->GetDestination(); |
| 5859 | |
| 5860 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5861 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5862 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5863 | __ Mov(IP, source.AsRegister<Register>()); |
| 5864 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5865 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5866 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5867 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5868 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5869 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5870 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5871 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5872 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5873 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5874 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5875 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5876 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5877 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5878 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5879 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5880 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5881 | destination.AsRegisterPairHigh<Register>(), |
| 5882 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5883 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5884 | Register low_reg = source.IsRegisterPair() |
| 5885 | ? source.AsRegisterPairLow<Register>() |
| 5886 | : destination.AsRegisterPairLow<Register>(); |
| 5887 | int mem = source.IsRegisterPair() |
| 5888 | ? destination.GetStackIndex() |
| 5889 | : source.GetStackIndex(); |
| 5890 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5891 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5892 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5893 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5894 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5895 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5896 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5897 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5898 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5899 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5900 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5901 | DRegister reg = source.IsFpuRegisterPair() |
| 5902 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5903 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5904 | int mem = source.IsFpuRegisterPair() |
| 5905 | ? destination.GetStackIndex() |
| 5906 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5907 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5908 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5909 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5910 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5911 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5912 | : destination.AsFpuRegister<SRegister>(); |
| 5913 | int mem = source.IsFpuRegister() |
| 5914 | ? destination.GetStackIndex() |
| 5915 | : source.GetStackIndex(); |
| 5916 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5917 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5918 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5919 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5920 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5921 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5922 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5923 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5924 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5929 | __ Push(static_cast<Register>(reg)); |
| 5930 | } |
| 5931 | |
| 5932 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5933 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5934 | } |
| 5935 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5936 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5937 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5938 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5939 | case HLoadClass::LoadKind::kInvalid: |
| 5940 | LOG(FATAL) << "UNREACHABLE"; |
| 5941 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5942 | case HLoadClass::LoadKind::kReferrersClass: |
| 5943 | break; |
| 5944 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5945 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5946 | break; |
| 5947 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5948 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5949 | break; |
| 5950 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5951 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5952 | case HLoadClass::LoadKind::kBssEntry: |
| 5953 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5954 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5955 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5956 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5957 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5958 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5959 | break; |
| 5960 | } |
| 5961 | return desired_class_load_kind; |
| 5962 | } |
| 5963 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5964 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5965 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5966 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5967 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5968 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5969 | cls, |
| 5970 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5971 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5972 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5973 | return; |
| 5974 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5975 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5976 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5977 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5978 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5979 | ? LocationSummary::kCallOnSlowPath |
| 5980 | : LocationSummary::kNoCall; |
| 5981 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5982 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5983 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5984 | } |
| 5985 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5986 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5987 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5988 | } |
| 5989 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5990 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5991 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5992 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 5993 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 5994 | // to the custom calling convention) or by marking, so we request a different temp. |
| 5995 | locations->AddTemp(Location::RequiresRegister()); |
| 5996 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5997 | InvokeRuntimeCallingConvention calling_convention; |
| 5998 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5999 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6000 | // that the the kPrimNot result register is the same as the first argument register. |
| 6001 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6002 | } else { |
| 6003 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6004 | } |
| 6005 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6006 | } |
| 6007 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6008 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6009 | // move. |
| 6010 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6011 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6012 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6013 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6014 | return; |
| 6015 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6016 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6017 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6018 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6019 | Location out_loc = locations->Out(); |
| 6020 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6021 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6022 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6023 | ? kWithoutReadBarrier |
| 6024 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6025 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6026 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6027 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6028 | DCHECK(!cls->CanCallRuntime()); |
| 6029 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6030 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6031 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6032 | GenerateGcRootFieldLoad(cls, |
| 6033 | out_loc, |
| 6034 | current_method, |
| 6035 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6036 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6037 | break; |
| 6038 | } |
| 6039 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6040 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6041 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6042 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6043 | cls->GetTypeIndex())); |
| 6044 | break; |
| 6045 | } |
| 6046 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6047 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6048 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6049 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6050 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6051 | __ BindTrackedLabel(&labels->movw_label); |
| 6052 | __ movw(out, /* placeholder */ 0u); |
| 6053 | __ BindTrackedLabel(&labels->movt_label); |
| 6054 | __ movt(out, /* placeholder */ 0u); |
| 6055 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6056 | __ add(out, out, ShifterOperand(PC)); |
| 6057 | break; |
| 6058 | } |
| 6059 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6060 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6061 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6062 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6063 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6064 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6065 | break; |
| 6066 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6067 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6068 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6069 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6070 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6071 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6072 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6073 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6074 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6075 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6076 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6077 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6078 | __ add(temp, temp, ShifterOperand(PC)); |
| 6079 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6080 | generate_null_check = true; |
| 6081 | break; |
| 6082 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6083 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6084 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6085 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6086 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6087 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6088 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6089 | break; |
| 6090 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6091 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6092 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6093 | LOG(FATAL) << "UNREACHABLE"; |
| 6094 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6095 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6096 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6097 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6098 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6099 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6100 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6101 | codegen_->AddSlowPath(slow_path); |
| 6102 | if (generate_null_check) { |
| 6103 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6104 | } |
| 6105 | if (cls->MustGenerateClinitCheck()) { |
| 6106 | GenerateClassInitializationCheck(slow_path, out); |
| 6107 | } else { |
| 6108 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6109 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6114 | LocationSummary* locations = |
| 6115 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6116 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6117 | if (check->HasUses()) { |
| 6118 | locations->SetOut(Location::SameAsFirstInput()); |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6123 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6124 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6125 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6126 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6127 | GenerateClassInitializationCheck(slow_path, |
| 6128 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6129 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6130 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6131 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6132 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6133 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6134 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6135 | __ b(slow_path->GetEntryLabel(), LT); |
| 6136 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6137 | // properly. Therefore, we do a memory fence. |
| 6138 | __ dmb(ISH); |
| 6139 | __ Bind(slow_path->GetExitLabel()); |
| 6140 | } |
| 6141 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6142 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6143 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6144 | switch (desired_string_load_kind) { |
| 6145 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6146 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6147 | break; |
| 6148 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6149 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6150 | break; |
| 6151 | case HLoadString::LoadKind::kBootImageAddress: |
| 6152 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6153 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6154 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6155 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6156 | case HLoadString::LoadKind::kJitTableAddress: |
| 6157 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6158 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6159 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6160 | break; |
| 6161 | } |
| 6162 | return desired_string_load_kind; |
| 6163 | } |
| 6164 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6165 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6166 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6167 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6168 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6169 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6170 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6171 | } else { |
| 6172 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6173 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6174 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6175 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6176 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6177 | // 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] | 6178 | locations->AddTemp(Location::RequiresRegister()); |
| 6179 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6180 | InvokeRuntimeCallingConvention calling_convention; |
| 6181 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6182 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6183 | // that the the kPrimNot result register is the same as the first argument register. |
| 6184 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6185 | } else { |
| 6186 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6187 | } |
| 6188 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6189 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6192 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6193 | // move. |
| 6194 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6195 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6196 | Location out_loc = locations->Out(); |
| 6197 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6198 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6199 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6200 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6201 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6202 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6203 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6204 | load->GetStringIndex())); |
| 6205 | return; // No dex cache slow path. |
| 6206 | } |
| 6207 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6208 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6209 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6210 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6211 | __ BindTrackedLabel(&labels->movw_label); |
| 6212 | __ movw(out, /* placeholder */ 0u); |
| 6213 | __ BindTrackedLabel(&labels->movt_label); |
| 6214 | __ movt(out, /* placeholder */ 0u); |
| 6215 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6216 | __ add(out, out, ShifterOperand(PC)); |
| 6217 | return; // No dex cache slow path. |
| 6218 | } |
| 6219 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6220 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6221 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6222 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6223 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6224 | return; // No dex cache slow path. |
| 6225 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6226 | case HLoadString::LoadKind::kBssEntry: { |
| 6227 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6228 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6229 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6230 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6231 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6232 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6233 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6234 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6235 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6236 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6237 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6238 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6239 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6240 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 6241 | codegen_->AddSlowPath(slow_path); |
| 6242 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6243 | __ Bind(slow_path->GetExitLabel()); |
| 6244 | return; |
| 6245 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6246 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6247 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6248 | load->GetStringIndex(), |
| 6249 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6250 | // /* GcRoot<mirror::String> */ out = *out |
| 6251 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6252 | return; |
| 6253 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6254 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6255 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6256 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6257 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6258 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6259 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6260 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6261 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6262 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6263 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6264 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6267 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6268 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6269 | } |
| 6270 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6271 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6272 | LocationSummary* locations = |
| 6273 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6274 | locations->SetOut(Location::RequiresRegister()); |
| 6275 | } |
| 6276 | |
| 6277 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6278 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6279 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6280 | } |
| 6281 | |
| 6282 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6283 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6284 | } |
| 6285 | |
| 6286 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6287 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6288 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6292 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6293 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6294 | InvokeRuntimeCallingConvention calling_convention; |
| 6295 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6296 | } |
| 6297 | |
| 6298 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6299 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6300 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6303 | // Temp is used for read barrier. |
| 6304 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6305 | if (kEmitCompilerReadBarrier && |
| 6306 | (kUseBakerReadBarrier || |
| 6307 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6308 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6309 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6310 | return 1; |
| 6311 | } |
| 6312 | return 0; |
| 6313 | } |
| 6314 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6315 | // 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] | 6316 | // interface pointer, one for loading the current interface. |
| 6317 | // The other checks have one temp for loading the object's class. |
| 6318 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6319 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6320 | return 3; |
| 6321 | } |
| 6322 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6323 | } |
| 6324 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6325 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6326 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6327 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6328 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6329 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6330 | case TypeCheckKind::kExactCheck: |
| 6331 | case TypeCheckKind::kAbstractClassCheck: |
| 6332 | case TypeCheckKind::kClassHierarchyCheck: |
| 6333 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6334 | call_kind = |
| 6335 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6336 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6337 | break; |
| 6338 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6339 | case TypeCheckKind::kUnresolvedCheck: |
| 6340 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6341 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6342 | break; |
| 6343 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6344 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6345 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6346 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6347 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6348 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6350 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6351 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6352 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6353 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6354 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6355 | } |
| 6356 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6357 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6358 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6359 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6360 | Location obj_loc = locations->InAt(0); |
| 6361 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6362 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6363 | Location out_loc = locations->Out(); |
| 6364 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6365 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6366 | DCHECK_LE(num_temps, 1u); |
| 6367 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6368 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6369 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6370 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6371 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6372 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6373 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6374 | |
| 6375 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6376 | // avoid null check if we know obj is not null. |
| 6377 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6378 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6379 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6380 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6381 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6382 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6383 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6384 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6385 | out_loc, |
| 6386 | obj_loc, |
| 6387 | class_offset, |
| 6388 | maybe_temp_loc, |
| 6389 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6390 | __ cmp(out, ShifterOperand(cls)); |
| 6391 | // Classes must be equal for the instanceof to succeed. |
| 6392 | __ b(&zero, NE); |
| 6393 | __ LoadImmediate(out, 1); |
| 6394 | __ b(&done); |
| 6395 | break; |
| 6396 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6397 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6398 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6399 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6400 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6401 | out_loc, |
| 6402 | obj_loc, |
| 6403 | class_offset, |
| 6404 | maybe_temp_loc, |
| 6405 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | // If the class is abstract, we eagerly fetch the super class of the |
| 6407 | // object to avoid doing a comparison we know will fail. |
| 6408 | Label loop; |
| 6409 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6410 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6411 | GenerateReferenceLoadOneRegister(instruction, |
| 6412 | out_loc, |
| 6413 | super_offset, |
| 6414 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6415 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6416 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6417 | __ CompareAndBranchIfZero(out, &done); |
| 6418 | __ cmp(out, ShifterOperand(cls)); |
| 6419 | __ b(&loop, NE); |
| 6420 | __ LoadImmediate(out, 1); |
| 6421 | if (zero.IsLinked()) { |
| 6422 | __ b(&done); |
| 6423 | } |
| 6424 | break; |
| 6425 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6426 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6427 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6428 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6429 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6430 | out_loc, |
| 6431 | obj_loc, |
| 6432 | class_offset, |
| 6433 | maybe_temp_loc, |
| 6434 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6435 | // Walk over the class hierarchy to find a match. |
| 6436 | Label loop, success; |
| 6437 | __ Bind(&loop); |
| 6438 | __ cmp(out, ShifterOperand(cls)); |
| 6439 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6440 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6441 | GenerateReferenceLoadOneRegister(instruction, |
| 6442 | out_loc, |
| 6443 | super_offset, |
| 6444 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6445 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6446 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6447 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6448 | __ b(&done); |
| 6449 | __ Bind(&success); |
| 6450 | __ LoadImmediate(out, 1); |
| 6451 | if (zero.IsLinked()) { |
| 6452 | __ b(&done); |
| 6453 | } |
| 6454 | break; |
| 6455 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6456 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6457 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6458 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6459 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6460 | out_loc, |
| 6461 | obj_loc, |
| 6462 | class_offset, |
| 6463 | maybe_temp_loc, |
| 6464 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6465 | // Do an exact check. |
| 6466 | Label exact_check; |
| 6467 | __ cmp(out, ShifterOperand(cls)); |
| 6468 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6469 | // 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] | 6470 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6471 | GenerateReferenceLoadOneRegister(instruction, |
| 6472 | out_loc, |
| 6473 | component_offset, |
| 6474 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6475 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6476 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6477 | __ CompareAndBranchIfZero(out, &done); |
| 6478 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6479 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6480 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6481 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6482 | __ LoadImmediate(out, 1); |
| 6483 | __ b(&done); |
| 6484 | break; |
| 6485 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6486 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6487 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6488 | // No read barrier since the slow path will retry upon failure. |
| 6489 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6490 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6491 | out_loc, |
| 6492 | obj_loc, |
| 6493 | class_offset, |
| 6494 | maybe_temp_loc, |
| 6495 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6496 | __ cmp(out, ShifterOperand(cls)); |
| 6497 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6498 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6499 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6500 | codegen_->AddSlowPath(slow_path); |
| 6501 | __ b(slow_path->GetEntryLabel(), NE); |
| 6502 | __ LoadImmediate(out, 1); |
| 6503 | if (zero.IsLinked()) { |
| 6504 | __ b(&done); |
| 6505 | } |
| 6506 | break; |
| 6507 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6508 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6509 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6510 | case TypeCheckKind::kInterfaceCheck: { |
| 6511 | // 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] | 6512 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6513 | // cases. |
| 6514 | // |
| 6515 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6516 | // entry point without resorting to a type checking slow path |
| 6517 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6518 | // require to assign fixed registers for the inputs of this |
| 6519 | // HInstanceOf instruction (following the runtime calling |
| 6520 | // convention), which might be cluttered by the potential first |
| 6521 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6522 | // |
| 6523 | // TODO: Introduce a new runtime entry point taking the object |
| 6524 | // to test (instead of its class) as argument, and let it deal |
| 6525 | // with the read barrier issues. This will let us refactor this |
| 6526 | // case of the `switch` code as it was previously (with a direct |
| 6527 | // call to the runtime not using a type checking slow path). |
| 6528 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6529 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6530 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6531 | /* is_fatal */ false); |
| 6532 | codegen_->AddSlowPath(slow_path); |
| 6533 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6534 | if (zero.IsLinked()) { |
| 6535 | __ b(&done); |
| 6536 | } |
| 6537 | break; |
| 6538 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6539 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6540 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6541 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6542 | __ Bind(&zero); |
| 6543 | __ LoadImmediate(out, 0); |
| 6544 | } |
| 6545 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6546 | if (done.IsLinked()) { |
| 6547 | __ Bind(&done); |
| 6548 | } |
| 6549 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6550 | if (slow_path != nullptr) { |
| 6551 | __ Bind(slow_path->GetExitLabel()); |
| 6552 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6553 | } |
| 6554 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6555 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6556 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6557 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6558 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6559 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6560 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6561 | case TypeCheckKind::kExactCheck: |
| 6562 | case TypeCheckKind::kAbstractClassCheck: |
| 6563 | case TypeCheckKind::kClassHierarchyCheck: |
| 6564 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6565 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6566 | LocationSummary::kCallOnSlowPath : |
| 6567 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6568 | break; |
| 6569 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6570 | case TypeCheckKind::kUnresolvedCheck: |
| 6571 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6572 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6573 | break; |
| 6574 | } |
| 6575 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6576 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6577 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6578 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6579 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6580 | } |
| 6581 | |
| 6582 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6583 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6584 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6585 | Location obj_loc = locations->InAt(0); |
| 6586 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6587 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6588 | Location temp_loc = locations->GetTemp(0); |
| 6589 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6590 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6591 | DCHECK_LE(num_temps, 3u); |
| 6592 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6593 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6594 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6595 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6596 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6597 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6598 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6599 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6600 | const uint32_t object_array_data_offset = |
| 6601 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6602 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6603 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6604 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6605 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6606 | bool is_type_check_slow_path_fatal = false; |
| 6607 | if (!kEmitCompilerReadBarrier) { |
| 6608 | is_type_check_slow_path_fatal = |
| 6609 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6610 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6611 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6612 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6613 | !instruction->CanThrowIntoCatchBlock(); |
| 6614 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6615 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6616 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6617 | is_type_check_slow_path_fatal); |
| 6618 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6619 | |
| 6620 | Label done; |
| 6621 | // Avoid null check if we know obj is not null. |
| 6622 | if (instruction->MustDoNullCheck()) { |
| 6623 | __ CompareAndBranchIfZero(obj, &done); |
| 6624 | } |
| 6625 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6626 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6627 | case TypeCheckKind::kExactCheck: |
| 6628 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6629 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6630 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6631 | temp_loc, |
| 6632 | obj_loc, |
| 6633 | class_offset, |
| 6634 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6635 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6636 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6637 | __ cmp(temp, ShifterOperand(cls)); |
| 6638 | // Jump to slow path for throwing the exception or doing a |
| 6639 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6640 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6641 | break; |
| 6642 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6643 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6644 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6645 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6646 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6647 | temp_loc, |
| 6648 | obj_loc, |
| 6649 | class_offset, |
| 6650 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6651 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6652 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6653 | // If the class is abstract, we eagerly fetch the super class of the |
| 6654 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6655 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6656 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6657 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6658 | GenerateReferenceLoadOneRegister(instruction, |
| 6659 | temp_loc, |
| 6660 | super_offset, |
| 6661 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6662 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6663 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6664 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6665 | // exception. |
| 6666 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6667 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6668 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6669 | __ cmp(temp, ShifterOperand(cls)); |
| 6670 | __ b(&loop, NE); |
| 6671 | break; |
| 6672 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6673 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6674 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6675 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6676 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6677 | temp_loc, |
| 6678 | obj_loc, |
| 6679 | class_offset, |
| 6680 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6681 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6682 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6683 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6684 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6685 | __ Bind(&loop); |
| 6686 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6687 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6688 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6689 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6690 | GenerateReferenceLoadOneRegister(instruction, |
| 6691 | temp_loc, |
| 6692 | super_offset, |
| 6693 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6694 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6695 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6696 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6697 | // exception. |
| 6698 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6699 | // Otherwise, jump to the beginning of the loop. |
| 6700 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6701 | break; |
| 6702 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6703 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6704 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6705 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6706 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6707 | temp_loc, |
| 6708 | obj_loc, |
| 6709 | class_offset, |
| 6710 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6711 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6712 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6713 | // Do an exact check. |
| 6714 | __ cmp(temp, ShifterOperand(cls)); |
| 6715 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6716 | |
| 6717 | // 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] | 6718 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6719 | GenerateReferenceLoadOneRegister(instruction, |
| 6720 | temp_loc, |
| 6721 | component_offset, |
| 6722 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6723 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6724 | // If the component type is null, jump to the slow path to throw the exception. |
| 6725 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6726 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6727 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6728 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6729 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6730 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6731 | break; |
| 6732 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6733 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6734 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6735 | // 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] | 6736 | // We cannot directly call the CheckCast runtime entry point |
| 6737 | // without resorting to a type checking slow path here (i.e. by |
| 6738 | // calling InvokeRuntime directly), as it would require to |
| 6739 | // assign fixed registers for the inputs of this HInstanceOf |
| 6740 | // instruction (following the runtime calling convention), which |
| 6741 | // might be cluttered by the potential first read barrier |
| 6742 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6743 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6744 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6745 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6746 | |
| 6747 | case TypeCheckKind::kInterfaceCheck: { |
| 6748 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6749 | // positives by doing this. |
| 6750 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6751 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6752 | temp_loc, |
| 6753 | obj_loc, |
| 6754 | class_offset, |
| 6755 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6756 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6757 | |
| 6758 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6759 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6760 | temp_loc, |
| 6761 | temp_loc, |
| 6762 | iftable_offset, |
| 6763 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6764 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6765 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6766 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6767 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6768 | Label start_loop; |
| 6769 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6770 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 6771 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6772 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6773 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6774 | // Go to next interface. |
| 6775 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 6776 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 6777 | maybe_temp2_loc.AsRegister<Register>(), |
| 6778 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6779 | // Compare the classes and continue the loop if they do not match. |
| 6780 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 6781 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6782 | break; |
| 6783 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6784 | } |
| 6785 | __ Bind(&done); |
| 6786 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6787 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6788 | } |
| 6789 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6790 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6791 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6792 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6793 | InvokeRuntimeCallingConvention calling_convention; |
| 6794 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6795 | } |
| 6796 | |
| 6797 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6798 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6799 | instruction, |
| 6800 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6801 | if (instruction->IsEnter()) { |
| 6802 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6803 | } else { |
| 6804 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6805 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6806 | } |
| 6807 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6808 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6809 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6810 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6811 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6812 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6813 | LocationSummary* locations = |
| 6814 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6815 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6816 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6817 | // 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] | 6818 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6819 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6820 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6824 | HandleBitwiseOperation(instruction); |
| 6825 | } |
| 6826 | |
| 6827 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6828 | HandleBitwiseOperation(instruction); |
| 6829 | } |
| 6830 | |
| 6831 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6832 | HandleBitwiseOperation(instruction); |
| 6833 | } |
| 6834 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6835 | |
| 6836 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6837 | LocationSummary* locations = |
| 6838 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6839 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6840 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6841 | |
| 6842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6843 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6844 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6845 | } |
| 6846 | |
| 6847 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6848 | LocationSummary* locations = instruction->GetLocations(); |
| 6849 | Location first = locations->InAt(0); |
| 6850 | Location second = locations->InAt(1); |
| 6851 | Location out = locations->Out(); |
| 6852 | |
| 6853 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6854 | Register first_reg = first.AsRegister<Register>(); |
| 6855 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6856 | Register out_reg = out.AsRegister<Register>(); |
| 6857 | |
| 6858 | switch (instruction->GetOpKind()) { |
| 6859 | case HInstruction::kAnd: |
| 6860 | __ bic(out_reg, first_reg, second_reg); |
| 6861 | break; |
| 6862 | case HInstruction::kOr: |
| 6863 | __ orn(out_reg, first_reg, second_reg); |
| 6864 | break; |
| 6865 | // There is no EON on arm. |
| 6866 | case HInstruction::kXor: |
| 6867 | default: |
| 6868 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6869 | UNREACHABLE(); |
| 6870 | } |
| 6871 | return; |
| 6872 | |
| 6873 | } else { |
| 6874 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6875 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6876 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6877 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6878 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6879 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6880 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6881 | |
| 6882 | switch (instruction->GetOpKind()) { |
| 6883 | case HInstruction::kAnd: |
| 6884 | __ bic(out_low, first_low, second_low); |
| 6885 | __ bic(out_high, first_high, second_high); |
| 6886 | break; |
| 6887 | case HInstruction::kOr: |
| 6888 | __ orn(out_low, first_low, second_low); |
| 6889 | __ orn(out_high, first_high, second_high); |
| 6890 | break; |
| 6891 | // There is no EON on arm. |
| 6892 | case HInstruction::kXor: |
| 6893 | default: |
| 6894 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6895 | UNREACHABLE(); |
| 6896 | } |
| 6897 | } |
| 6898 | } |
| 6899 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 6900 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 6901 | HDataProcWithShifterOp* instruction) { |
| 6902 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 6903 | instruction->GetType() == Primitive::kPrimLong); |
| 6904 | LocationSummary* locations = |
| 6905 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6906 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 6907 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 6908 | |
| 6909 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6910 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6911 | locations->SetOut(Location::RequiresRegister(), |
| 6912 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6913 | } |
| 6914 | |
| 6915 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 6916 | HDataProcWithShifterOp* instruction) { |
| 6917 | const LocationSummary* const locations = instruction->GetLocations(); |
| 6918 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 6919 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 6920 | const Location left = locations->InAt(0); |
| 6921 | const Location right = locations->InAt(1); |
| 6922 | const Location out = locations->Out(); |
| 6923 | |
| 6924 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 6925 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 6926 | |
| 6927 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 6928 | ? right.AsRegisterPairLow<Register>() |
| 6929 | : right.AsRegister<Register>(); |
| 6930 | |
| 6931 | GenerateDataProcInstruction(kind, |
| 6932 | out.AsRegister<Register>(), |
| 6933 | left.AsRegister<Register>(), |
| 6934 | ShifterOperand(second, |
| 6935 | ShiftFromOpKind(op_kind), |
| 6936 | instruction->GetShiftAmount()), |
| 6937 | codegen_); |
| 6938 | } else { |
| 6939 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 6940 | |
| 6941 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 6942 | const Register second = right.AsRegister<Register>(); |
| 6943 | |
| 6944 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 6945 | GenerateDataProc(kind, |
| 6946 | out, |
| 6947 | left, |
| 6948 | ShifterOperand(second), |
| 6949 | ShifterOperand(second, ASR, 31), |
| 6950 | codegen_); |
| 6951 | } else { |
| 6952 | GenerateLongDataProc(instruction, codegen_); |
| 6953 | } |
| 6954 | } |
| 6955 | } |
| 6956 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6957 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6958 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6959 | if (value == 0xffffffffu) { |
| 6960 | if (out != first) { |
| 6961 | __ mov(out, ShifterOperand(first)); |
| 6962 | } |
| 6963 | return; |
| 6964 | } |
| 6965 | if (value == 0u) { |
| 6966 | __ mov(out, ShifterOperand(0)); |
| 6967 | return; |
| 6968 | } |
| 6969 | ShifterOperand so; |
| 6970 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6971 | __ and_(out, first, so); |
| 6972 | } else { |
| 6973 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6974 | __ bic(out, first, ShifterOperand(~value)); |
| 6975 | } |
| 6976 | } |
| 6977 | |
| 6978 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6979 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6980 | if (value == 0u) { |
| 6981 | if (out != first) { |
| 6982 | __ mov(out, ShifterOperand(first)); |
| 6983 | } |
| 6984 | return; |
| 6985 | } |
| 6986 | if (value == 0xffffffffu) { |
| 6987 | __ mvn(out, ShifterOperand(0)); |
| 6988 | return; |
| 6989 | } |
| 6990 | ShifterOperand so; |
| 6991 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6992 | __ orr(out, first, so); |
| 6993 | } else { |
| 6994 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6995 | __ orn(out, first, ShifterOperand(~value)); |
| 6996 | } |
| 6997 | } |
| 6998 | |
| 6999 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7000 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7001 | if (value == 0u) { |
| 7002 | if (out != first) { |
| 7003 | __ mov(out, ShifterOperand(first)); |
| 7004 | } |
| 7005 | return; |
| 7006 | } |
| 7007 | __ eor(out, first, ShifterOperand(value)); |
| 7008 | } |
| 7009 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7010 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7011 | Location first, |
| 7012 | uint64_t value) { |
| 7013 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7014 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7015 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7016 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7017 | uint32_t value_low = Low32Bits(value); |
| 7018 | uint32_t value_high = High32Bits(value); |
| 7019 | if (value_low == 0u) { |
| 7020 | if (out_low != first_low) { |
| 7021 | __ mov(out_low, ShifterOperand(first_low)); |
| 7022 | } |
| 7023 | __ AddConstant(out_high, first_high, value_high); |
| 7024 | return; |
| 7025 | } |
| 7026 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7027 | ShifterOperand so; |
| 7028 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7029 | __ adc(out_high, first_high, so); |
| 7030 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7031 | __ sbc(out_high, first_high, so); |
| 7032 | } else { |
| 7033 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7034 | UNREACHABLE(); |
| 7035 | } |
| 7036 | } |
| 7037 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7038 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7039 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7040 | Location first = locations->InAt(0); |
| 7041 | Location second = locations->InAt(1); |
| 7042 | Location out = locations->Out(); |
| 7043 | |
| 7044 | if (second.IsConstant()) { |
| 7045 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7046 | uint32_t value_low = Low32Bits(value); |
| 7047 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7048 | Register first_reg = first.AsRegister<Register>(); |
| 7049 | Register out_reg = out.AsRegister<Register>(); |
| 7050 | if (instruction->IsAnd()) { |
| 7051 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7052 | } else if (instruction->IsOr()) { |
| 7053 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7054 | } else { |
| 7055 | DCHECK(instruction->IsXor()); |
| 7056 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7057 | } |
| 7058 | } else { |
| 7059 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7060 | uint32_t value_high = High32Bits(value); |
| 7061 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7062 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7063 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7064 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7065 | if (instruction->IsAnd()) { |
| 7066 | GenerateAndConst(out_low, first_low, value_low); |
| 7067 | GenerateAndConst(out_high, first_high, value_high); |
| 7068 | } else if (instruction->IsOr()) { |
| 7069 | GenerateOrrConst(out_low, first_low, value_low); |
| 7070 | GenerateOrrConst(out_high, first_high, value_high); |
| 7071 | } else { |
| 7072 | DCHECK(instruction->IsXor()); |
| 7073 | GenerateEorConst(out_low, first_low, value_low); |
| 7074 | GenerateEorConst(out_high, first_high, value_high); |
| 7075 | } |
| 7076 | } |
| 7077 | return; |
| 7078 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7079 | |
| 7080 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7081 | Register first_reg = first.AsRegister<Register>(); |
| 7082 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7083 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7084 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7085 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7086 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7087 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7088 | } else { |
| 7089 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7090 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7091 | } |
| 7092 | } else { |
| 7093 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7094 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7095 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7096 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7097 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7098 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7099 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7100 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7101 | __ and_(out_low, first_low, second_low); |
| 7102 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7103 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7104 | __ orr(out_low, first_low, second_low); |
| 7105 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7106 | } else { |
| 7107 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7108 | __ eor(out_low, first_low, second_low); |
| 7109 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7110 | } |
| 7111 | } |
| 7112 | } |
| 7113 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7114 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7115 | HInstruction* instruction, |
| 7116 | Location out, |
| 7117 | uint32_t offset, |
| 7118 | Location maybe_temp, |
| 7119 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7120 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7121 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7122 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7123 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7124 | if (kUseBakerReadBarrier) { |
| 7125 | // Load with fast path based Baker's read barrier. |
| 7126 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7127 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7128 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7129 | } else { |
| 7130 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7131 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7132 | // in the following move operation, as we will need it for the |
| 7133 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7134 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7135 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7136 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7137 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7138 | } |
| 7139 | } else { |
| 7140 | // Plain load with no read barrier. |
| 7141 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7142 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7143 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7144 | } |
| 7145 | } |
| 7146 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7147 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7148 | HInstruction* instruction, |
| 7149 | Location out, |
| 7150 | Location obj, |
| 7151 | uint32_t offset, |
| 7152 | Location maybe_temp, |
| 7153 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7154 | Register out_reg = out.AsRegister<Register>(); |
| 7155 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7156 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7157 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7158 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7159 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7160 | // Load with fast path based Baker's read barrier. |
| 7161 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7162 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7163 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7164 | } else { |
| 7165 | // Load with slow path based read barrier. |
| 7166 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7167 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7168 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7169 | } |
| 7170 | } else { |
| 7171 | // Plain load with no read barrier. |
| 7172 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7173 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7174 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7175 | } |
| 7176 | } |
| 7177 | |
| 7178 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7179 | Location root, |
| 7180 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7181 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7182 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7183 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7184 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7185 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7186 | if (kUseBakerReadBarrier) { |
| 7187 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7188 | // Baker's read barrier are used: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7189 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7190 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7191 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7192 | // if (temp != null) { |
| 7193 | // root = temp(root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7194 | // } |
| 7195 | |
| 7196 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7197 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7198 | static_assert( |
| 7199 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7200 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7201 | "have different sizes."); |
| 7202 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7203 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7204 | "have different sizes."); |
| 7205 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7206 | // Slow path marking the GC root `root`. |
| 7207 | Location temp = Location::RegisterLocation(LR); |
| 7208 | SlowPathCodeARM* slow_path = |
| 7209 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 7210 | instruction, |
| 7211 | root, |
| 7212 | /*entrypoint*/ temp); |
| 7213 | codegen_->AddSlowPath(slow_path); |
| 7214 | |
| 7215 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7216 | const int32_t entry_point_offset = |
| 7217 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 7218 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7219 | // threads are suspended or running a checkpoint. |
| 7220 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7221 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 7222 | // checking GetIsGcMarking. |
| 7223 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7224 | __ Bind(slow_path->GetExitLabel()); |
| 7225 | } else { |
| 7226 | // GC root loaded through a slow path for read barriers other |
| 7227 | // than Baker's. |
| 7228 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7229 | __ AddConstant(root_reg, obj, offset); |
| 7230 | // /* mirror::Object* */ root = root->Read() |
| 7231 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7232 | } |
| 7233 | } else { |
| 7234 | // Plain GC root load with no read barrier. |
| 7235 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7236 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7237 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7238 | // do not have to unpoison `root_reg` here. |
| 7239 | } |
| 7240 | } |
| 7241 | |
| 7242 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7243 | Location ref, |
| 7244 | Register obj, |
| 7245 | uint32_t offset, |
| 7246 | Location temp, |
| 7247 | bool needs_null_check) { |
| 7248 | DCHECK(kEmitCompilerReadBarrier); |
| 7249 | DCHECK(kUseBakerReadBarrier); |
| 7250 | |
| 7251 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7252 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7253 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7254 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7255 | 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] | 7256 | } |
| 7257 | |
| 7258 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7259 | Location ref, |
| 7260 | Register obj, |
| 7261 | uint32_t data_offset, |
| 7262 | Location index, |
| 7263 | Location temp, |
| 7264 | bool needs_null_check) { |
| 7265 | DCHECK(kEmitCompilerReadBarrier); |
| 7266 | DCHECK(kUseBakerReadBarrier); |
| 7267 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7268 | static_assert( |
| 7269 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7270 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7271 | // /* HeapReference<Object> */ ref = |
| 7272 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7273 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7274 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7275 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7276 | } |
| 7277 | |
| 7278 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7279 | Location ref, |
| 7280 | Register obj, |
| 7281 | uint32_t offset, |
| 7282 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7283 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7284 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7285 | bool needs_null_check, |
| 7286 | bool always_update_field, |
| 7287 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7288 | DCHECK(kEmitCompilerReadBarrier); |
| 7289 | DCHECK(kUseBakerReadBarrier); |
| 7290 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7291 | // In slow path based read barriers, the read barrier call is |
| 7292 | // inserted after the original load. However, in fast path based |
| 7293 | // Baker's read barriers, we need to perform the load of |
| 7294 | // mirror::Object::monitor_ *before* the original reference load. |
| 7295 | // This load-load ordering is required by the read barrier. |
| 7296 | // The fast path/slow path (for Baker's algorithm) should look like: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7297 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7298 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7299 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7300 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7301 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7302 | // if (is_gray) { |
| 7303 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7304 | // } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7305 | // |
| 7306 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7307 | // slightly more complex as it performs additional checks that we do |
| 7308 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7309 | |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7310 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7311 | Register temp_reg = temp.AsRegister<Register>(); |
| 7312 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7313 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7314 | // /* int32_t */ monitor = obj->monitor_ |
| 7315 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7316 | if (needs_null_check) { |
| 7317 | MaybeRecordImplicitNullCheck(instruction); |
| 7318 | } |
| 7319 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7320 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7321 | "art::LockWord and int32_t have different sizes."); |
| 7322 | |
| 7323 | // Introduce a dependency on the lock_word including the rb_state, |
| 7324 | // which shall prevent load-load reordering without using |
| 7325 | // a memory barrier (which would be more expensive). |
| 7326 | // `obj` is unchanged by this operation, but its value now depends |
| 7327 | // on `temp_reg`. |
| 7328 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
| 7329 | |
| 7330 | // The actual reference load. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7331 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7332 | // Load types involving an "index": ArrayGet, |
| 7333 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7334 | // intrinsics. |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7335 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7336 | if (index.IsConstant()) { |
| 7337 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7338 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7339 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7340 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7341 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7342 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7343 | // intrinsics, which use a register pair as index ("long |
| 7344 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7345 | Register index_reg = index.IsRegisterPair() |
| 7346 | ? index.AsRegisterPairLow<Register>() |
| 7347 | : index.AsRegister<Register>(); |
| 7348 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7349 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7350 | } |
| 7351 | } else { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7352 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7353 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7354 | } |
| 7355 | |
| 7356 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7357 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7358 | |
| 7359 | // Slow path marking the object `ref` when it is gray. |
| 7360 | SlowPathCodeARM* slow_path; |
| 7361 | if (always_update_field) { |
| 7362 | DCHECK(temp2 != nullptr); |
| 7363 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 7364 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7365 | // `field_offset` is a register pair (of which only the lower half |
| 7366 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7367 | // to be null in this code path. |
| 7368 | DCHECK_EQ(offset, 0u); |
| 7369 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7370 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 7371 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7372 | } else { |
| 7373 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 7374 | } |
| 7375 | AddSlowPath(slow_path); |
| 7376 | |
| 7377 | // if (rb_state == ReadBarrier::GrayState()) |
| 7378 | // ref = ReadBarrier::Mark(ref); |
| 7379 | // Given the numeric representation, it's enough to check the low bit of the |
| 7380 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7381 | // which can be a 16-bit instruction unlike the TST immediate. |
| 7382 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7383 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7384 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7385 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
| 7386 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7390 | Location out, |
| 7391 | Location ref, |
| 7392 | Location obj, |
| 7393 | uint32_t offset, |
| 7394 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7395 | DCHECK(kEmitCompilerReadBarrier); |
| 7396 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7397 | // Insert a slow path based read barrier *after* the reference load. |
| 7398 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7399 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7400 | // reference will be carried out by the runtime within the slow |
| 7401 | // path. |
| 7402 | // |
| 7403 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7404 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7405 | // not used by the artReadBarrierSlow entry point. |
| 7406 | // |
| 7407 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7408 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7409 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7410 | AddSlowPath(slow_path); |
| 7411 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7412 | __ b(slow_path->GetEntryLabel()); |
| 7413 | __ Bind(slow_path->GetExitLabel()); |
| 7414 | } |
| 7415 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7416 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7417 | Location out, |
| 7418 | Location ref, |
| 7419 | Location obj, |
| 7420 | uint32_t offset, |
| 7421 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7422 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7423 | // Baker's read barriers shall be handled by the fast path |
| 7424 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7425 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7426 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7427 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7428 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7429 | } else if (kPoisonHeapReferences) { |
| 7430 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7431 | } |
| 7432 | } |
| 7433 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7434 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7435 | Location out, |
| 7436 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7437 | DCHECK(kEmitCompilerReadBarrier); |
| 7438 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7439 | // Insert a slow path based read barrier *after* the GC root load. |
| 7440 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7441 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7442 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7443 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7444 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7445 | AddSlowPath(slow_path); |
| 7446 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7447 | __ b(slow_path->GetEntryLabel()); |
| 7448 | __ Bind(slow_path->GetExitLabel()); |
| 7449 | } |
| 7450 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7451 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7452 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7453 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 7454 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7455 | } |
| 7456 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7457 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7458 | Register temp) { |
| 7459 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7460 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7461 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7462 | return location.AsRegister<Register>(); |
| 7463 | } |
| 7464 | // For intrinsics we allow any location, so it may be on the stack. |
| 7465 | if (!location.IsRegister()) { |
| 7466 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7467 | return temp; |
| 7468 | } |
| 7469 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7470 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7471 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7472 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7473 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7474 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7475 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7476 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7477 | return temp; |
| 7478 | } |
| 7479 | return location.AsRegister<Register>(); |
| 7480 | } |
| 7481 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7482 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 7483 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7484 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7485 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7486 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7487 | uint32_t offset = |
| 7488 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7489 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7490 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7491 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7492 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7493 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7494 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7495 | break; |
| 7496 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7497 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7498 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7499 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7500 | HArmDexCacheArraysBase* base = |
| 7501 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7502 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7503 | temp.AsRegister<Register>()); |
| 7504 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7505 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7506 | break; |
| 7507 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7508 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7509 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7510 | Register method_reg; |
| 7511 | Register reg = temp.AsRegister<Register>(); |
| 7512 | if (current_method.IsRegister()) { |
| 7513 | method_reg = current_method.AsRegister<Register>(); |
| 7514 | } else { |
| 7515 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7516 | DCHECK(!current_method.IsValid()); |
| 7517 | method_reg = reg; |
| 7518 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7519 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7520 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7521 | __ LoadFromOffset(kLoadWord, |
| 7522 | reg, |
| 7523 | method_reg, |
| 7524 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7525 | // temp = temp[index_in_cache]; |
| 7526 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7527 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7528 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7529 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7530 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7531 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7532 | return callee_method; |
| 7533 | } |
| 7534 | |
| 7535 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 7536 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7537 | |
| 7538 | switch (invoke->GetCodePtrLocation()) { |
| 7539 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7540 | __ bl(GetFrameEntryLabel()); |
| 7541 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7542 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7543 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7544 | __ LoadFromOffset( |
| 7545 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7546 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7547 | // LR() |
| 7548 | __ blx(LR); |
| 7549 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7550 | } |
| 7551 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7552 | DCHECK(!IsLeafMethod()); |
| 7553 | } |
| 7554 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7555 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7556 | Register temp = temp_location.AsRegister<Register>(); |
| 7557 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7558 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7559 | |
| 7560 | // Use the calling convention instead of the location of the receiver, as |
| 7561 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7562 | // slow path, the arguments have been moved to the right place, so here we are |
| 7563 | // guaranteed that the receiver is the first register of the calling convention. |
| 7564 | InvokeDexCallingConvention calling_convention; |
| 7565 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7566 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7567 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7568 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7569 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7570 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7571 | // emit a read barrier for the previous class reference load. |
| 7572 | // However this is not required in practice, as this is an |
| 7573 | // intermediate/temporary reference and because the current |
| 7574 | // concurrent copying collector keeps the from-space memory |
| 7575 | // intact/accessible until the end of the marking phase (the |
| 7576 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7577 | __ MaybeUnpoisonHeapReference(temp); |
| 7578 | // temp = temp->GetMethodAt(method_offset); |
| 7579 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7580 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7581 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7582 | // LR = temp->GetEntryPoint(); |
| 7583 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7584 | // LR(); |
| 7585 | __ blx(LR); |
| 7586 | } |
| 7587 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7588 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7589 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7590 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7591 | } |
| 7592 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7593 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7594 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7595 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7596 | } |
| 7597 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7598 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 7599 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7600 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7601 | } |
| 7602 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7603 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7604 | const DexFile& dex_file, uint32_t element_offset) { |
| 7605 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7606 | } |
| 7607 | |
| 7608 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7609 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7610 | patches->emplace_back(dex_file, offset_or_index); |
| 7611 | return &patches->back(); |
| 7612 | } |
| 7613 | |
| 7614 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7615 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7616 | return boot_image_string_patches_.GetOrCreate( |
| 7617 | StringReference(&dex_file, string_index), |
| 7618 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7619 | } |
| 7620 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7621 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7622 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7623 | return boot_image_type_patches_.GetOrCreate( |
| 7624 | TypeReference(&dex_file, type_index), |
| 7625 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7626 | } |
| 7627 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7628 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7629 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7630 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7631 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7632 | } |
| 7633 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7634 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7635 | dex::StringIndex string_index, |
| 7636 | Handle<mirror::String> handle) { |
| 7637 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7638 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7639 | return jit_string_patches_.GetOrCreate( |
| 7640 | StringReference(&dex_file, string_index), |
| 7641 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7642 | } |
| 7643 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7644 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7645 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7646 | Handle<mirror::Class> handle) { |
| 7647 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 7648 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7649 | return jit_class_patches_.GetOrCreate( |
| 7650 | TypeReference(&dex_file, type_index), |
| 7651 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7652 | } |
| 7653 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7654 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7655 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7656 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7657 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7658 | for (const PcRelativePatchInfo& info : infos) { |
| 7659 | const DexFile& dex_file = info.target_dex_file; |
| 7660 | size_t offset_or_index = info.offset_or_index; |
| 7661 | DCHECK(info.add_pc_label.IsBound()); |
| 7662 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7663 | // Add MOVW patch. |
| 7664 | DCHECK(info.movw_label.IsBound()); |
| 7665 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7666 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7667 | // Add MOVT patch. |
| 7668 | DCHECK(info.movt_label.IsBound()); |
| 7669 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7670 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7671 | } |
| 7672 | } |
| 7673 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7674 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7675 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7676 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7677 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7678 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7679 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7680 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7681 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7682 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7683 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7684 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7685 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7686 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7687 | for (const auto& entry : boot_image_string_patches_) { |
| 7688 | const StringReference& target_string = entry.first; |
| 7689 | Literal* literal = entry.second; |
| 7690 | DCHECK(literal->GetLabel()->IsBound()); |
| 7691 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7692 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7693 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7694 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7695 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7696 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7697 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7698 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7699 | linker_patches); |
| 7700 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7701 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7702 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7703 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7704 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7705 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7706 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7707 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7708 | for (const auto& entry : boot_image_type_patches_) { |
| 7709 | const TypeReference& target_type = entry.first; |
| 7710 | Literal* literal = entry.second; |
| 7711 | DCHECK(literal->GetLabel()->IsBound()); |
| 7712 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7713 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7714 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7715 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7716 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7717 | for (const auto& entry : boot_image_address_patches_) { |
| 7718 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7719 | Literal* literal = entry.second; |
| 7720 | DCHECK(literal->GetLabel()->IsBound()); |
| 7721 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7722 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7723 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7724 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7725 | } |
| 7726 | |
| 7727 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7728 | return map->GetOrCreate( |
| 7729 | value, |
| 7730 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7731 | } |
| 7732 | |
| 7733 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7734 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7735 | return map->GetOrCreate( |
| 7736 | target_method, |
| 7737 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7738 | } |
| 7739 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7740 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7741 | LocationSummary* locations = |
| 7742 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7743 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7744 | Location::RequiresRegister()); |
| 7745 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7746 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7747 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7748 | } |
| 7749 | |
| 7750 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7751 | LocationSummary* locations = instr->GetLocations(); |
| 7752 | Register res = locations->Out().AsRegister<Register>(); |
| 7753 | Register accumulator = |
| 7754 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7755 | Register mul_left = |
| 7756 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7757 | Register mul_right = |
| 7758 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7759 | |
| 7760 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7761 | __ mla(res, mul_left, mul_right, accumulator); |
| 7762 | } else { |
| 7763 | __ mls(res, mul_left, mul_right, accumulator); |
| 7764 | } |
| 7765 | } |
| 7766 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7767 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7768 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7769 | LOG(FATAL) << "Unreachable"; |
| 7770 | } |
| 7771 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7772 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7773 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7774 | LOG(FATAL) << "Unreachable"; |
| 7775 | } |
| 7776 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7777 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7778 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7779 | LocationSummary* locations = |
| 7780 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7781 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7782 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7783 | codegen_->GetAssembler()->IsThumb()) { |
| 7784 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7785 | if (switch_instr->GetStartValue() != 0) { |
| 7786 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7787 | } |
| 7788 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7789 | } |
| 7790 | |
| 7791 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7792 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7793 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7794 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7795 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7796 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7797 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7798 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7799 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7800 | Register temp_reg = IP; |
| 7801 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7802 | // the immediate, because IP is used as the destination register. For the other |
| 7803 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7804 | // and they can be encoded in the instruction without making use of IP register. |
| 7805 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7806 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7807 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7808 | // Jump to successors[0] if value == lower_bound. |
| 7809 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7810 | int32_t last_index = 0; |
| 7811 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7812 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7813 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7814 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7815 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7816 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7817 | } |
| 7818 | if (num_entries - last_index == 2) { |
| 7819 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7820 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7821 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7822 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7823 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7824 | // And the default for any other value. |
| 7825 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7826 | __ b(codegen_->GetLabelOf(default_block)); |
| 7827 | } |
| 7828 | } else { |
| 7829 | // Create a table lookup. |
| 7830 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7831 | |
| 7832 | // Materialize a pointer to the switch table |
| 7833 | std::vector<Label*> labels(num_entries); |
| 7834 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7835 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7836 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7837 | } |
| 7838 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7839 | |
| 7840 | // Remove the bias. |
| 7841 | Register key_reg; |
| 7842 | if (lower_bound != 0) { |
| 7843 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7844 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7845 | } else { |
| 7846 | key_reg = value_reg; |
| 7847 | } |
| 7848 | |
| 7849 | // Check whether the value is in the table, jump to default block if not. |
| 7850 | __ CmpConstant(key_reg, num_entries - 1); |
| 7851 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7852 | |
| 7853 | // Load the displacement from the table. |
| 7854 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7855 | |
| 7856 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7857 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7858 | } |
| 7859 | } |
| 7860 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7861 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7862 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7863 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7867 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7868 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7869 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7870 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7871 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7872 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7873 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7874 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7875 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7876 | } |
| 7877 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7878 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7879 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7880 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7881 | return; |
| 7882 | } |
| 7883 | |
| 7884 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7885 | |
| 7886 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7887 | if (return_loc.Equals(trg)) { |
| 7888 | return; |
| 7889 | } |
| 7890 | |
| 7891 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7892 | // with the last branch. |
| 7893 | if (type == Primitive::kPrimLong) { |
| 7894 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7895 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7896 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7897 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7898 | } else if (type == Primitive::kPrimDouble) { |
| 7899 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7900 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7901 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7902 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7903 | } else { |
| 7904 | // Let the parallel move resolver take care of all of this. |
| 7905 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7906 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7907 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7908 | } |
| 7909 | } |
| 7910 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7911 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7912 | LocationSummary* locations = |
| 7913 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7914 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7915 | locations->SetOut(Location::RequiresRegister()); |
| 7916 | } |
| 7917 | |
| 7918 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7919 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7920 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7921 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7922 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7923 | __ LoadFromOffset(kLoadWord, |
| 7924 | locations->Out().AsRegister<Register>(), |
| 7925 | locations->InAt(0).AsRegister<Register>(), |
| 7926 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7927 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7928 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7929 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7930 | __ LoadFromOffset(kLoadWord, |
| 7931 | locations->Out().AsRegister<Register>(), |
| 7932 | locations->InAt(0).AsRegister<Register>(), |
| 7933 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7934 | __ LoadFromOffset(kLoadWord, |
| 7935 | locations->Out().AsRegister<Register>(), |
| 7936 | locations->Out().AsRegister<Register>(), |
| 7937 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7938 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7939 | } |
| 7940 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7941 | static void PatchJitRootUse(uint8_t* code, |
| 7942 | const uint8_t* roots_data, |
| 7943 | Literal* literal, |
| 7944 | uint64_t index_in_table) { |
| 7945 | DCHECK(literal->GetLabel()->IsBound()); |
| 7946 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7947 | uintptr_t address = |
| 7948 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7949 | uint8_t* data = code + literal_offset; |
| 7950 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 7951 | } |
| 7952 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7953 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7954 | for (const auto& entry : jit_string_patches_) { |
| 7955 | const auto& it = jit_string_roots_.find(entry.first); |
| 7956 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7957 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 7958 | } |
| 7959 | for (const auto& entry : jit_class_patches_) { |
| 7960 | const auto& it = jit_class_roots_.find(entry.first); |
| 7961 | DCHECK(it != jit_class_roots_.end()); |
| 7962 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7963 | } |
| 7964 | } |
| 7965 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7966 | #undef __ |
| 7967 | #undef QUICK_ENTRY_POINT |
| 7968 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7969 | } // namespace arm |
| 7970 | } // namespace art |