Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 66 | static constexpr int kRegListThreshold = 4; |
| 67 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 68 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 69 | // for each live D registers they treat two corresponding S registers as live ones. |
| 70 | // |
| 71 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 72 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 73 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 74 | // - decreasing code size |
| 75 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 76 | // restored and then used in regular non SlowPath code as D register. |
| 77 | // |
| 78 | // For the following example (v means the S register is live): |
| 79 | // D names: | D0 | D1 | D2 | D4 | ... |
| 80 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 81 | // Live? | | v | v | v | v | v | v | | ... |
| 82 | // |
| 83 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 84 | // as D registers. |
| 85 | static size_t SaveContiguousSRegisterList(size_t first, |
| 86 | size_t last, |
| 87 | CodeGenerator* codegen, |
| 88 | size_t stack_offset) { |
| 89 | DCHECK_LE(first, last); |
| 90 | if ((first == last) && (first == 0)) { |
| 91 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 92 | return stack_offset; |
| 93 | } |
| 94 | if (first % 2 == 1) { |
| 95 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 96 | } |
| 97 | |
| 98 | bool save_last = false; |
| 99 | if (last % 2 == 0) { |
| 100 | save_last = true; |
| 101 | --last; |
| 102 | } |
| 103 | |
| 104 | if (first < last) { |
| 105 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 106 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 107 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 108 | |
| 109 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 110 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 111 | } else if (number_of_d_regs > 1) { |
| 112 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 113 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 114 | } |
| 115 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 116 | } |
| 117 | |
| 118 | if (save_last) { |
| 119 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 120 | } |
| 121 | |
| 122 | return stack_offset; |
| 123 | } |
| 124 | |
| 125 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 126 | size_t last, |
| 127 | CodeGenerator* codegen, |
| 128 | size_t stack_offset) { |
| 129 | DCHECK_LE(first, last); |
| 130 | if ((first == last) && (first == 0)) { |
| 131 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 132 | return stack_offset; |
| 133 | } |
| 134 | if (first % 2 == 1) { |
| 135 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 136 | } |
| 137 | |
| 138 | bool restore_last = false; |
| 139 | if (last % 2 == 0) { |
| 140 | restore_last = true; |
| 141 | --last; |
| 142 | } |
| 143 | |
| 144 | if (first < last) { |
| 145 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 146 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 147 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 148 | if (number_of_d_regs == 1) { |
| 149 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 150 | } else if (number_of_d_regs > 1) { |
| 151 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 152 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 153 | } |
| 154 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 155 | } |
| 156 | |
| 157 | if (restore_last) { |
| 158 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 159 | } |
| 160 | |
| 161 | return stack_offset; |
| 162 | } |
| 163 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 164 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 165 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 166 | size_t orig_offset = stack_offset; |
| 167 | |
| 168 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 169 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 170 | // If the register holds an object, update the stack mask. |
| 171 | if (locations->RegisterContainsObject(i)) { |
| 172 | locations->SetStackBit(stack_offset / kVRegSize); |
| 173 | } |
| 174 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 175 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 176 | saved_core_stack_offsets_[i] = stack_offset; |
| 177 | stack_offset += kArmWordSize; |
| 178 | } |
| 179 | |
| 180 | int reg_num = POPCOUNT(core_spills); |
| 181 | if (reg_num != 0) { |
| 182 | if (reg_num > kRegListThreshold) { |
| 183 | __ StoreList(RegList(core_spills), orig_offset); |
| 184 | } else { |
| 185 | stack_offset = orig_offset; |
| 186 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 187 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 192 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 193 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 197 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 199 | |
| 200 | stack_offset = orig_offset; |
| 201 | while (fp_spills != 0u) { |
| 202 | uint32_t begin = CTZ(fp_spills); |
| 203 | uint32_t tmp = fp_spills + (1u << begin); |
| 204 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 205 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 206 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 207 | } |
| 208 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 212 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 213 | size_t orig_offset = stack_offset; |
| 214 | |
| 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 218 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 219 | stack_offset += kArmWordSize; |
| 220 | } |
| 221 | |
| 222 | int reg_num = POPCOUNT(core_spills); |
| 223 | if (reg_num != 0) { |
| 224 | if (reg_num > kRegListThreshold) { |
| 225 | __ LoadList(RegList(core_spills), orig_offset); |
| 226 | } else { |
| 227 | stack_offset = orig_offset; |
| 228 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 229 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 234 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 235 | while (fp_spills != 0u) { |
| 236 | uint32_t begin = CTZ(fp_spills); |
| 237 | uint32_t tmp = fp_spills + (1u << begin); |
| 238 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 239 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 240 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 241 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 246 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 251 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 252 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 253 | // Live registers will be restored in the catch block if caught. |
| 254 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 255 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 257 | instruction_, |
| 258 | instruction_->GetDexPc(), |
| 259 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 260 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 263 | bool IsFatal() const OVERRIDE { return true; } |
| 264 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 265 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 266 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 267 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 269 | }; |
| 270 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 271 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 272 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 273 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 276 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 277 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 278 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 282 | bool IsFatal() const OVERRIDE { return true; } |
| 283 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 285 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 286 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 288 | }; |
| 289 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 290 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 291 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 293 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 296 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 297 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 298 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 300 | if (successor_ == nullptr) { |
| 301 | __ b(GetReturnLabel()); |
| 302 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 303 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 304 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 307 | Label* GetReturnLabel() { |
| 308 | DCHECK(successor_ == nullptr); |
| 309 | return &return_label_; |
| 310 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 311 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 312 | HBasicBlock* GetSuccessor() const { |
| 313 | return successor_; |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 317 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 318 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 319 | // If not null, the block to branch to after the suspend check. |
| 320 | HBasicBlock* const successor_; |
| 321 | |
| 322 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 323 | Label return_label_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 329 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 330 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | LocationSummary* locations = instruction_->GetLocations(); |
| 336 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 337 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 338 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 339 | // Live registers will be restored in the catch block if caught. |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 341 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 342 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 343 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 344 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 346 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 351 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 352 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 353 | ? kQuickThrowStringBounds |
| 354 | : kQuickThrowArrayBounds; |
| 355 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return true; } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 364 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 366 | }; |
| 367 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 368 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 369 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 370 | LoadClassSlowPathARM(HLoadClass* cls, |
| 371 | HInstruction* at, |
| 372 | uint32_t dex_pc, |
| 373 | bool do_clinit) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 374 | : SlowPathCodeARM(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 375 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 376 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 377 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 378 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 379 | LocationSummary* locations = at_->GetLocations(); |
| 380 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 381 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 382 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 383 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 385 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 386 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 387 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 388 | : kQuickInitializeType; |
| 389 | arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 390 | if (do_clinit_) { |
| 391 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 392 | } else { |
| 393 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 394 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 395 | |
| 396 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 397 | Location out = locations->Out(); |
| 398 | if (out.IsValid()) { |
| 399 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 400 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 401 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 402 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 403 | __ b(GetExitLabel()); |
| 404 | } |
| 405 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 406 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 407 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 408 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 409 | // The class this slow path will load. |
| 410 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 411 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 412 | // The instruction where this slow path is happening. |
| 413 | // (Might be the load class or an initialization check). |
| 414 | HInstruction* const at_; |
| 415 | |
| 416 | // The dex PC of `at_`. |
| 417 | const uint32_t dex_pc_; |
| 418 | |
| 419 | // Whether to initialize the class. |
| 420 | const bool do_clinit_; |
| 421 | |
| 422 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 423 | }; |
| 424 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 425 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 426 | public: |
| 427 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 428 | |
| 429 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 430 | LocationSummary* locations = instruction_->GetLocations(); |
| 431 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 432 | HLoadString* load = instruction_->AsLoadString(); |
| 433 | const uint32_t string_index = load->GetStringIndex(); |
| 434 | Register out = locations->Out().AsRegister<Register>(); |
| 435 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 436 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 437 | |
| 438 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 439 | __ Bind(GetEntryLabel()); |
| 440 | SaveLiveRegisters(codegen, locations); |
| 441 | |
| 442 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 443 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 444 | // the kSaveEverything call (or use `out` for the address after non-kSaveEverything call). |
| 445 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 446 | Register entry_address = temp_is_r0 ? out : temp; |
| 447 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 448 | if (call_saves_everything_except_r0 && temp_is_r0) { |
| 449 | __ mov(entry_address, ShifterOperand(temp)); |
| 450 | } |
| 451 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 452 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
| 453 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 454 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 455 | |
| 456 | // Store the resolved String to the .bss entry. |
| 457 | if (call_saves_everything_except_r0) { |
| 458 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 459 | __ str(R0, Address(entry_address)); |
| 460 | } else { |
| 461 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 462 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 463 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 464 | __ BindTrackedLabel(&labels->movw_label); |
| 465 | __ movw(entry_address, /* placeholder */ 0u); |
| 466 | __ BindTrackedLabel(&labels->movt_label); |
| 467 | __ movt(entry_address, /* placeholder */ 0u); |
| 468 | __ BindTrackedLabel(&labels->add_pc_label); |
| 469 | __ add(entry_address, entry_address, ShifterOperand(PC)); |
| 470 | __ str(R0, Address(entry_address)); |
| 471 | } |
| 472 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 473 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 474 | RestoreLiveRegisters(codegen, locations); |
| 475 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 476 | __ b(GetExitLabel()); |
| 477 | } |
| 478 | |
| 479 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 480 | |
| 481 | private: |
| 482 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 483 | }; |
| 484 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 485 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 486 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 487 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 488 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 489 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 490 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 491 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 492 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 493 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 494 | DCHECK(instruction_->IsCheckCast() |
| 495 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 496 | |
| 497 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 498 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 500 | if (!is_fatal_) { |
| 501 | SaveLiveRegisters(codegen, locations); |
| 502 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 503 | |
| 504 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 505 | // move resolver. |
| 506 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 507 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 508 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 509 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 510 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 511 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 512 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 513 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 514 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 515 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 516 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 517 | instruction_, |
| 518 | instruction_->GetDexPc(), |
| 519 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 520 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 521 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 522 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 523 | } else { |
| 524 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 525 | arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 526 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 527 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 528 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 529 | if (!is_fatal_) { |
| 530 | RestoreLiveRegisters(codegen, locations); |
| 531 | __ b(GetExitLabel()); |
| 532 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 535 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 536 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 537 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 538 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 539 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 540 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 541 | |
| 542 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 543 | }; |
| 544 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 545 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 546 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 547 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 548 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 549 | |
| 550 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 551 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 552 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 553 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 554 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 557 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 558 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 559 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 560 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 561 | }; |
| 562 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 563 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 564 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 565 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 566 | |
| 567 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 568 | LocationSummary* locations = instruction_->GetLocations(); |
| 569 | __ Bind(GetEntryLabel()); |
| 570 | SaveLiveRegisters(codegen, locations); |
| 571 | |
| 572 | InvokeRuntimeCallingConvention calling_convention; |
| 573 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 574 | parallel_move.AddMove( |
| 575 | locations->InAt(0), |
| 576 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 577 | Primitive::kPrimNot, |
| 578 | nullptr); |
| 579 | parallel_move.AddMove( |
| 580 | locations->InAt(1), |
| 581 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 582 | Primitive::kPrimInt, |
| 583 | nullptr); |
| 584 | parallel_move.AddMove( |
| 585 | locations->InAt(2), |
| 586 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 587 | Primitive::kPrimNot, |
| 588 | nullptr); |
| 589 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 590 | |
| 591 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 592 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 593 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 594 | RestoreLiveRegisters(codegen, locations); |
| 595 | __ b(GetExitLabel()); |
| 596 | } |
| 597 | |
| 598 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 599 | |
| 600 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 601 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 602 | }; |
| 603 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 604 | // Slow path marking an object reference `ref` during a read |
| 605 | // barrier. The field `obj.field` in the object `obj` holding this |
| 606 | // reference does not get updated by this slow path after marking (see |
| 607 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
| 608 | // |
| 609 | // This means that after the execution of this slow path, `ref` will |
| 610 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 611 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 612 | // probably still be a from-space reference (unless it gets updated by |
| 613 | // another thread, or if another thread installed another object |
| 614 | // reference (different from `ref`) in `obj.field`). |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 615 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 616 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 617 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location ref) |
| 618 | : SlowPathCodeARM(instruction), ref_(ref) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 619 | DCHECK(kEmitCompilerReadBarrier); |
| 620 | } |
| 621 | |
| 622 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 623 | |
| 624 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 625 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 626 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 627 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 628 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 629 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 630 | instruction_->IsStaticFieldGet() || |
| 631 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 632 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 633 | instruction_->IsLoadClass() || |
| 634 | instruction_->IsLoadString() || |
| 635 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 636 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 637 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 638 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 639 | << "Unexpected instruction in read barrier marking slow path: " |
| 640 | << instruction_->DebugName(); |
| 641 | |
| 642 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 643 | // No need to save live registers; it's taken care of by the |
| 644 | // entrypoint. Also, there is no need to update the stack mask, |
| 645 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 646 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 647 | DCHECK_NE(ref_reg, SP); |
| 648 | DCHECK_NE(ref_reg, LR); |
| 649 | DCHECK_NE(ref_reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 650 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 651 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 652 | DCHECK_NE(ref_reg, IP); |
| 653 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 654 | // "Compact" slow path, saving two moves. |
| 655 | // |
| 656 | // Instead of using the standard runtime calling convention (input |
| 657 | // and output in R0): |
| 658 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 659 | // R0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 660 | // R0 <- ReadBarrierMark(R0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 661 | // ref <- R0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 662 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 663 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 664 | // of a dedicated entrypoint: |
| 665 | // |
| 666 | // rX <- ReadBarrierMarkRegX(rX) |
| 667 | // |
| 668 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 669 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 670 | // This runtime call does not require a stack map. |
| 671 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 672 | __ b(GetExitLabel()); |
| 673 | } |
| 674 | |
| 675 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 676 | // The location (register) of the marked object reference. |
| 677 | const Location ref_; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 678 | |
| 679 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 680 | }; |
| 681 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 682 | // Slow path marking an object reference `ref` during a read barrier, |
| 683 | // and if needed, atomically updating the field `obj.field` in the |
| 684 | // object `obj` holding this reference after marking (contrary to |
| 685 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 686 | // `obj.field`). |
| 687 | // |
| 688 | // This means that after the execution of this slow path, both `ref` |
| 689 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 690 | // hold the same to-space reference (unless another thread installed |
| 691 | // another object reference (different from `ref`) in `obj.field`). |
| 692 | class ReadBarrierMarkAndUpdateFieldSlowPathARM : public SlowPathCodeARM { |
| 693 | public: |
| 694 | ReadBarrierMarkAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 695 | Location ref, |
| 696 | Register obj, |
| 697 | Location field_offset, |
| 698 | Register temp1, |
| 699 | Register temp2) |
| 700 | : SlowPathCodeARM(instruction), |
| 701 | ref_(ref), |
| 702 | obj_(obj), |
| 703 | field_offset_(field_offset), |
| 704 | temp1_(temp1), |
| 705 | temp2_(temp2) { |
| 706 | DCHECK(kEmitCompilerReadBarrier); |
| 707 | } |
| 708 | |
| 709 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathARM"; } |
| 710 | |
| 711 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 712 | LocationSummary* locations = instruction_->GetLocations(); |
| 713 | Register ref_reg = ref_.AsRegister<Register>(); |
| 714 | DCHECK(locations->CanCall()); |
| 715 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 716 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 717 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 718 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 719 | << instruction_->DebugName(); |
| 720 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 721 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 722 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 723 | |
| 724 | __ Bind(GetEntryLabel()); |
| 725 | |
| 726 | // Save the old reference. |
| 727 | // Note that we cannot use IP to save the old reference, as IP is |
| 728 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 729 | // need the old reference after the call to that entry point. |
| 730 | DCHECK_NE(temp1_, IP); |
| 731 | __ Mov(temp1_, ref_reg); |
| 732 | |
| 733 | // No need to save live registers; it's taken care of by the |
| 734 | // entrypoint. Also, there is no need to update the stack mask, |
| 735 | // as this runtime call will not trigger a garbage collection. |
| 736 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 737 | DCHECK_NE(ref_reg, SP); |
| 738 | DCHECK_NE(ref_reg, LR); |
| 739 | DCHECK_NE(ref_reg, PC); |
| 740 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 741 | // as a temporary, it cannot be the entry point's input/output. |
| 742 | DCHECK_NE(ref_reg, IP); |
| 743 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 744 | // "Compact" slow path, saving two moves. |
| 745 | // |
| 746 | // Instead of using the standard runtime calling convention (input |
| 747 | // and output in R0): |
| 748 | // |
| 749 | // R0 <- ref |
| 750 | // R0 <- ReadBarrierMark(R0) |
| 751 | // ref <- R0 |
| 752 | // |
| 753 | // we just use rX (the register containing `ref`) as input and output |
| 754 | // of a dedicated entrypoint: |
| 755 | // |
| 756 | // rX <- ReadBarrierMarkRegX(rX) |
| 757 | // |
| 758 | int32_t entry_point_offset = |
| 759 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 760 | // This runtime call does not require a stack map. |
| 761 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 762 | |
| 763 | // If the new reference is different from the old reference, |
| 764 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 765 | // |
| 766 | // Note that this field could also hold a different object, if |
| 767 | // another thread had concurrently changed it. In that case, the |
| 768 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 769 | // (CAS) operation below would abort the CAS, leaving the field |
| 770 | // as-is. |
| 771 | Label done; |
| 772 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
| 773 | __ b(&done, EQ); |
| 774 | |
| 775 | // Update the the holder's field atomically. This may fail if |
| 776 | // mutator updates before us, but it's OK. This is achieved |
| 777 | // using a strong compare-and-set (CAS) operation with relaxed |
| 778 | // memory synchronization ordering, where the expected value is |
| 779 | // the old reference and the desired value is the new reference. |
| 780 | |
| 781 | // Convenience aliases. |
| 782 | Register base = obj_; |
| 783 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 784 | // offset ("long offset"), of which only the low part contains |
| 785 | // data. |
| 786 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 787 | Register expected = temp1_; |
| 788 | Register value = ref_reg; |
| 789 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 790 | Register tmp = temp2_; // Value in memory. |
| 791 | |
| 792 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 793 | |
| 794 | if (kPoisonHeapReferences) { |
| 795 | __ PoisonHeapReference(expected); |
| 796 | if (value == expected) { |
| 797 | // Do not poison `value`, as it is the same register as |
| 798 | // `expected`, which has just been poisoned. |
| 799 | } else { |
| 800 | __ PoisonHeapReference(value); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | // do { |
| 805 | // tmp = [r_ptr] - expected; |
| 806 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 807 | |
| 808 | Label loop_head; |
| 809 | __ Bind(&loop_head); |
| 810 | |
| 811 | __ ldrex(tmp, tmp_ptr); |
| 812 | |
| 813 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 814 | |
| 815 | __ it(EQ, ItState::kItT); |
| 816 | __ strex(tmp, value, tmp_ptr, EQ); |
| 817 | __ cmp(tmp, ShifterOperand(1), EQ); |
| 818 | |
| 819 | __ b(&loop_head, EQ); |
| 820 | |
| 821 | if (kPoisonHeapReferences) { |
| 822 | __ UnpoisonHeapReference(expected); |
| 823 | if (value == expected) { |
| 824 | // Do not unpoison `value`, as it is the same register as |
| 825 | // `expected`, which has just been unpoisoned. |
| 826 | } else { |
| 827 | __ UnpoisonHeapReference(value); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | __ Bind(&done); |
| 832 | __ b(GetExitLabel()); |
| 833 | } |
| 834 | |
| 835 | private: |
| 836 | // The location (register) of the marked object reference. |
| 837 | const Location ref_; |
| 838 | // The register containing the object holding the marked object reference field. |
| 839 | const Register obj_; |
| 840 | // The location of the offset of the marked reference field within `obj_`. |
| 841 | Location field_offset_; |
| 842 | |
| 843 | const Register temp1_; |
| 844 | const Register temp2_; |
| 845 | |
| 846 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM); |
| 847 | }; |
| 848 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 849 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 850 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 851 | public: |
| 852 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 853 | Location out, |
| 854 | Location ref, |
| 855 | Location obj, |
| 856 | uint32_t offset, |
| 857 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 858 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 859 | out_(out), |
| 860 | ref_(ref), |
| 861 | obj_(obj), |
| 862 | offset_(offset), |
| 863 | index_(index) { |
| 864 | DCHECK(kEmitCompilerReadBarrier); |
| 865 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 866 | // has been overwritten by (or after) the heap object reference load |
| 867 | // to be instrumented, e.g.: |
| 868 | // |
| 869 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 870 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 871 | // |
| 872 | // In that case, we have lost the information about the original |
| 873 | // object, and the emitted read barrier cannot work properly. |
| 874 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 875 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 876 | } |
| 877 | |
| 878 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 879 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 880 | LocationSummary* locations = instruction_->GetLocations(); |
| 881 | Register reg_out = out_.AsRegister<Register>(); |
| 882 | DCHECK(locations->CanCall()); |
| 883 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 884 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 885 | instruction_->IsStaticFieldGet() || |
| 886 | instruction_->IsArrayGet() || |
| 887 | instruction_->IsInstanceOf() || |
| 888 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 889 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 890 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 891 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 892 | |
| 893 | __ Bind(GetEntryLabel()); |
| 894 | SaveLiveRegisters(codegen, locations); |
| 895 | |
| 896 | // We may have to change the index's value, but as `index_` is a |
| 897 | // constant member (like other "inputs" of this slow path), |
| 898 | // introduce a copy of it, `index`. |
| 899 | Location index = index_; |
| 900 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 901 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 902 | if (instruction_->IsArrayGet()) { |
| 903 | // Compute the actual memory offset and store it in `index`. |
| 904 | Register index_reg = index_.AsRegister<Register>(); |
| 905 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 906 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 907 | // We are about to change the value of `index_reg` (see the |
| 908 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 909 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 910 | // not been saved by the previous call to |
| 911 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 912 | // callee-save register -- |
| 913 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 914 | // callee-save registers, as it has been designed with the |
| 915 | // assumption that callee-save registers are supposed to be |
| 916 | // handled by the called function. So, as a callee-save |
| 917 | // register, `index_reg` _would_ eventually be saved onto |
| 918 | // the stack, but it would be too late: we would have |
| 919 | // changed its value earlier. Therefore, we manually save |
| 920 | // it here into another freely available register, |
| 921 | // `free_reg`, chosen of course among the caller-save |
| 922 | // registers (as a callee-save `free_reg` register would |
| 923 | // exhibit the same problem). |
| 924 | // |
| 925 | // Note we could have requested a temporary register from |
| 926 | // the register allocator instead; but we prefer not to, as |
| 927 | // this is a slow path, and we know we can find a |
| 928 | // caller-save register that is available. |
| 929 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 930 | __ Mov(free_reg, index_reg); |
| 931 | index_reg = free_reg; |
| 932 | index = Location::RegisterLocation(index_reg); |
| 933 | } else { |
| 934 | // The initial register stored in `index_` has already been |
| 935 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 936 | // (as it is not a callee-save register), so we can freely |
| 937 | // use it. |
| 938 | } |
| 939 | // Shifting the index value contained in `index_reg` by the scale |
| 940 | // factor (2) cannot overflow in practice, as the runtime is |
| 941 | // unable to allocate object arrays with a size larger than |
| 942 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 943 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 944 | static_assert( |
| 945 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 946 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 947 | __ AddConstant(index_reg, index_reg, offset_); |
| 948 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 949 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 950 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 951 | // (as in the case of ArrayGet), as it is actually an offset |
| 952 | // to an object field within an object. |
| 953 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 954 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 955 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 956 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 957 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 958 | DCHECK_EQ(offset_, 0U); |
| 959 | DCHECK(index_.IsRegisterPair()); |
| 960 | // UnsafeGet's offset location is a register pair, the low |
| 961 | // part contains the correct offset. |
| 962 | index = index_.ToLow(); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | // We're moving two or three locations to locations that could |
| 967 | // overlap, so we need a parallel move resolver. |
| 968 | InvokeRuntimeCallingConvention calling_convention; |
| 969 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 970 | parallel_move.AddMove(ref_, |
| 971 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 972 | Primitive::kPrimNot, |
| 973 | nullptr); |
| 974 | parallel_move.AddMove(obj_, |
| 975 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 976 | Primitive::kPrimNot, |
| 977 | nullptr); |
| 978 | if (index.IsValid()) { |
| 979 | parallel_move.AddMove(index, |
| 980 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 981 | Primitive::kPrimInt, |
| 982 | nullptr); |
| 983 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 984 | } else { |
| 985 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 986 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 987 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 988 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 989 | CheckEntrypointTypes< |
| 990 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 991 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 992 | |
| 993 | RestoreLiveRegisters(codegen, locations); |
| 994 | __ b(GetExitLabel()); |
| 995 | } |
| 996 | |
| 997 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 998 | |
| 999 | private: |
| 1000 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1001 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1002 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1003 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1004 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1005 | return static_cast<Register>(i); |
| 1006 | } |
| 1007 | } |
| 1008 | // We shall never fail to find a free caller-save register, as |
| 1009 | // there are more than two core caller-save registers on ARM |
| 1010 | // (meaning it is possible to find one which is different from |
| 1011 | // `ref` and `obj`). |
| 1012 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1013 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1014 | UNREACHABLE(); |
| 1015 | } |
| 1016 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1017 | const Location out_; |
| 1018 | const Location ref_; |
| 1019 | const Location obj_; |
| 1020 | const uint32_t offset_; |
| 1021 | // An additional location containing an index to an array. |
| 1022 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1023 | // UnsafeGetObjectVolatile intrinsics. |
| 1024 | const Location index_; |
| 1025 | |
| 1026 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1027 | }; |
| 1028 | |
| 1029 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1030 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1031 | public: |
| 1032 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1033 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1034 | DCHECK(kEmitCompilerReadBarrier); |
| 1035 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1036 | |
| 1037 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1038 | LocationSummary* locations = instruction_->GetLocations(); |
| 1039 | Register reg_out = out_.AsRegister<Register>(); |
| 1040 | DCHECK(locations->CanCall()); |
| 1041 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1042 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1043 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1044 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1045 | |
| 1046 | __ Bind(GetEntryLabel()); |
| 1047 | SaveLiveRegisters(codegen, locations); |
| 1048 | |
| 1049 | InvokeRuntimeCallingConvention calling_convention; |
| 1050 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1051 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1052 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1053 | instruction_, |
| 1054 | instruction_->GetDexPc(), |
| 1055 | this); |
| 1056 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1057 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1058 | |
| 1059 | RestoreLiveRegisters(codegen, locations); |
| 1060 | __ b(GetExitLabel()); |
| 1061 | } |
| 1062 | |
| 1063 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1064 | |
| 1065 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1066 | const Location out_; |
| 1067 | const Location root_; |
| 1068 | |
| 1069 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1070 | }; |
| 1071 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1072 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1073 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1074 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1075 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1076 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1077 | switch (cond) { |
| 1078 | case kCondEQ: return EQ; |
| 1079 | case kCondNE: return NE; |
| 1080 | case kCondLT: return LT; |
| 1081 | case kCondLE: return LE; |
| 1082 | case kCondGT: return GT; |
| 1083 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1084 | case kCondB: return LO; |
| 1085 | case kCondBE: return LS; |
| 1086 | case kCondA: return HI; |
| 1087 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1088 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1089 | LOG(FATAL) << "Unreachable"; |
| 1090 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1093 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1094 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1095 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1096 | case kCondEQ: return EQ; |
| 1097 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1098 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1099 | case kCondLT: return LO; |
| 1100 | case kCondLE: return LS; |
| 1101 | case kCondGT: return HI; |
| 1102 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1103 | // Unsigned remain unchanged. |
| 1104 | case kCondB: return LO; |
| 1105 | case kCondBE: return LS; |
| 1106 | case kCondA: return HI; |
| 1107 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1108 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1109 | LOG(FATAL) << "Unreachable"; |
| 1110 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1113 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1114 | // The ARM condition codes can express all the necessary branches, see the |
| 1115 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1116 | // There is no dex instruction or HIR that would need the missing conditions |
| 1117 | // "equal or unordered" or "not equal". |
| 1118 | switch (cond) { |
| 1119 | case kCondEQ: return EQ; |
| 1120 | case kCondNE: return NE /* unordered */; |
| 1121 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1122 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1123 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1124 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1125 | default: |
| 1126 | LOG(FATAL) << "UNREACHABLE"; |
| 1127 | UNREACHABLE(); |
| 1128 | } |
| 1129 | } |
| 1130 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1131 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1132 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1136 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1139 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1140 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1141 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1144 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1145 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1146 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1149 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1150 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1151 | return kArmWordSize; |
| 1152 | } |
| 1153 | |
| 1154 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1155 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1156 | return kArmWordSize; |
| 1157 | } |
| 1158 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1159 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1160 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1161 | const CompilerOptions& compiler_options, |
| 1162 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1163 | : CodeGenerator(graph, |
| 1164 | kNumberOfCoreRegisters, |
| 1165 | kNumberOfSRegisters, |
| 1166 | kNumberOfRegisterPairs, |
| 1167 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1168 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1169 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1170 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1171 | compiler_options, |
| 1172 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1173 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1174 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1175 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1176 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1177 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1178 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1179 | uint32_literals_(std::less<uint32_t>(), |
| 1180 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1181 | method_patches_(MethodReferenceComparator(), |
| 1182 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1183 | call_patches_(MethodReferenceComparator(), |
| 1184 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1185 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1186 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1187 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1188 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1189 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1190 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1191 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1192 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1193 | boot_image_address_patches_(std::less<uint32_t>(), |
| 1194 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1195 | // Always save the LR register to mimic Quick. |
| 1196 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1199 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1200 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1201 | __ FinalizeCode(); |
| 1202 | |
| 1203 | // Adjust native pc offsets in stack maps. |
| 1204 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 1205 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 1206 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1207 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1208 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1209 | // Adjust pc offsets for the disassembly information. |
| 1210 | if (disasm_info_ != nullptr) { |
| 1211 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1212 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1213 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1214 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1215 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1216 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1217 | } |
| 1218 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1219 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1220 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1221 | } |
| 1222 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1223 | |
| 1224 | CodeGenerator::Finalize(allocator); |
| 1225 | } |
| 1226 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1227 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1228 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1229 | blocked_core_registers_[SP] = true; |
| 1230 | blocked_core_registers_[LR] = true; |
| 1231 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1232 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1233 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1234 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1235 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1236 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1237 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1238 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1239 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1240 | // Stubs do not save callee-save floating point registers. If the graph |
| 1241 | // is debuggable, we need to deal with these registers differently. For |
| 1242 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1243 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1244 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1245 | } |
| 1246 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1247 | } |
| 1248 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1249 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1250 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1251 | assembler_(codegen->GetAssembler()), |
| 1252 | codegen_(codegen) {} |
| 1253 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1254 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1255 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1256 | 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] | 1257 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1258 | // restore another arbitrary register. |
| 1259 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1260 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1261 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1262 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1263 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1264 | // but in the range. |
| 1265 | if (fpu_spill_mask_ != 0) { |
| 1266 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1267 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1268 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1269 | fpu_spill_mask_ |= (1 << i); |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1274 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1275 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1279 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1282 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1283 | bool skip_overflow_check = |
| 1284 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1285 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1286 | __ Bind(&frame_entry_label_); |
| 1287 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1288 | if (HasEmptyFrame()) { |
| 1289 | return; |
| 1290 | } |
| 1291 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1292 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1293 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1294 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1295 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1296 | } |
| 1297 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1298 | __ PushList(core_spill_mask_); |
| 1299 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1300 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1301 | if (fpu_spill_mask_ != 0) { |
| 1302 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1303 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1304 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1305 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1306 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1307 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1308 | __ AddConstant(SP, -adjust); |
| 1309 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1310 | |
| 1311 | // Save the current method if we need it. Note that we do not |
| 1312 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1313 | // in the SSA graph. |
| 1314 | if (RequiresCurrentMethod()) { |
| 1315 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1316 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1320 | if (HasEmptyFrame()) { |
| 1321 | __ bx(LR); |
| 1322 | return; |
| 1323 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1324 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1325 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1326 | __ AddConstant(SP, adjust); |
| 1327 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1328 | if (fpu_spill_mask_ != 0) { |
| 1329 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1330 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1331 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1332 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1333 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1334 | // Pop LR into PC to return. |
| 1335 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1336 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1337 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1338 | __ cfi().RestoreState(); |
| 1339 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1342 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1343 | Label* label = GetLabelOf(block); |
| 1344 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1347 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1348 | switch (type) { |
| 1349 | case Primitive::kPrimBoolean: |
| 1350 | case Primitive::kPrimByte: |
| 1351 | case Primitive::kPrimChar: |
| 1352 | case Primitive::kPrimShort: |
| 1353 | case Primitive::kPrimInt: |
| 1354 | case Primitive::kPrimNot: { |
| 1355 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1356 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1357 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1358 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1359 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1360 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1361 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1362 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1363 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1364 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1365 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1366 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1367 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1368 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1369 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1370 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1371 | // Skip R1, and use R2_R3 instead. |
| 1372 | gp_index_++; |
| 1373 | index++; |
| 1374 | } |
| 1375 | } |
| 1376 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1377 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1378 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1379 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1380 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1381 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1382 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1383 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | case Primitive::kPrimFloat: { |
| 1388 | uint32_t stack_index = stack_index_++; |
| 1389 | if (float_index_ % 2 == 0) { |
| 1390 | float_index_ = std::max(double_index_, float_index_); |
| 1391 | } |
| 1392 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1393 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1394 | } else { |
| 1395 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | case Primitive::kPrimDouble: { |
| 1400 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1401 | uint32_t stack_index = stack_index_; |
| 1402 | stack_index_ += 2; |
| 1403 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1404 | uint32_t index = double_index_; |
| 1405 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1406 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1407 | calling_convention.GetFpuRegisterAt(index), |
| 1408 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1409 | DCHECK(ExpectedPairLayout(result)); |
| 1410 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1411 | } else { |
| 1412 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1416 | case Primitive::kPrimVoid: |
| 1417 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1418 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1419 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1420 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1421 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1422 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1423 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1424 | switch (type) { |
| 1425 | case Primitive::kPrimBoolean: |
| 1426 | case Primitive::kPrimByte: |
| 1427 | case Primitive::kPrimChar: |
| 1428 | case Primitive::kPrimShort: |
| 1429 | case Primitive::kPrimInt: |
| 1430 | case Primitive::kPrimNot: { |
| 1431 | return Location::RegisterLocation(R0); |
| 1432 | } |
| 1433 | |
| 1434 | case Primitive::kPrimFloat: { |
| 1435 | return Location::FpuRegisterLocation(S0); |
| 1436 | } |
| 1437 | |
| 1438 | case Primitive::kPrimLong: { |
| 1439 | return Location::RegisterPairLocation(R0, R1); |
| 1440 | } |
| 1441 | |
| 1442 | case Primitive::kPrimDouble: { |
| 1443 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1444 | } |
| 1445 | |
| 1446 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1447 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1448 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1449 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1450 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1453 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1454 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1455 | } |
| 1456 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1457 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1458 | if (source.Equals(destination)) { |
| 1459 | return; |
| 1460 | } |
| 1461 | if (destination.IsRegister()) { |
| 1462 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1463 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1464 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1465 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1466 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1467 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1468 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1469 | } else if (destination.IsFpuRegister()) { |
| 1470 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1471 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1472 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1473 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1474 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1475 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1476 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1477 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1478 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1479 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1480 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1481 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1482 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1483 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1484 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1485 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1486 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1492 | if (source.Equals(destination)) { |
| 1493 | return; |
| 1494 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1495 | if (destination.IsRegisterPair()) { |
| 1496 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1497 | EmitParallelMoves( |
| 1498 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1499 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1500 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1501 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1502 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1503 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1504 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1505 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1506 | } else if (source.IsFpuRegisterPair()) { |
| 1507 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1508 | destination.AsRegisterPairHigh<Register>(), |
| 1509 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1510 | } else { |
| 1511 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1512 | DCHECK(ExpectedPairLayout(destination)); |
| 1513 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1514 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1515 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1516 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1517 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1518 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1519 | SP, |
| 1520 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1521 | } else if (source.IsRegisterPair()) { |
| 1522 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1523 | source.AsRegisterPairLow<Register>(), |
| 1524 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1525 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1526 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1527 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1528 | } else { |
| 1529 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1530 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1531 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1532 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1533 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1534 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1535 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1536 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1537 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1538 | SP, destination.GetStackIndex()); |
| 1539 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1540 | } else if (source.IsFpuRegisterPair()) { |
| 1541 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1542 | SP, |
| 1543 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1544 | } else { |
| 1545 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1546 | EmitParallelMoves( |
| 1547 | Location::StackSlot(source.GetStackIndex()), |
| 1548 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1549 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1550 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1551 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1552 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1557 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1558 | DCHECK(location.IsRegister()); |
| 1559 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1560 | } |
| 1561 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1562 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1563 | HParallelMove move(GetGraph()->GetArena()); |
| 1564 | move.AddMove(src, dst, dst_type, nullptr); |
| 1565 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1569 | if (location.IsRegister()) { |
| 1570 | locations->AddTemp(location); |
| 1571 | } else if (location.IsRegisterPair()) { |
| 1572 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1573 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1574 | } else { |
| 1575 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1576 | } |
| 1577 | } |
| 1578 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1579 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1580 | HInstruction* instruction, |
| 1581 | uint32_t dex_pc, |
| 1582 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1583 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1584 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1585 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1586 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1587 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1588 | } |
| 1589 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1590 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1591 | HInstruction* instruction, |
| 1592 | SlowPathCode* slow_path) { |
| 1593 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1594 | GenerateInvokeRuntime(entry_point_offset); |
| 1595 | } |
| 1596 | |
| 1597 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1598 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1599 | __ blx(LR); |
| 1600 | } |
| 1601 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1602 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1603 | DCHECK(!successor->IsExitBlock()); |
| 1604 | |
| 1605 | HBasicBlock* block = got->GetBlock(); |
| 1606 | HInstruction* previous = got->GetPrevious(); |
| 1607 | |
| 1608 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1609 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1610 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1611 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1612 | return; |
| 1613 | } |
| 1614 | |
| 1615 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1616 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1617 | } |
| 1618 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1619 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1623 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1624 | got->SetLocations(nullptr); |
| 1625 | } |
| 1626 | |
| 1627 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1628 | HandleGoto(got, got->GetSuccessor()); |
| 1629 | } |
| 1630 | |
| 1631 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1632 | try_boundary->SetLocations(nullptr); |
| 1633 | } |
| 1634 | |
| 1635 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1636 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1637 | if (!successor->IsExitBlock()) { |
| 1638 | HandleGoto(try_boundary, successor); |
| 1639 | } |
| 1640 | } |
| 1641 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1642 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1643 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1646 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1649 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1650 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1651 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1652 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1653 | if (rhs_loc.IsConstant()) { |
| 1654 | // 0.0 is the only immediate that can be encoded directly in |
| 1655 | // a VCMP instruction. |
| 1656 | // |
| 1657 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1658 | // specify that in a floating-point comparison, positive zero |
| 1659 | // and negative zero are considered equal, so we can use the |
| 1660 | // literal 0.0 for both cases here. |
| 1661 | // |
| 1662 | // Note however that some methods (Float.equal, Float.compare, |
| 1663 | // Float.compareTo, Double.equal, Double.compare, |
| 1664 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1665 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1666 | // -0.0. So if we ever translate calls to these methods into a |
| 1667 | // HCompare instruction, we must handle the -0.0 case with |
| 1668 | // care here. |
| 1669 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1670 | if (type == Primitive::kPrimFloat) { |
| 1671 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1672 | } else { |
| 1673 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1674 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1675 | } |
| 1676 | } else { |
| 1677 | if (type == Primitive::kPrimFloat) { |
| 1678 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1679 | } else { |
| 1680 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1681 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1682 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1687 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1688 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1689 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1690 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1691 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1695 | Label* true_label, |
| 1696 | Label* false_label) { |
| 1697 | LocationSummary* locations = cond->GetLocations(); |
| 1698 | Location left = locations->InAt(0); |
| 1699 | Location right = locations->InAt(1); |
| 1700 | IfCondition if_cond = cond->GetCondition(); |
| 1701 | |
| 1702 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1703 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1704 | IfCondition true_high_cond = if_cond; |
| 1705 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1706 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1707 | |
| 1708 | // Set the conditions for the test, remembering that == needs to be |
| 1709 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1710 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1711 | switch (if_cond) { |
| 1712 | case kCondEQ: |
| 1713 | case kCondNE: |
| 1714 | // Nothing to do. |
| 1715 | break; |
| 1716 | case kCondLT: |
| 1717 | false_high_cond = kCondGT; |
| 1718 | break; |
| 1719 | case kCondLE: |
| 1720 | true_high_cond = kCondLT; |
| 1721 | break; |
| 1722 | case kCondGT: |
| 1723 | false_high_cond = kCondLT; |
| 1724 | break; |
| 1725 | case kCondGE: |
| 1726 | true_high_cond = kCondGT; |
| 1727 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1728 | case kCondB: |
| 1729 | false_high_cond = kCondA; |
| 1730 | break; |
| 1731 | case kCondBE: |
| 1732 | true_high_cond = kCondB; |
| 1733 | break; |
| 1734 | case kCondA: |
| 1735 | false_high_cond = kCondB; |
| 1736 | break; |
| 1737 | case kCondAE: |
| 1738 | true_high_cond = kCondA; |
| 1739 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1740 | } |
| 1741 | if (right.IsConstant()) { |
| 1742 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1743 | int32_t val_low = Low32Bits(value); |
| 1744 | int32_t val_high = High32Bits(value); |
| 1745 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1746 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1747 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1748 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1749 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1750 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1751 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1752 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1753 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1754 | } |
| 1755 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1756 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1757 | } else { |
| 1758 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1759 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1760 | |
| 1761 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1762 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1763 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1764 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1765 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1766 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1767 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1768 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1769 | } |
| 1770 | // Must be equal high, so compare the lows. |
| 1771 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1772 | } |
| 1773 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1774 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1775 | __ b(true_label, final_condition); |
| 1776 | } |
| 1777 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1778 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1779 | Label* true_target_in, |
| 1780 | Label* false_target_in) { |
| 1781 | // Generated branching requires both targets to be explicit. If either of the |
| 1782 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1783 | Label fallthrough_target; |
| 1784 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1785 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1786 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1787 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1788 | switch (type) { |
| 1789 | case Primitive::kPrimLong: |
| 1790 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1791 | break; |
| 1792 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1793 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1794 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1795 | GenerateFPJumps(condition, true_target, false_target); |
| 1796 | break; |
| 1797 | default: |
| 1798 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1799 | } |
| 1800 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1801 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1802 | __ b(false_target); |
| 1803 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1804 | |
| 1805 | if (fallthrough_target.IsLinked()) { |
| 1806 | __ Bind(&fallthrough_target); |
| 1807 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1808 | } |
| 1809 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1810 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1811 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1812 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1813 | Label* false_target) { |
| 1814 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1815 | |
| 1816 | if (true_target == nullptr && false_target == nullptr) { |
| 1817 | // Nothing to do. The code always falls through. |
| 1818 | return; |
| 1819 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1820 | // Constant condition, statically compared against "true" (integer value 1). |
| 1821 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1822 | if (true_target != nullptr) { |
| 1823 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1824 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1825 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1826 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1827 | if (false_target != nullptr) { |
| 1828 | __ b(false_target); |
| 1829 | } |
| 1830 | } |
| 1831 | return; |
| 1832 | } |
| 1833 | |
| 1834 | // The following code generates these patterns: |
| 1835 | // (1) true_target == nullptr && false_target != nullptr |
| 1836 | // - opposite condition true => branch to false_target |
| 1837 | // (2) true_target != nullptr && false_target == nullptr |
| 1838 | // - condition true => branch to true_target |
| 1839 | // (3) true_target != nullptr && false_target != nullptr |
| 1840 | // - condition true => branch to true_target |
| 1841 | // - branch to false_target |
| 1842 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1843 | // Condition has been materialized, compare the output to 0. |
| 1844 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1845 | DCHECK(cond_val.IsRegister()); |
| 1846 | if (true_target == nullptr) { |
| 1847 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1848 | } else { |
| 1849 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1850 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1851 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1852 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1853 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1854 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1855 | |
| 1856 | // If this is a long or FP comparison that has been folded into |
| 1857 | // the HCondition, generate the comparison directly. |
| 1858 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1859 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1860 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1861 | return; |
| 1862 | } |
| 1863 | |
| 1864 | LocationSummary* locations = cond->GetLocations(); |
| 1865 | DCHECK(locations->InAt(0).IsRegister()); |
| 1866 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1867 | Location right = locations->InAt(1); |
| 1868 | if (right.IsRegister()) { |
| 1869 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1870 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1871 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1872 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1873 | } |
| 1874 | if (true_target == nullptr) { |
| 1875 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1876 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1877 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1878 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1879 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1880 | |
| 1881 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1882 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1883 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1884 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1888 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1889 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1890 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1891 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1896 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1897 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1898 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1899 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1900 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1901 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1902 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1906 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1907 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1908 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1909 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1910 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1915 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1916 | GenerateTestAndBranch(deoptimize, |
| 1917 | /* condition_input_index */ 0, |
| 1918 | slow_path->GetEntryLabel(), |
| 1919 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1920 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1921 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1922 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1923 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1924 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1925 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1926 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1927 | } else { |
| 1928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1929 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1930 | } |
| 1931 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1932 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1933 | } |
| 1934 | locations->SetOut(Location::SameAsFirstInput()); |
| 1935 | } |
| 1936 | |
| 1937 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1938 | LocationSummary* locations = select->GetLocations(); |
| 1939 | Label false_target; |
| 1940 | GenerateTestAndBranch(select, |
| 1941 | /* condition_input_index */ 2, |
| 1942 | /* true_target */ nullptr, |
| 1943 | &false_target); |
| 1944 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1945 | __ Bind(&false_target); |
| 1946 | } |
| 1947 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1948 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1949 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1950 | } |
| 1951 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1952 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1953 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void CodeGeneratorARM::GenerateNop() { |
| 1957 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1960 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1961 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1962 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1963 | // Handle the long/FP comparisons made in instruction simplification. |
| 1964 | switch (cond->InputAt(0)->GetType()) { |
| 1965 | case Primitive::kPrimLong: |
| 1966 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1967 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1968 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1969 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1970 | } |
| 1971 | break; |
| 1972 | |
| 1973 | case Primitive::kPrimFloat: |
| 1974 | case Primitive::kPrimDouble: |
| 1975 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1976 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1977 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1978 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1979 | } |
| 1980 | break; |
| 1981 | |
| 1982 | default: |
| 1983 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1984 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1985 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1986 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1987 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1988 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1992 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1993 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1994 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1995 | |
| 1996 | LocationSummary* locations = cond->GetLocations(); |
| 1997 | Location left = locations->InAt(0); |
| 1998 | Location right = locations->InAt(1); |
| 1999 | Register out = locations->Out().AsRegister<Register>(); |
| 2000 | Label true_label, false_label; |
| 2001 | |
| 2002 | switch (cond->InputAt(0)->GetType()) { |
| 2003 | default: { |
| 2004 | // Integer case. |
| 2005 | if (right.IsRegister()) { |
| 2006 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2007 | } else { |
| 2008 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2009 | __ CmpConstant(left.AsRegister<Register>(), |
| 2010 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2011 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2012 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2013 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2014 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2015 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2016 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2017 | return; |
| 2018 | } |
| 2019 | case Primitive::kPrimLong: |
| 2020 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2021 | break; |
| 2022 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2023 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2024 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2025 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | // Convert the jumps into the result. |
| 2030 | Label done_label; |
| 2031 | |
| 2032 | // False case: result = 0. |
| 2033 | __ Bind(&false_label); |
| 2034 | __ LoadImmediate(out, 0); |
| 2035 | __ b(&done_label); |
| 2036 | |
| 2037 | // True case: result = 1. |
| 2038 | __ Bind(&true_label); |
| 2039 | __ LoadImmediate(out, 1); |
| 2040 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2044 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2048 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2052 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2056 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2060 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2064 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2068 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2072 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2076 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2080 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2084 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2088 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2091 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2092 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2096 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2100 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2104 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2108 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2112 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2116 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2120 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2123 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2124 | LocationSummary* locations = |
| 2125 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2126 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2129 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2130 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2133 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2134 | LocationSummary* locations = |
| 2135 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2136 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2137 | } |
| 2138 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2139 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2140 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2143 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2144 | LocationSummary* locations = |
| 2145 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2146 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2147 | } |
| 2148 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2149 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2150 | // Will be generated at use site. |
| 2151 | } |
| 2152 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2153 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2154 | LocationSummary* locations = |
| 2155 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2156 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2157 | } |
| 2158 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2159 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2160 | // Will be generated at use site. |
| 2161 | } |
| 2162 | |
| 2163 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2164 | LocationSummary* locations = |
| 2165 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2166 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2167 | } |
| 2168 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2169 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2170 | // Will be generated at use site. |
| 2171 | } |
| 2172 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2173 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2174 | memory_barrier->SetLocations(nullptr); |
| 2175 | } |
| 2176 | |
| 2177 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2178 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2179 | } |
| 2180 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2181 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2182 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2185 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2186 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2189 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2190 | LocationSummary* locations = |
| 2191 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2192 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2195 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2196 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2199 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2200 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2201 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2202 | // the method_idx. |
| 2203 | HandleInvoke(invoke); |
| 2204 | } |
| 2205 | |
| 2206 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2207 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2208 | } |
| 2209 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2210 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2211 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2212 | // art::PrepareForRegisterAllocation. |
| 2213 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2214 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2215 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2216 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2217 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2218 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2219 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2220 | return; |
| 2221 | } |
| 2222 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2223 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2224 | |
| 2225 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2226 | if (invoke->HasPcRelativeDexCache()) { |
| 2227 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2228 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2229 | } |
| 2230 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2231 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2232 | if (invoke->GetLocations()->Intrinsified()) { |
| 2233 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2234 | intrinsic.Dispatch(invoke); |
| 2235 | return true; |
| 2236 | } |
| 2237 | return false; |
| 2238 | } |
| 2239 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2240 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2241 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2242 | // art::PrepareForRegisterAllocation. |
| 2243 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2244 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2245 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2246 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2247 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2248 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2249 | LocationSummary* locations = invoke->GetLocations(); |
| 2250 | codegen_->GenerateStaticOrDirectCall( |
| 2251 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2252 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2253 | } |
| 2254 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2255 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2256 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2257 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2260 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2261 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2262 | if (intrinsic.TryDispatch(invoke)) { |
| 2263 | return; |
| 2264 | } |
| 2265 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2266 | HandleInvoke(invoke); |
| 2267 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2268 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2269 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2270 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2271 | return; |
| 2272 | } |
| 2273 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2274 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2275 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2276 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2279 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2280 | HandleInvoke(invoke); |
| 2281 | // Add the hidden argument. |
| 2282 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2283 | } |
| 2284 | |
| 2285 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2286 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2287 | LocationSummary* locations = invoke->GetLocations(); |
| 2288 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2289 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2290 | Location receiver = locations->InAt(0); |
| 2291 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2292 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2293 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2294 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2295 | DCHECK_EQ(R12, hidden_reg); |
| 2296 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2297 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2298 | if (receiver.IsStackSlot()) { |
| 2299 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2300 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2301 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2302 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2303 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2304 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2305 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2306 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2307 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2308 | // emit a read barrier for the previous class reference load. |
| 2309 | // However this is not required in practice, as this is an |
| 2310 | // intermediate/temporary reference and because the current |
| 2311 | // concurrent copying collector keeps the from-space memory |
| 2312 | // intact/accessible until the end of the marking phase (the |
| 2313 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2314 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2315 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2316 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2317 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2318 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2319 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2320 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2321 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2322 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2323 | // LR = temp->GetEntryPoint(); |
| 2324 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2325 | // LR(); |
| 2326 | __ blx(LR); |
| 2327 | DCHECK(!codegen_->IsLeafMethod()); |
| 2328 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2329 | } |
| 2330 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2331 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2332 | LocationSummary* locations = |
| 2333 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2334 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2335 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2336 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2337 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2338 | break; |
| 2339 | } |
| 2340 | case Primitive::kPrimLong: { |
| 2341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2342 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2343 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2344 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2345 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2346 | case Primitive::kPrimFloat: |
| 2347 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2349 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2350 | break; |
| 2351 | |
| 2352 | default: |
| 2353 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2358 | LocationSummary* locations = neg->GetLocations(); |
| 2359 | Location out = locations->Out(); |
| 2360 | Location in = locations->InAt(0); |
| 2361 | switch (neg->GetResultType()) { |
| 2362 | case Primitive::kPrimInt: |
| 2363 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2364 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2365 | break; |
| 2366 | |
| 2367 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2368 | DCHECK(in.IsRegisterPair()); |
| 2369 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2370 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2371 | in.AsRegisterPairLow<Register>(), |
| 2372 | ShifterOperand(0)); |
| 2373 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2374 | // instruction here, as it does not exist in the Thumb-2 |
| 2375 | // instruction set. We use the following approach |
| 2376 | // using SBC and SUB instead. |
| 2377 | // |
| 2378 | // out.hi = -C |
| 2379 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2380 | out.AsRegisterPairHigh<Register>(), |
| 2381 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2382 | // out.hi = out.hi - in.hi |
| 2383 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2384 | out.AsRegisterPairHigh<Register>(), |
| 2385 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2386 | break; |
| 2387 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2388 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2389 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2390 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2393 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2394 | DCHECK(in.IsFpuRegisterPair()); |
| 2395 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2396 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2397 | break; |
| 2398 | |
| 2399 | default: |
| 2400 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2401 | } |
| 2402 | } |
| 2403 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2404 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | Primitive::Type result_type = conversion->GetResultType(); |
| 2406 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2407 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2408 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2409 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2410 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2411 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2412 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2413 | && result_type == Primitive::kPrimLong) |
| 2414 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2415 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2416 | : LocationSummary::kNoCall; |
| 2417 | LocationSummary* locations = |
| 2418 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2419 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2420 | // The Java language does not allow treating boolean as an integral type but |
| 2421 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2422 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2423 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimByte: |
| 2425 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimLong: |
| 2427 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimBoolean: |
| 2429 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimShort: |
| 2431 | case Primitive::kPrimInt: |
| 2432 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2433 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2435 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2436 | break; |
| 2437 | |
| 2438 | default: |
| 2439 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2440 | << " to " << result_type; |
| 2441 | } |
| 2442 | break; |
| 2443 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2444 | case Primitive::kPrimShort: |
| 2445 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimLong: |
| 2447 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimBoolean: |
| 2449 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2450 | case Primitive::kPrimByte: |
| 2451 | case Primitive::kPrimInt: |
| 2452 | case Primitive::kPrimChar: |
| 2453 | // Processing a Dex `int-to-short' instruction. |
| 2454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2456 | break; |
| 2457 | |
| 2458 | default: |
| 2459 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2460 | << " to " << result_type; |
| 2461 | } |
| 2462 | break; |
| 2463 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimInt: |
| 2465 | switch (input_type) { |
| 2466 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2467 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2468 | locations->SetInAt(0, Location::Any()); |
| 2469 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2470 | break; |
| 2471 | |
| 2472 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2473 | // Processing a Dex `float-to-int' instruction. |
| 2474 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2475 | locations->SetOut(Location::RequiresRegister()); |
| 2476 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2477 | break; |
| 2478 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2479 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2480 | // Processing a Dex `double-to-int' instruction. |
| 2481 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2482 | locations->SetOut(Location::RequiresRegister()); |
| 2483 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | |
| 2486 | default: |
| 2487 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2488 | << " to " << result_type; |
| 2489 | } |
| 2490 | break; |
| 2491 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimLong: |
| 2493 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimBoolean: |
| 2495 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimByte: |
| 2497 | case Primitive::kPrimShort: |
| 2498 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2500 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2501 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2502 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2503 | break; |
| 2504 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimFloat: { |
| 2506 | // Processing a Dex `float-to-long' instruction. |
| 2507 | InvokeRuntimeCallingConvention calling_convention; |
| 2508 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2509 | calling_convention.GetFpuRegisterAt(0))); |
| 2510 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2511 | break; |
| 2512 | } |
| 2513 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimDouble: { |
| 2515 | // Processing a Dex `double-to-long' instruction. |
| 2516 | InvokeRuntimeCallingConvention calling_convention; |
| 2517 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2518 | calling_convention.GetFpuRegisterAt(0), |
| 2519 | calling_convention.GetFpuRegisterAt(1))); |
| 2520 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2521 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2522 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2523 | |
| 2524 | default: |
| 2525 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2526 | << " to " << result_type; |
| 2527 | } |
| 2528 | break; |
| 2529 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimChar: |
| 2531 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimLong: |
| 2533 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimBoolean: |
| 2535 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimByte: |
| 2537 | case Primitive::kPrimShort: |
| 2538 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2539 | // Processing a Dex `int-to-char' instruction. |
| 2540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2541 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2542 | break; |
| 2543 | |
| 2544 | default: |
| 2545 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2546 | << " to " << result_type; |
| 2547 | } |
| 2548 | break; |
| 2549 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2551 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2552 | case Primitive::kPrimBoolean: |
| 2553 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimByte: |
| 2555 | case Primitive::kPrimShort: |
| 2556 | case Primitive::kPrimInt: |
| 2557 | case Primitive::kPrimChar: |
| 2558 | // Processing a Dex `int-to-float' instruction. |
| 2559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2560 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2561 | break; |
| 2562 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2563 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2564 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2565 | InvokeRuntimeCallingConvention calling_convention; |
| 2566 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2567 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2568 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2569 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2570 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2571 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2573 | // Processing a Dex `double-to-float' instruction. |
| 2574 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2575 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | |
| 2578 | default: |
| 2579 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2580 | << " to " << result_type; |
| 2581 | }; |
| 2582 | break; |
| 2583 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2584 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2585 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimBoolean: |
| 2587 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimByte: |
| 2589 | case Primitive::kPrimShort: |
| 2590 | case Primitive::kPrimInt: |
| 2591 | case Primitive::kPrimChar: |
| 2592 | // Processing a Dex `int-to-double' instruction. |
| 2593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2594 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2595 | break; |
| 2596 | |
| 2597 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2598 | // Processing a Dex `long-to-double' instruction. |
| 2599 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2600 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2601 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2602 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2603 | break; |
| 2604 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2606 | // Processing a Dex `float-to-double' instruction. |
| 2607 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2608 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2609 | break; |
| 2610 | |
| 2611 | default: |
| 2612 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2613 | << " to " << result_type; |
| 2614 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2615 | break; |
| 2616 | |
| 2617 | default: |
| 2618 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2619 | << " to " << result_type; |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2624 | LocationSummary* locations = conversion->GetLocations(); |
| 2625 | Location out = locations->Out(); |
| 2626 | Location in = locations->InAt(0); |
| 2627 | Primitive::Type result_type = conversion->GetResultType(); |
| 2628 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2629 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2630 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2631 | case Primitive::kPrimByte: |
| 2632 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimLong: |
| 2634 | // Type conversion from long to byte is a result of code transformations. |
| 2635 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2636 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimBoolean: |
| 2638 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2639 | case Primitive::kPrimShort: |
| 2640 | case Primitive::kPrimInt: |
| 2641 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2642 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2643 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2644 | break; |
| 2645 | |
| 2646 | default: |
| 2647 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2648 | << " to " << result_type; |
| 2649 | } |
| 2650 | break; |
| 2651 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2652 | case Primitive::kPrimShort: |
| 2653 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2654 | case Primitive::kPrimLong: |
| 2655 | // Type conversion from long to short is a result of code transformations. |
| 2656 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2657 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimBoolean: |
| 2659 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2660 | case Primitive::kPrimByte: |
| 2661 | case Primitive::kPrimInt: |
| 2662 | case Primitive::kPrimChar: |
| 2663 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2664 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2665 | break; |
| 2666 | |
| 2667 | default: |
| 2668 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2669 | << " to " << result_type; |
| 2670 | } |
| 2671 | break; |
| 2672 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2673 | case Primitive::kPrimInt: |
| 2674 | switch (input_type) { |
| 2675 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2676 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2677 | DCHECK(out.IsRegister()); |
| 2678 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2679 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2680 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2681 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2682 | } else { |
| 2683 | DCHECK(in.IsConstant()); |
| 2684 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2685 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2686 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2687 | } |
| 2688 | break; |
| 2689 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2690 | case Primitive::kPrimFloat: { |
| 2691 | // Processing a Dex `float-to-int' instruction. |
| 2692 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2693 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2694 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2695 | break; |
| 2696 | } |
| 2697 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2698 | case Primitive::kPrimDouble: { |
| 2699 | // Processing a Dex `double-to-int' instruction. |
| 2700 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2701 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2702 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2703 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2704 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2705 | |
| 2706 | default: |
| 2707 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2708 | << " to " << result_type; |
| 2709 | } |
| 2710 | break; |
| 2711 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2712 | case Primitive::kPrimLong: |
| 2713 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2714 | case Primitive::kPrimBoolean: |
| 2715 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2716 | case Primitive::kPrimByte: |
| 2717 | case Primitive::kPrimShort: |
| 2718 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2719 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2720 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2721 | DCHECK(out.IsRegisterPair()); |
| 2722 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2723 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2724 | // Sign extension. |
| 2725 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2726 | out.AsRegisterPairLow<Register>(), |
| 2727 | 31); |
| 2728 | break; |
| 2729 | |
| 2730 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2731 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2732 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2733 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2736 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2737 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2738 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2739 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2740 | break; |
| 2741 | |
| 2742 | default: |
| 2743 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2744 | << " to " << result_type; |
| 2745 | } |
| 2746 | break; |
| 2747 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2748 | case Primitive::kPrimChar: |
| 2749 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2750 | case Primitive::kPrimLong: |
| 2751 | // Type conversion from long to char is a result of code transformations. |
| 2752 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2753 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2754 | case Primitive::kPrimBoolean: |
| 2755 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2756 | case Primitive::kPrimByte: |
| 2757 | case Primitive::kPrimShort: |
| 2758 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2759 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2760 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2761 | break; |
| 2762 | |
| 2763 | default: |
| 2764 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2765 | << " to " << result_type; |
| 2766 | } |
| 2767 | break; |
| 2768 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2769 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2770 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2771 | case Primitive::kPrimBoolean: |
| 2772 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2773 | case Primitive::kPrimByte: |
| 2774 | case Primitive::kPrimShort: |
| 2775 | case Primitive::kPrimInt: |
| 2776 | case Primitive::kPrimChar: { |
| 2777 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2778 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2779 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2780 | break; |
| 2781 | } |
| 2782 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2783 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2784 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2785 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2786 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2787 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2788 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2789 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2790 | // Processing a Dex `double-to-float' instruction. |
| 2791 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2792 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2793 | break; |
| 2794 | |
| 2795 | default: |
| 2796 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2797 | << " to " << result_type; |
| 2798 | }; |
| 2799 | break; |
| 2800 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2801 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2802 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2803 | case Primitive::kPrimBoolean: |
| 2804 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2805 | case Primitive::kPrimByte: |
| 2806 | case Primitive::kPrimShort: |
| 2807 | case Primitive::kPrimInt: |
| 2808 | case Primitive::kPrimChar: { |
| 2809 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2810 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2811 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2812 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2813 | break; |
| 2814 | } |
| 2815 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2816 | case Primitive::kPrimLong: { |
| 2817 | // Processing a Dex `long-to-double' instruction. |
| 2818 | Register low = in.AsRegisterPairLow<Register>(); |
| 2819 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2820 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2821 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2822 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2823 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2824 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2825 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2826 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2827 | // temp_d = int-to-double(high) |
| 2828 | __ vmovsr(temp_s, high); |
| 2829 | __ vcvtdi(temp_d, temp_s); |
| 2830 | // constant_d = k2Pow32EncodingForDouble |
| 2831 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2832 | // out_d = unsigned-to-double(low) |
| 2833 | __ vmovsr(out_s, low); |
| 2834 | __ vcvtdu(out_d, out_s); |
| 2835 | // out_d += temp_d * constant_d |
| 2836 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2837 | break; |
| 2838 | } |
| 2839 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2840 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2841 | // Processing a Dex `float-to-double' instruction. |
| 2842 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2843 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2844 | break; |
| 2845 | |
| 2846 | default: |
| 2847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2848 | << " to " << result_type; |
| 2849 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2850 | break; |
| 2851 | |
| 2852 | default: |
| 2853 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2854 | << " to " << result_type; |
| 2855 | } |
| 2856 | } |
| 2857 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2858 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2859 | LocationSummary* locations = |
| 2860 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2861 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2862 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2864 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2866 | break; |
| 2867 | } |
| 2868 | |
| 2869 | case Primitive::kPrimLong: { |
| 2870 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2871 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2872 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2873 | break; |
| 2874 | } |
| 2875 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2876 | case Primitive::kPrimFloat: |
| 2877 | case Primitive::kPrimDouble: { |
| 2878 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2879 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2880 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2881 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2882 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2883 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2884 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2885 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2886 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2890 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2891 | Location out = locations->Out(); |
| 2892 | Location first = locations->InAt(0); |
| 2893 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2894 | switch (add->GetResultType()) { |
| 2895 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2896 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2897 | __ add(out.AsRegister<Register>(), |
| 2898 | first.AsRegister<Register>(), |
| 2899 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2900 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2901 | __ AddConstant(out.AsRegister<Register>(), |
| 2902 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2903 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2904 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2905 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2906 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2907 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2908 | if (second.IsConstant()) { |
| 2909 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2910 | GenerateAddLongConst(out, first, value); |
| 2911 | } else { |
| 2912 | DCHECK(second.IsRegisterPair()); |
| 2913 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2914 | first.AsRegisterPairLow<Register>(), |
| 2915 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2916 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2917 | first.AsRegisterPairHigh<Register>(), |
| 2918 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2919 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2920 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2921 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2922 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2923 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2924 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2925 | first.AsFpuRegister<SRegister>(), |
| 2926 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2927 | break; |
| 2928 | |
| 2929 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2930 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2931 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2932 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2933 | break; |
| 2934 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2935 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2936 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2940 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2941 | LocationSummary* locations = |
| 2942 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2943 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2944 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2945 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2946 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2947 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2948 | break; |
| 2949 | } |
| 2950 | |
| 2951 | case Primitive::kPrimLong: { |
| 2952 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2953 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2954 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2955 | break; |
| 2956 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2957 | case Primitive::kPrimFloat: |
| 2958 | case Primitive::kPrimDouble: { |
| 2959 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2960 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2961 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2962 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2963 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2964 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2965 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2966 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2970 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2971 | Location out = locations->Out(); |
| 2972 | Location first = locations->InAt(0); |
| 2973 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2974 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2975 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2976 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2977 | __ sub(out.AsRegister<Register>(), |
| 2978 | first.AsRegister<Register>(), |
| 2979 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2980 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2981 | __ AddConstant(out.AsRegister<Register>(), |
| 2982 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2983 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2984 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2985 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2986 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2987 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2988 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2989 | if (second.IsConstant()) { |
| 2990 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2991 | GenerateAddLongConst(out, first, -value); |
| 2992 | } else { |
| 2993 | DCHECK(second.IsRegisterPair()); |
| 2994 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2995 | first.AsRegisterPairLow<Register>(), |
| 2996 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2997 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2998 | first.AsRegisterPairHigh<Register>(), |
| 2999 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3000 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3001 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3002 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3003 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3004 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3005 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3006 | first.AsFpuRegister<SRegister>(), |
| 3007 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3008 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3012 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3013 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3014 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3015 | break; |
| 3016 | } |
| 3017 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3018 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3019 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3020 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3024 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3025 | LocationSummary* locations = |
| 3026 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3027 | switch (mul->GetResultType()) { |
| 3028 | case Primitive::kPrimInt: |
| 3029 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3030 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3031 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3032 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3033 | break; |
| 3034 | } |
| 3035 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3036 | case Primitive::kPrimFloat: |
| 3037 | case Primitive::kPrimDouble: { |
| 3038 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3039 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3040 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3041 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3042 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3043 | |
| 3044 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3045 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3050 | LocationSummary* locations = mul->GetLocations(); |
| 3051 | Location out = locations->Out(); |
| 3052 | Location first = locations->InAt(0); |
| 3053 | Location second = locations->InAt(1); |
| 3054 | switch (mul->GetResultType()) { |
| 3055 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3056 | __ mul(out.AsRegister<Register>(), |
| 3057 | first.AsRegister<Register>(), |
| 3058 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3059 | break; |
| 3060 | } |
| 3061 | case Primitive::kPrimLong: { |
| 3062 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3063 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3064 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3065 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3066 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3067 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3068 | |
| 3069 | // Extra checks to protect caused by the existence of R1_R2. |
| 3070 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3071 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3072 | DCHECK_NE(out_hi, in1_lo); |
| 3073 | DCHECK_NE(out_hi, in2_lo); |
| 3074 | |
| 3075 | // input: in1 - 64 bits, in2 - 64 bits |
| 3076 | // output: out |
| 3077 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3078 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3079 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3080 | |
| 3081 | // IP <- in1.lo * in2.hi |
| 3082 | __ mul(IP, in1_lo, in2_hi); |
| 3083 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3084 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3085 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3086 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3087 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3088 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3089 | break; |
| 3090 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3091 | |
| 3092 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3093 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3094 | first.AsFpuRegister<SRegister>(), |
| 3095 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3096 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3100 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3101 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3102 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3103 | break; |
| 3104 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3105 | |
| 3106 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3107 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3108 | } |
| 3109 | } |
| 3110 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3111 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3112 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3113 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3114 | |
| 3115 | LocationSummary* locations = instruction->GetLocations(); |
| 3116 | Location second = locations->InAt(1); |
| 3117 | DCHECK(second.IsConstant()); |
| 3118 | |
| 3119 | Register out = locations->Out().AsRegister<Register>(); |
| 3120 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3121 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3122 | DCHECK(imm == 1 || imm == -1); |
| 3123 | |
| 3124 | if (instruction->IsRem()) { |
| 3125 | __ LoadImmediate(out, 0); |
| 3126 | } else { |
| 3127 | if (imm == 1) { |
| 3128 | __ Mov(out, dividend); |
| 3129 | } else { |
| 3130 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3136 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3137 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3138 | |
| 3139 | LocationSummary* locations = instruction->GetLocations(); |
| 3140 | Location second = locations->InAt(1); |
| 3141 | DCHECK(second.IsConstant()); |
| 3142 | |
| 3143 | Register out = locations->Out().AsRegister<Register>(); |
| 3144 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3145 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3146 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3147 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3148 | int ctz_imm = CTZ(abs_imm); |
| 3149 | |
| 3150 | if (ctz_imm == 1) { |
| 3151 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3152 | } else { |
| 3153 | __ Asr(temp, dividend, 31); |
| 3154 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3155 | } |
| 3156 | __ add(out, temp, ShifterOperand(dividend)); |
| 3157 | |
| 3158 | if (instruction->IsDiv()) { |
| 3159 | __ Asr(out, out, ctz_imm); |
| 3160 | if (imm < 0) { |
| 3161 | __ rsb(out, out, ShifterOperand(0)); |
| 3162 | } |
| 3163 | } else { |
| 3164 | __ ubfx(out, out, 0, ctz_imm); |
| 3165 | __ sub(out, out, ShifterOperand(temp)); |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3170 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3171 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3172 | |
| 3173 | LocationSummary* locations = instruction->GetLocations(); |
| 3174 | Location second = locations->InAt(1); |
| 3175 | DCHECK(second.IsConstant()); |
| 3176 | |
| 3177 | Register out = locations->Out().AsRegister<Register>(); |
| 3178 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3179 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3180 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3181 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3182 | |
| 3183 | int64_t magic; |
| 3184 | int shift; |
| 3185 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3186 | |
| 3187 | __ LoadImmediate(temp1, magic); |
| 3188 | __ smull(temp2, temp1, dividend, temp1); |
| 3189 | |
| 3190 | if (imm > 0 && magic < 0) { |
| 3191 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3192 | } else if (imm < 0 && magic > 0) { |
| 3193 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3194 | } |
| 3195 | |
| 3196 | if (shift != 0) { |
| 3197 | __ Asr(temp1, temp1, shift); |
| 3198 | } |
| 3199 | |
| 3200 | if (instruction->IsDiv()) { |
| 3201 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3202 | } else { |
| 3203 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3204 | // TODO: Strength reduction for mls. |
| 3205 | __ LoadImmediate(temp2, imm); |
| 3206 | __ mls(out, temp1, temp2, dividend); |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3211 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3212 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3213 | |
| 3214 | LocationSummary* locations = instruction->GetLocations(); |
| 3215 | Location second = locations->InAt(1); |
| 3216 | DCHECK(second.IsConstant()); |
| 3217 | |
| 3218 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3219 | if (imm == 0) { |
| 3220 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3221 | } else if (imm == 1 || imm == -1) { |
| 3222 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3223 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3224 | DivRemByPowerOfTwo(instruction); |
| 3225 | } else { |
| 3226 | DCHECK(imm <= -2 || imm >= 2); |
| 3227 | GenerateDivRemWithAnyConstant(instruction); |
| 3228 | } |
| 3229 | } |
| 3230 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3231 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3232 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3233 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3234 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3235 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3236 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3237 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3238 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3239 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3240 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3241 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3244 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3245 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3246 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3247 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3248 | if (div->InputAt(1)->IsConstant()) { |
| 3249 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3250 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3251 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3252 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3253 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3254 | // No temp register required. |
| 3255 | } else { |
| 3256 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3257 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3258 | locations->AddTemp(Location::RequiresRegister()); |
| 3259 | } |
| 3260 | } |
| 3261 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3262 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3263 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3264 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3265 | } else { |
| 3266 | InvokeRuntimeCallingConvention calling_convention; |
| 3267 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3268 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3269 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3270 | // we only need the former. |
| 3271 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3272 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3273 | break; |
| 3274 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3275 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3276 | InvokeRuntimeCallingConvention calling_convention; |
| 3277 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3278 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3279 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3280 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3281 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3282 | break; |
| 3283 | } |
| 3284 | case Primitive::kPrimFloat: |
| 3285 | case Primitive::kPrimDouble: { |
| 3286 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3287 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3288 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3289 | break; |
| 3290 | } |
| 3291 | |
| 3292 | default: |
| 3293 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3298 | LocationSummary* locations = div->GetLocations(); |
| 3299 | Location out = locations->Out(); |
| 3300 | Location first = locations->InAt(0); |
| 3301 | Location second = locations->InAt(1); |
| 3302 | |
| 3303 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3304 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3305 | if (second.IsConstant()) { |
| 3306 | GenerateDivRemConstantIntegral(div); |
| 3307 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3308 | __ sdiv(out.AsRegister<Register>(), |
| 3309 | first.AsRegister<Register>(), |
| 3310 | second.AsRegister<Register>()); |
| 3311 | } else { |
| 3312 | InvokeRuntimeCallingConvention calling_convention; |
| 3313 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3314 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3315 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3316 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3317 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3318 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3319 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3320 | break; |
| 3321 | } |
| 3322 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3323 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3324 | InvokeRuntimeCallingConvention calling_convention; |
| 3325 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3326 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3327 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3328 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3329 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3330 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3331 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3332 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3333 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3334 | break; |
| 3335 | } |
| 3336 | |
| 3337 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3338 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3339 | first.AsFpuRegister<SRegister>(), |
| 3340 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3341 | break; |
| 3342 | } |
| 3343 | |
| 3344 | case Primitive::kPrimDouble: { |
| 3345 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3346 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3347 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3348 | break; |
| 3349 | } |
| 3350 | |
| 3351 | default: |
| 3352 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3353 | } |
| 3354 | } |
| 3355 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3356 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3357 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3358 | |
| 3359 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3360 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3361 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3362 | // sdiv will be replaced by other instruction sequence. |
| 3363 | call_kind = LocationSummary::kNoCall; |
| 3364 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3365 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3366 | // Have hardware divide instruction for int, do it with three instructions. |
| 3367 | call_kind = LocationSummary::kNoCall; |
| 3368 | } |
| 3369 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3370 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3371 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3372 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3373 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3374 | if (rem->InputAt(1)->IsConstant()) { |
| 3375 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3376 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3378 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3379 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3380 | // No temp register required. |
| 3381 | } else { |
| 3382 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3383 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3384 | locations->AddTemp(Location::RequiresRegister()); |
| 3385 | } |
| 3386 | } |
| 3387 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3388 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3389 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3391 | locations->AddTemp(Location::RequiresRegister()); |
| 3392 | } else { |
| 3393 | InvokeRuntimeCallingConvention calling_convention; |
| 3394 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3395 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3396 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3397 | // we only need the latter. |
| 3398 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3399 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3400 | break; |
| 3401 | } |
| 3402 | case Primitive::kPrimLong: { |
| 3403 | InvokeRuntimeCallingConvention calling_convention; |
| 3404 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3405 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3406 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3407 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3408 | // The runtime helper puts the output in R2,R3. |
| 3409 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3410 | break; |
| 3411 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3412 | case Primitive::kPrimFloat: { |
| 3413 | InvokeRuntimeCallingConvention calling_convention; |
| 3414 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3415 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3416 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3417 | break; |
| 3418 | } |
| 3419 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3420 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3421 | InvokeRuntimeCallingConvention calling_convention; |
| 3422 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3423 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3424 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3425 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3426 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3427 | break; |
| 3428 | } |
| 3429 | |
| 3430 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3431 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3436 | LocationSummary* locations = rem->GetLocations(); |
| 3437 | Location out = locations->Out(); |
| 3438 | Location first = locations->InAt(0); |
| 3439 | Location second = locations->InAt(1); |
| 3440 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3441 | Primitive::Type type = rem->GetResultType(); |
| 3442 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3443 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3444 | if (second.IsConstant()) { |
| 3445 | GenerateDivRemConstantIntegral(rem); |
| 3446 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3447 | Register reg1 = first.AsRegister<Register>(); |
| 3448 | Register reg2 = second.AsRegister<Register>(); |
| 3449 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3450 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3451 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3452 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3453 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3454 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3455 | } else { |
| 3456 | InvokeRuntimeCallingConvention calling_convention; |
| 3457 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3458 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3459 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3460 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3461 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3462 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3463 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3464 | break; |
| 3465 | } |
| 3466 | |
| 3467 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3468 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3469 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3470 | break; |
| 3471 | } |
| 3472 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3473 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3474 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3475 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3476 | break; |
| 3477 | } |
| 3478 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3479 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3480 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3481 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3482 | break; |
| 3483 | } |
| 3484 | |
| 3485 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3486 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3487 | } |
| 3488 | } |
| 3489 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3490 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3491 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3492 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3496 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3497 | codegen_->AddSlowPath(slow_path); |
| 3498 | |
| 3499 | LocationSummary* locations = instruction->GetLocations(); |
| 3500 | Location value = locations->InAt(0); |
| 3501 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3502 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3503 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3504 | case Primitive::kPrimByte: |
| 3505 | case Primitive::kPrimChar: |
| 3506 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3507 | case Primitive::kPrimInt: { |
| 3508 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3509 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3510 | } else { |
| 3511 | DCHECK(value.IsConstant()) << value; |
| 3512 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3513 | __ b(slow_path->GetEntryLabel()); |
| 3514 | } |
| 3515 | } |
| 3516 | break; |
| 3517 | } |
| 3518 | case Primitive::kPrimLong: { |
| 3519 | if (value.IsRegisterPair()) { |
| 3520 | __ orrs(IP, |
| 3521 | value.AsRegisterPairLow<Register>(), |
| 3522 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3523 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3524 | } else { |
| 3525 | DCHECK(value.IsConstant()) << value; |
| 3526 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3527 | __ b(slow_path->GetEntryLabel()); |
| 3528 | } |
| 3529 | } |
| 3530 | break; |
| 3531 | default: |
| 3532 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3533 | } |
| 3534 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3537 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3538 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3539 | Location rhs = locations->InAt(1); |
| 3540 | Register out = locations->Out().AsRegister<Register>(); |
| 3541 | |
| 3542 | if (rhs.IsConstant()) { |
| 3543 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3544 | // so map all rotations to a +ve. equivalent in that range. |
| 3545 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3546 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3547 | if (rot) { |
| 3548 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3549 | // (e.g. left by 2 bits == right by 30.) |
| 3550 | __ Ror(out, in, rot); |
| 3551 | } else if (out != in) { |
| 3552 | __ Mov(out, in); |
| 3553 | } |
| 3554 | } else { |
| 3555 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3556 | } |
| 3557 | } |
| 3558 | |
| 3559 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3560 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3561 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3562 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3563 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3564 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3565 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3566 | Location rhs = locations->InAt(1); |
| 3567 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3568 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3569 | |
| 3570 | if (rhs.IsConstant()) { |
| 3571 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3572 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3573 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3574 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3575 | // logic below to a simple pair of binary orr. |
| 3576 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3577 | if (rot >= kArmBitsPerWord) { |
| 3578 | rot -= kArmBitsPerWord; |
| 3579 | std::swap(in_reg_hi, in_reg_lo); |
| 3580 | } |
| 3581 | // Rotate, or mov to out for zero or word size rotations. |
| 3582 | if (rot != 0u) { |
| 3583 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3584 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3585 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3586 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3587 | } else { |
| 3588 | __ Mov(out_reg_lo, in_reg_lo); |
| 3589 | __ Mov(out_reg_hi, in_reg_hi); |
| 3590 | } |
| 3591 | } else { |
| 3592 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3593 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3594 | Label end; |
| 3595 | Label shift_by_32_plus_shift_right; |
| 3596 | |
| 3597 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3598 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3599 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3600 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3601 | |
| 3602 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3603 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3604 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3605 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3606 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3607 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3608 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3609 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3610 | __ b(&end); |
| 3611 | |
| 3612 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3613 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3614 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3615 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3616 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3617 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3618 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3619 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3620 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3621 | |
| 3622 | __ Bind(&end); |
| 3623 | } |
| 3624 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3625 | |
| 3626 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3627 | LocationSummary* locations = |
| 3628 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3629 | switch (ror->GetResultType()) { |
| 3630 | case Primitive::kPrimInt: { |
| 3631 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3632 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3634 | break; |
| 3635 | } |
| 3636 | case Primitive::kPrimLong: { |
| 3637 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3638 | if (ror->InputAt(1)->IsConstant()) { |
| 3639 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3640 | } else { |
| 3641 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3642 | locations->AddTemp(Location::RequiresRegister()); |
| 3643 | locations->AddTemp(Location::RequiresRegister()); |
| 3644 | } |
| 3645 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3646 | break; |
| 3647 | } |
| 3648 | default: |
| 3649 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3650 | } |
| 3651 | } |
| 3652 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3653 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3654 | LocationSummary* locations = ror->GetLocations(); |
| 3655 | Primitive::Type type = ror->GetResultType(); |
| 3656 | switch (type) { |
| 3657 | case Primitive::kPrimInt: { |
| 3658 | HandleIntegerRotate(locations); |
| 3659 | break; |
| 3660 | } |
| 3661 | case Primitive::kPrimLong: { |
| 3662 | HandleLongRotate(locations); |
| 3663 | break; |
| 3664 | } |
| 3665 | default: |
| 3666 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3667 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3668 | } |
| 3669 | } |
| 3670 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3671 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3672 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3673 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3674 | LocationSummary* locations = |
| 3675 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3676 | |
| 3677 | switch (op->GetResultType()) { |
| 3678 | case Primitive::kPrimInt: { |
| 3679 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3680 | if (op->InputAt(1)->IsConstant()) { |
| 3681 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3682 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3683 | } else { |
| 3684 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3685 | // Make the output overlap, as it will be used to hold the masked |
| 3686 | // second input. |
| 3687 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3688 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | } |
| 3691 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3692 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3693 | if (op->InputAt(1)->IsConstant()) { |
| 3694 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3695 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3696 | // don't clash with high registers which the register allocator currently guarantees. |
| 3697 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3698 | } else { |
| 3699 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3700 | locations->AddTemp(Location::RequiresRegister()); |
| 3701 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3702 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3703 | break; |
| 3704 | } |
| 3705 | default: |
| 3706 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3711 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3712 | |
| 3713 | LocationSummary* locations = op->GetLocations(); |
| 3714 | Location out = locations->Out(); |
| 3715 | Location first = locations->InAt(0); |
| 3716 | Location second = locations->InAt(1); |
| 3717 | |
| 3718 | Primitive::Type type = op->GetResultType(); |
| 3719 | switch (type) { |
| 3720 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3721 | Register out_reg = out.AsRegister<Register>(); |
| 3722 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3723 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3724 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3725 | // 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] | 3726 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3727 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3728 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3729 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3730 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3731 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3732 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3733 | } |
| 3734 | } else { |
| 3735 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3736 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3737 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3738 | __ Mov(out_reg, first_reg); |
| 3739 | } else if (op->IsShl()) { |
| 3740 | __ Lsl(out_reg, first_reg, shift_value); |
| 3741 | } else if (op->IsShr()) { |
| 3742 | __ Asr(out_reg, first_reg, shift_value); |
| 3743 | } else { |
| 3744 | __ Lsr(out_reg, first_reg, shift_value); |
| 3745 | } |
| 3746 | } |
| 3747 | break; |
| 3748 | } |
| 3749 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3750 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3751 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3752 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3753 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3754 | Register low = first.AsRegisterPairLow<Register>(); |
| 3755 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3756 | if (second.IsRegister()) { |
| 3757 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3758 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3759 | Register second_reg = second.AsRegister<Register>(); |
| 3760 | |
| 3761 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3762 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3763 | // Shift the high part |
| 3764 | __ Lsl(o_h, high, o_l); |
| 3765 | // Shift the low part and `or` what overflew on the high part |
| 3766 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3767 | __ Lsr(temp, low, temp); |
| 3768 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3769 | // If the shift is > 32 bits, override the high part |
| 3770 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3771 | __ it(PL); |
| 3772 | __ Lsl(o_h, low, temp, PL); |
| 3773 | // Shift the low part |
| 3774 | __ Lsl(o_l, low, o_l); |
| 3775 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3776 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3777 | // Shift the low part |
| 3778 | __ Lsr(o_l, low, o_h); |
| 3779 | // Shift the high part and `or` what underflew on the low part |
| 3780 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3781 | __ Lsl(temp, high, temp); |
| 3782 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3783 | // If the shift is > 32 bits, override the low part |
| 3784 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3785 | __ it(PL); |
| 3786 | __ Asr(o_l, high, temp, PL); |
| 3787 | // Shift the high part |
| 3788 | __ Asr(o_h, high, o_h); |
| 3789 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3790 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3791 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3792 | __ Lsr(o_l, low, o_h); |
| 3793 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3794 | __ Lsl(temp, high, temp); |
| 3795 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3796 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3797 | __ it(PL); |
| 3798 | __ Lsr(o_l, high, temp, PL); |
| 3799 | __ Lsr(o_h, high, o_h); |
| 3800 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3801 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3802 | // Register allocator doesn't create partial overlap. |
| 3803 | DCHECK_NE(o_l, high); |
| 3804 | DCHECK_NE(o_h, low); |
| 3805 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3806 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3807 | if (shift_value > 32) { |
| 3808 | if (op->IsShl()) { |
| 3809 | __ Lsl(o_h, low, shift_value - 32); |
| 3810 | __ LoadImmediate(o_l, 0); |
| 3811 | } else if (op->IsShr()) { |
| 3812 | __ Asr(o_l, high, shift_value - 32); |
| 3813 | __ Asr(o_h, high, 31); |
| 3814 | } else { |
| 3815 | __ Lsr(o_l, high, shift_value - 32); |
| 3816 | __ LoadImmediate(o_h, 0); |
| 3817 | } |
| 3818 | } else if (shift_value == 32) { |
| 3819 | if (op->IsShl()) { |
| 3820 | __ mov(o_h, ShifterOperand(low)); |
| 3821 | __ LoadImmediate(o_l, 0); |
| 3822 | } else if (op->IsShr()) { |
| 3823 | __ mov(o_l, ShifterOperand(high)); |
| 3824 | __ Asr(o_h, high, 31); |
| 3825 | } else { |
| 3826 | __ mov(o_l, ShifterOperand(high)); |
| 3827 | __ LoadImmediate(o_h, 0); |
| 3828 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3829 | } else if (shift_value == 1) { |
| 3830 | if (op->IsShl()) { |
| 3831 | __ Lsls(o_l, low, 1); |
| 3832 | __ adc(o_h, high, ShifterOperand(high)); |
| 3833 | } else if (op->IsShr()) { |
| 3834 | __ Asrs(o_h, high, 1); |
| 3835 | __ Rrx(o_l, low); |
| 3836 | } else { |
| 3837 | __ Lsrs(o_h, high, 1); |
| 3838 | __ Rrx(o_l, low); |
| 3839 | } |
| 3840 | } else { |
| 3841 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3842 | if (op->IsShl()) { |
| 3843 | __ Lsl(o_h, high, shift_value); |
| 3844 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3845 | __ Lsl(o_l, low, shift_value); |
| 3846 | } else if (op->IsShr()) { |
| 3847 | __ Lsr(o_l, low, shift_value); |
| 3848 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3849 | __ Asr(o_h, high, shift_value); |
| 3850 | } else { |
| 3851 | __ Lsr(o_l, low, shift_value); |
| 3852 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3853 | __ Lsr(o_h, high, shift_value); |
| 3854 | } |
| 3855 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3856 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3857 | break; |
| 3858 | } |
| 3859 | default: |
| 3860 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3861 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3866 | HandleShift(shl); |
| 3867 | } |
| 3868 | |
| 3869 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3870 | HandleShift(shl); |
| 3871 | } |
| 3872 | |
| 3873 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3874 | HandleShift(shr); |
| 3875 | } |
| 3876 | |
| 3877 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3878 | HandleShift(shr); |
| 3879 | } |
| 3880 | |
| 3881 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3882 | HandleShift(ushr); |
| 3883 | } |
| 3884 | |
| 3885 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3886 | HandleShift(ushr); |
| 3887 | } |
| 3888 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3889 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3890 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3891 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3892 | if (instruction->IsStringAlloc()) { |
| 3893 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3894 | } else { |
| 3895 | InvokeRuntimeCallingConvention calling_convention; |
| 3896 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3897 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3898 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3899 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3903 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3904 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3905 | if (instruction->IsStringAlloc()) { |
| 3906 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3907 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3908 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3909 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3910 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3911 | __ blx(LR); |
| 3912 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3913 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3914 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3915 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3916 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3917 | } |
| 3918 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3919 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3920 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3921 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3922 | InvokeRuntimeCallingConvention calling_convention; |
| 3923 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3924 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3925 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3926 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3930 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3931 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3932 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3933 | // of poisoning the reference. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3934 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3935 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3936 | } |
| 3937 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3938 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3939 | LocationSummary* locations = |
| 3940 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3941 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3942 | if (location.IsStackSlot()) { |
| 3943 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3944 | } else if (location.IsDoubleStackSlot()) { |
| 3945 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3946 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3947 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3948 | } |
| 3949 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3950 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3951 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3952 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3956 | LocationSummary* locations = |
| 3957 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3958 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3959 | } |
| 3960 | |
| 3961 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3962 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3963 | } |
| 3964 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3965 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3966 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3967 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3969 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3970 | } |
| 3971 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3972 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3973 | LocationSummary* locations = not_->GetLocations(); |
| 3974 | Location out = locations->Out(); |
| 3975 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3976 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3977 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3978 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3979 | break; |
| 3980 | |
| 3981 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3982 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3983 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3984 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3985 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3986 | break; |
| 3987 | |
| 3988 | default: |
| 3989 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3990 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3991 | } |
| 3992 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3993 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3994 | LocationSummary* locations = |
| 3995 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3996 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3997 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3998 | } |
| 3999 | |
| 4000 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4001 | LocationSummary* locations = bool_not->GetLocations(); |
| 4002 | Location out = locations->Out(); |
| 4003 | Location in = locations->InAt(0); |
| 4004 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4005 | } |
| 4006 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4007 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4008 | LocationSummary* locations = |
| 4009 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4010 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4011 | case Primitive::kPrimBoolean: |
| 4012 | case Primitive::kPrimByte: |
| 4013 | case Primitive::kPrimShort: |
| 4014 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4015 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4016 | case Primitive::kPrimLong: { |
| 4017 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4018 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4019 | // Output overlaps because it is written before doing the low comparison. |
| 4020 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4021 | break; |
| 4022 | } |
| 4023 | case Primitive::kPrimFloat: |
| 4024 | case Primitive::kPrimDouble: { |
| 4025 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4026 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4027 | locations->SetOut(Location::RequiresRegister()); |
| 4028 | break; |
| 4029 | } |
| 4030 | default: |
| 4031 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4032 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4036 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4037 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4038 | Location left = locations->InAt(0); |
| 4039 | Location right = locations->InAt(1); |
| 4040 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4041 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4042 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4043 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4044 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4045 | case Primitive::kPrimBoolean: |
| 4046 | case Primitive::kPrimByte: |
| 4047 | case Primitive::kPrimShort: |
| 4048 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4049 | case Primitive::kPrimInt: { |
| 4050 | __ LoadImmediate(out, 0); |
| 4051 | __ cmp(left.AsRegister<Register>(), |
| 4052 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4053 | less_cond = LT; |
| 4054 | break; |
| 4055 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4056 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4057 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4058 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4059 | __ b(&less, LT); |
| 4060 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4061 | // 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] | 4062 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4063 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4064 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4065 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4066 | break; |
| 4067 | } |
| 4068 | case Primitive::kPrimFloat: |
| 4069 | case Primitive::kPrimDouble: { |
| 4070 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4071 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4072 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4073 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4074 | break; |
| 4075 | } |
| 4076 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4077 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4078 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4079 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4080 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4081 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4082 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4083 | |
| 4084 | __ Bind(&greater); |
| 4085 | __ LoadImmediate(out, 1); |
| 4086 | __ b(&done); |
| 4087 | |
| 4088 | __ Bind(&less); |
| 4089 | __ LoadImmediate(out, -1); |
| 4090 | |
| 4091 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4092 | } |
| 4093 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4094 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4095 | LocationSummary* locations = |
| 4096 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4097 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4098 | locations->SetInAt(i, Location::Any()); |
| 4099 | } |
| 4100 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4103 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4104 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4105 | } |
| 4106 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4107 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4108 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4109 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4110 | switch (kind) { |
| 4111 | case MemBarrierKind::kAnyStore: |
| 4112 | case MemBarrierKind::kLoadAny: |
| 4113 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4114 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4115 | break; |
| 4116 | } |
| 4117 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4118 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4119 | break; |
| 4120 | } |
| 4121 | default: |
| 4122 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4123 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4124 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4128 | uint32_t offset, |
| 4129 | Register out_lo, |
| 4130 | Register out_hi) { |
| 4131 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4132 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4133 | // `offset` into `out_lo` does not clutter `addr`. |
| 4134 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4135 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4136 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4137 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4138 | } |
| 4139 | __ ldrexd(out_lo, out_hi, addr); |
| 4140 | } |
| 4141 | |
| 4142 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4143 | uint32_t offset, |
| 4144 | Register value_lo, |
| 4145 | Register value_hi, |
| 4146 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4147 | Register temp2, |
| 4148 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4149 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4150 | if (offset != 0) { |
| 4151 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4152 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4153 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4154 | } |
| 4155 | __ Bind(&fail); |
| 4156 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4157 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4158 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4159 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4160 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4161 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4165 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4166 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4167 | LocationSummary* locations = |
| 4168 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4169 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4170 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4171 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4172 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4173 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4174 | } else { |
| 4175 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4176 | } |
| 4177 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4178 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4179 | bool generate_volatile = field_info.IsVolatile() |
| 4180 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4181 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4182 | bool needs_write_barrier = |
| 4183 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4184 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4185 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4186 | if (needs_write_barrier) { |
| 4187 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4188 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4189 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4190 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4191 | // - registers need to be consecutive |
| 4192 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4193 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4194 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4195 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4196 | |
| 4197 | locations->AddTemp(Location::RequiresRegister()); |
| 4198 | locations->AddTemp(Location::RequiresRegister()); |
| 4199 | if (field_type == Primitive::kPrimDouble) { |
| 4200 | // For doubles we need two more registers to copy the value. |
| 4201 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4202 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4203 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4204 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4205 | } |
| 4206 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4207 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4208 | const FieldInfo& field_info, |
| 4209 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4210 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4211 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4212 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4213 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4214 | Location value = locations->InAt(1); |
| 4215 | |
| 4216 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4217 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4218 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4219 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4220 | bool needs_write_barrier = |
| 4221 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4222 | |
| 4223 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4224 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4225 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4226 | |
| 4227 | switch (field_type) { |
| 4228 | case Primitive::kPrimBoolean: |
| 4229 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4230 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | |
| 4234 | case Primitive::kPrimShort: |
| 4235 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4236 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4237 | break; |
| 4238 | } |
| 4239 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4240 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4241 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4242 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4243 | // Note that in the case where `value` is a null reference, |
| 4244 | // we do not enter this block, as a null reference does not |
| 4245 | // need poisoning. |
| 4246 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4247 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4248 | __ Mov(temp, value.AsRegister<Register>()); |
| 4249 | __ PoisonHeapReference(temp); |
| 4250 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4251 | } else { |
| 4252 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4253 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4254 | break; |
| 4255 | } |
| 4256 | |
| 4257 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4258 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4259 | GenerateWideAtomicStore(base, offset, |
| 4260 | value.AsRegisterPairLow<Register>(), |
| 4261 | value.AsRegisterPairHigh<Register>(), |
| 4262 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4263 | locations->GetTemp(1).AsRegister<Register>(), |
| 4264 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4265 | } else { |
| 4266 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4267 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4268 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4269 | break; |
| 4270 | } |
| 4271 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4272 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4273 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4274 | break; |
| 4275 | } |
| 4276 | |
| 4277 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4278 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4279 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4280 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4281 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4282 | |
| 4283 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4284 | |
| 4285 | GenerateWideAtomicStore(base, offset, |
| 4286 | value_reg_lo, |
| 4287 | value_reg_hi, |
| 4288 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4289 | locations->GetTemp(3).AsRegister<Register>(), |
| 4290 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4291 | } else { |
| 4292 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4294 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4295 | break; |
| 4296 | } |
| 4297 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4298 | case Primitive::kPrimVoid: |
| 4299 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4300 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4301 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4302 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4303 | // Longs and doubles are handled in the switch. |
| 4304 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4306 | } |
| 4307 | |
| 4308 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4309 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4310 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4311 | codegen_->MarkGCCard( |
| 4312 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4315 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4316 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4317 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4318 | } |
| 4319 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4320 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4321 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4322 | |
| 4323 | bool object_field_get_with_read_barrier = |
| 4324 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4325 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4326 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4327 | object_field_get_with_read_barrier ? |
| 4328 | LocationSummary::kCallOnSlowPath : |
| 4329 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4330 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4331 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4332 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4333 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4334 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4335 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4336 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4337 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4338 | // The output overlaps in case of volatile long: we don't want the |
| 4339 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4340 | // object's location. Likewise, in the case of an object field get |
| 4341 | // with read barriers enabled, we do not want the load to overwrite |
| 4342 | // the object's location, as we need it to emit the read barrier. |
| 4343 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4344 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4345 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4346 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4347 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4348 | } else { |
| 4349 | locations->SetOut(Location::RequiresRegister(), |
| 4350 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4351 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4352 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4353 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4354 | // - registers need to be consecutive |
| 4355 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4356 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4357 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4358 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4359 | locations->AddTemp(Location::RequiresRegister()); |
| 4360 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4361 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4362 | // We need a temporary register for the read barrier marking slow |
| 4363 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4364 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4365 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4366 | } |
| 4367 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4368 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4369 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4370 | << input->GetType(); |
| 4371 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4372 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4373 | return Location::ConstantLocation(input->AsConstant()); |
| 4374 | } else { |
| 4375 | return Location::RequiresFpuRegister(); |
| 4376 | } |
| 4377 | } |
| 4378 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4379 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4380 | Opcode opcode) { |
| 4381 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4382 | if (constant->IsConstant() && |
| 4383 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4384 | return Location::ConstantLocation(constant->AsConstant()); |
| 4385 | } |
| 4386 | return Location::RequiresRegister(); |
| 4387 | } |
| 4388 | |
| 4389 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4390 | Opcode opcode) { |
| 4391 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4392 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4393 | Opcode high_opcode = opcode; |
| 4394 | SetCc low_set_cc = kCcDontCare; |
| 4395 | switch (opcode) { |
| 4396 | case SUB: |
| 4397 | // Flip the operation to an ADD. |
| 4398 | value = -value; |
| 4399 | opcode = ADD; |
| 4400 | FALLTHROUGH_INTENDED; |
| 4401 | case ADD: |
| 4402 | if (Low32Bits(value) == 0u) { |
| 4403 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4404 | } |
| 4405 | high_opcode = ADC; |
| 4406 | low_set_cc = kCcSet; |
| 4407 | break; |
| 4408 | default: |
| 4409 | break; |
| 4410 | } |
| 4411 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4412 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4413 | } else { |
| 4414 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4415 | } |
| 4416 | } |
| 4417 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4418 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4419 | Opcode opcode, |
| 4420 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4421 | ShifterOperand so; |
| 4422 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4423 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4424 | return true; |
| 4425 | } |
| 4426 | Opcode neg_opcode = kNoOperand; |
| 4427 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4428 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4429 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4430 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4431 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4432 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4433 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4434 | default: |
| 4435 | return false; |
| 4436 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4437 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4440 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4441 | const FieldInfo& field_info) { |
| 4442 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4443 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4444 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4445 | Location base_loc = locations->InAt(0); |
| 4446 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4447 | Location out = locations->Out(); |
| 4448 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4449 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4450 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4451 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4452 | |
| 4453 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4454 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4455 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4456 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4457 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4458 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4459 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4461 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4462 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4463 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4464 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4465 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4466 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4467 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4468 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4469 | |
| 4470 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4471 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4472 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4473 | |
| 4474 | case Primitive::kPrimNot: { |
| 4475 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4476 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4477 | Location temp_loc = locations->GetTemp(0); |
| 4478 | // Note that a potential implicit null check is handled in this |
| 4479 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4480 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4481 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4482 | if (is_volatile) { |
| 4483 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4484 | } |
| 4485 | } else { |
| 4486 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4487 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4488 | if (is_volatile) { |
| 4489 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4490 | } |
| 4491 | // If read barriers are enabled, emit read barriers other than |
| 4492 | // Baker's using a slow path (and also unpoison the loaded |
| 4493 | // reference, if heap poisoning is enabled). |
| 4494 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4495 | } |
| 4496 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4497 | } |
| 4498 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4499 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4500 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4501 | GenerateWideAtomicLoad(base, offset, |
| 4502 | out.AsRegisterPairLow<Register>(), |
| 4503 | out.AsRegisterPairHigh<Register>()); |
| 4504 | } else { |
| 4505 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4506 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4507 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4508 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4509 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4510 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4511 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4512 | |
| 4513 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4514 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4515 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4516 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4517 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4518 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4519 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4520 | __ vmovdrr(out_reg, lo, hi); |
| 4521 | } else { |
| 4522 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4523 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4524 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4525 | break; |
| 4526 | } |
| 4527 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4528 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4529 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4530 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4531 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4533 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4534 | // Potential implicit null checks, in the case of reference or |
| 4535 | // double fields, are handled in the previous switch statement. |
| 4536 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4537 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4538 | } |
| 4539 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4541 | if (field_type == Primitive::kPrimNot) { |
| 4542 | // Memory barriers, in the case of references, are also handled |
| 4543 | // in the previous switch statement. |
| 4544 | } else { |
| 4545 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4546 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4547 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4551 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4552 | } |
| 4553 | |
| 4554 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4555 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4559 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4560 | } |
| 4561 | |
| 4562 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4563 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4564 | } |
| 4565 | |
| 4566 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4567 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4568 | } |
| 4569 | |
| 4570 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4571 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4572 | } |
| 4573 | |
| 4574 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4575 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4576 | } |
| 4577 | |
| 4578 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4579 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4580 | } |
| 4581 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4582 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4583 | HUnresolvedInstanceFieldGet* instruction) { |
| 4584 | FieldAccessCallingConventionARM calling_convention; |
| 4585 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4586 | instruction, instruction->GetFieldType(), calling_convention); |
| 4587 | } |
| 4588 | |
| 4589 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4590 | HUnresolvedInstanceFieldGet* instruction) { |
| 4591 | FieldAccessCallingConventionARM calling_convention; |
| 4592 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4593 | instruction->GetFieldType(), |
| 4594 | instruction->GetFieldIndex(), |
| 4595 | instruction->GetDexPc(), |
| 4596 | calling_convention); |
| 4597 | } |
| 4598 | |
| 4599 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4600 | HUnresolvedInstanceFieldSet* instruction) { |
| 4601 | FieldAccessCallingConventionARM calling_convention; |
| 4602 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4603 | instruction, instruction->GetFieldType(), calling_convention); |
| 4604 | } |
| 4605 | |
| 4606 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4607 | HUnresolvedInstanceFieldSet* instruction) { |
| 4608 | FieldAccessCallingConventionARM calling_convention; |
| 4609 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4610 | instruction->GetFieldType(), |
| 4611 | instruction->GetFieldIndex(), |
| 4612 | instruction->GetDexPc(), |
| 4613 | calling_convention); |
| 4614 | } |
| 4615 | |
| 4616 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4617 | HUnresolvedStaticFieldGet* instruction) { |
| 4618 | FieldAccessCallingConventionARM calling_convention; |
| 4619 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4620 | instruction, instruction->GetFieldType(), calling_convention); |
| 4621 | } |
| 4622 | |
| 4623 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4624 | HUnresolvedStaticFieldGet* instruction) { |
| 4625 | FieldAccessCallingConventionARM calling_convention; |
| 4626 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4627 | instruction->GetFieldType(), |
| 4628 | instruction->GetFieldIndex(), |
| 4629 | instruction->GetDexPc(), |
| 4630 | calling_convention); |
| 4631 | } |
| 4632 | |
| 4633 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4634 | HUnresolvedStaticFieldSet* instruction) { |
| 4635 | FieldAccessCallingConventionARM calling_convention; |
| 4636 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4637 | instruction, instruction->GetFieldType(), calling_convention); |
| 4638 | } |
| 4639 | |
| 4640 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4641 | HUnresolvedStaticFieldSet* instruction) { |
| 4642 | FieldAccessCallingConventionARM calling_convention; |
| 4643 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4644 | instruction->GetFieldType(), |
| 4645 | instruction->GetFieldIndex(), |
| 4646 | instruction->GetDexPc(), |
| 4647 | calling_convention); |
| 4648 | } |
| 4649 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4650 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4651 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4652 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4653 | } |
| 4654 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4655 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4656 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4657 | return; |
| 4658 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4659 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4660 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4661 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4662 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4663 | } |
| 4664 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4665 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4666 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4667 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4668 | |
| 4669 | LocationSummary* locations = instruction->GetLocations(); |
| 4670 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4671 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4672 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4675 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4676 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4679 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4680 | switch (type) { |
| 4681 | case Primitive::kPrimNot: |
| 4682 | return kLoadWord; |
| 4683 | case Primitive::kPrimBoolean: |
| 4684 | return kLoadUnsignedByte; |
| 4685 | case Primitive::kPrimByte: |
| 4686 | return kLoadSignedByte; |
| 4687 | case Primitive::kPrimChar: |
| 4688 | return kLoadUnsignedHalfword; |
| 4689 | case Primitive::kPrimShort: |
| 4690 | return kLoadSignedHalfword; |
| 4691 | case Primitive::kPrimInt: |
| 4692 | return kLoadWord; |
| 4693 | case Primitive::kPrimLong: |
| 4694 | return kLoadWordPair; |
| 4695 | case Primitive::kPrimFloat: |
| 4696 | return kLoadSWord; |
| 4697 | case Primitive::kPrimDouble: |
| 4698 | return kLoadDWord; |
| 4699 | default: |
| 4700 | LOG(FATAL) << "Unreachable type " << type; |
| 4701 | UNREACHABLE(); |
| 4702 | } |
| 4703 | } |
| 4704 | |
| 4705 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4706 | switch (type) { |
| 4707 | case Primitive::kPrimNot: |
| 4708 | return kStoreWord; |
| 4709 | case Primitive::kPrimBoolean: |
| 4710 | case Primitive::kPrimByte: |
| 4711 | return kStoreByte; |
| 4712 | case Primitive::kPrimChar: |
| 4713 | case Primitive::kPrimShort: |
| 4714 | return kStoreHalfword; |
| 4715 | case Primitive::kPrimInt: |
| 4716 | return kStoreWord; |
| 4717 | case Primitive::kPrimLong: |
| 4718 | return kStoreWordPair; |
| 4719 | case Primitive::kPrimFloat: |
| 4720 | return kStoreSWord; |
| 4721 | case Primitive::kPrimDouble: |
| 4722 | return kStoreDWord; |
| 4723 | default: |
| 4724 | LOG(FATAL) << "Unreachable type " << type; |
| 4725 | UNREACHABLE(); |
| 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4730 | Location out_loc, |
| 4731 | Register base, |
| 4732 | Register reg_offset, |
| 4733 | Condition cond) { |
| 4734 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4735 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4736 | |
| 4737 | switch (type) { |
| 4738 | case Primitive::kPrimByte: |
| 4739 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4740 | break; |
| 4741 | case Primitive::kPrimBoolean: |
| 4742 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4743 | break; |
| 4744 | case Primitive::kPrimShort: |
| 4745 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4746 | break; |
| 4747 | case Primitive::kPrimChar: |
| 4748 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4749 | break; |
| 4750 | case Primitive::kPrimNot: |
| 4751 | case Primitive::kPrimInt: |
| 4752 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4753 | break; |
| 4754 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4755 | case Primitive::kPrimLong: |
| 4756 | case Primitive::kPrimFloat: |
| 4757 | case Primitive::kPrimDouble: |
| 4758 | default: |
| 4759 | LOG(FATAL) << "Unreachable type " << type; |
| 4760 | UNREACHABLE(); |
| 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4765 | Location loc, |
| 4766 | Register base, |
| 4767 | Register reg_offset, |
| 4768 | Condition cond) { |
| 4769 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4770 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4771 | |
| 4772 | switch (type) { |
| 4773 | case Primitive::kPrimByte: |
| 4774 | case Primitive::kPrimBoolean: |
| 4775 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4776 | break; |
| 4777 | case Primitive::kPrimShort: |
| 4778 | case Primitive::kPrimChar: |
| 4779 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4780 | break; |
| 4781 | case Primitive::kPrimNot: |
| 4782 | case Primitive::kPrimInt: |
| 4783 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4784 | break; |
| 4785 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4786 | case Primitive::kPrimLong: |
| 4787 | case Primitive::kPrimFloat: |
| 4788 | case Primitive::kPrimDouble: |
| 4789 | default: |
| 4790 | LOG(FATAL) << "Unreachable type " << type; |
| 4791 | UNREACHABLE(); |
| 4792 | } |
| 4793 | } |
| 4794 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4795 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4796 | bool object_array_get_with_read_barrier = |
| 4797 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4798 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4799 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4800 | object_array_get_with_read_barrier ? |
| 4801 | LocationSummary::kCallOnSlowPath : |
| 4802 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4803 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4804 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4805 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4807 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4808 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4809 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4810 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4811 | // The output overlaps in the case of an object array get with |
| 4812 | // read barriers enabled: we do not want the move to overwrite the |
| 4813 | // array's location, as we need it to emit the read barrier. |
| 4814 | locations->SetOut( |
| 4815 | Location::RequiresRegister(), |
| 4816 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4817 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4818 | // We need a temporary register for the read barrier marking slow |
| 4819 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4820 | // Also need for String compression feature. |
| 4821 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4822 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4823 | locations->AddTemp(Location::RequiresRegister()); |
| 4824 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4828 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4829 | Location obj_loc = locations->InAt(0); |
| 4830 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4831 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4832 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4833 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4834 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4835 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4836 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4837 | HInstruction* array_instr = instruction->GetArray(); |
| 4838 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4839 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4840 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4841 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4842 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4843 | case Primitive::kPrimBoolean: |
| 4844 | case Primitive::kPrimByte: |
| 4845 | case Primitive::kPrimShort: |
| 4846 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4847 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4848 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4849 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4850 | if (maybe_compressed_char_at) { |
| 4851 | Register length = IP; |
| 4852 | Label uncompressed_load, done; |
| 4853 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4854 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4855 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4856 | __ cmp(length, ShifterOperand(0)); |
| 4857 | __ b(&uncompressed_load, GE); |
| 4858 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4859 | out_loc.AsRegister<Register>(), |
| 4860 | obj, |
| 4861 | data_offset + const_index); |
| 4862 | __ b(&done); |
| 4863 | __ Bind(&uncompressed_load); |
| 4864 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4865 | out_loc.AsRegister<Register>(), |
| 4866 | obj, |
| 4867 | data_offset + (const_index << 1)); |
| 4868 | __ Bind(&done); |
| 4869 | } else { |
| 4870 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4871 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4872 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4873 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4874 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4875 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4876 | Register temp = IP; |
| 4877 | |
| 4878 | if (has_intermediate_address) { |
| 4879 | // We do not need to compute the intermediate address from the array: the |
| 4880 | // input instruction has done it already. See the comment in |
| 4881 | // `TryExtractArrayAccessAddress()`. |
| 4882 | if (kIsDebugBuild) { |
| 4883 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4884 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4885 | } |
| 4886 | temp = obj; |
| 4887 | } else { |
| 4888 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4889 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4890 | if (maybe_compressed_char_at) { |
| 4891 | Label uncompressed_load, done; |
| 4892 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4893 | Register length = locations->GetTemp(0).AsRegister<Register>(); |
| 4894 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4895 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4896 | __ cmp(length, ShifterOperand(0)); |
| 4897 | __ b(&uncompressed_load, GE); |
| 4898 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4899 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4900 | __ b(&done); |
| 4901 | __ Bind(&uncompressed_load); |
| 4902 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4903 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4904 | __ Bind(&done); |
| 4905 | } else { |
| 4906 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4907 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4908 | } |
| 4909 | break; |
| 4910 | } |
| 4911 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4912 | case Primitive::kPrimNot: { |
| 4913 | static_assert( |
| 4914 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4915 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4916 | // /* HeapReference<Object> */ out = |
| 4917 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4918 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4919 | Location temp = locations->GetTemp(0); |
| 4920 | // Note that a potential implicit null check is handled in this |
| 4921 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4922 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4923 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4924 | } else { |
| 4925 | Register out = out_loc.AsRegister<Register>(); |
| 4926 | if (index.IsConstant()) { |
| 4927 | size_t offset = |
| 4928 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4929 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4930 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4931 | // If read barriers are enabled, emit read barriers other than |
| 4932 | // Baker's using a slow path (and also unpoison the loaded |
| 4933 | // reference, if heap poisoning is enabled). |
| 4934 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4935 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4936 | Register temp = IP; |
| 4937 | |
| 4938 | if (has_intermediate_address) { |
| 4939 | // We do not need to compute the intermediate address from the array: the |
| 4940 | // input instruction has done it already. See the comment in |
| 4941 | // `TryExtractArrayAccessAddress()`. |
| 4942 | if (kIsDebugBuild) { |
| 4943 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4944 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4945 | } |
| 4946 | temp = obj; |
| 4947 | } else { |
| 4948 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4949 | } |
| 4950 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4951 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4952 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4953 | // If read barriers are enabled, emit read barriers other than |
| 4954 | // Baker's using a slow path (and also unpoison the loaded |
| 4955 | // reference, if heap poisoning is enabled). |
| 4956 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4957 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4958 | } |
| 4959 | } |
| 4960 | break; |
| 4961 | } |
| 4962 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4963 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4964 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4965 | size_t offset = |
| 4966 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4967 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4968 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4969 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4970 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4971 | } |
| 4972 | break; |
| 4973 | } |
| 4974 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4975 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4976 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4977 | if (index.IsConstant()) { |
| 4978 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4979 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4980 | } else { |
| 4981 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4982 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4983 | } |
| 4984 | break; |
| 4985 | } |
| 4986 | |
| 4987 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4988 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4989 | if (index.IsConstant()) { |
| 4990 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4991 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4992 | } else { |
| 4993 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4994 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4995 | } |
| 4996 | break; |
| 4997 | } |
| 4998 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4999 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5000 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5001 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5002 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5003 | |
| 5004 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5005 | // Potential implicit null checks, in the case of reference |
| 5006 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5007 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5008 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5009 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5013 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5014 | |
| 5015 | bool needs_write_barrier = |
| 5016 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5017 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5018 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5019 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5020 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5021 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5022 | LocationSummary::kCallOnSlowPath : |
| 5023 | LocationSummary::kNoCall); |
| 5024 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5025 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5026 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5027 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5028 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5030 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5031 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5032 | if (needs_write_barrier) { |
| 5033 | // Temporary registers for the write barrier. |
| 5034 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5035 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5036 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5040 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5041 | Location array_loc = locations->InAt(0); |
| 5042 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5043 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5044 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5045 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5046 | bool needs_write_barrier = |
| 5047 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5048 | uint32_t data_offset = |
| 5049 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5050 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5051 | HInstruction* array_instr = instruction->GetArray(); |
| 5052 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5053 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5054 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5055 | |
| 5056 | switch (value_type) { |
| 5057 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5058 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5059 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5060 | case Primitive::kPrimChar: |
| 5061 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5062 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5063 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5064 | uint32_t full_offset = |
| 5065 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5066 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5067 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5069 | Register temp = IP; |
| 5070 | |
| 5071 | if (has_intermediate_address) { |
| 5072 | // We do not need to compute the intermediate address from the array: the |
| 5073 | // input instruction has done it already. See the comment in |
| 5074 | // `TryExtractArrayAccessAddress()`. |
| 5075 | if (kIsDebugBuild) { |
| 5076 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5077 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5078 | } |
| 5079 | temp = array; |
| 5080 | } else { |
| 5081 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5082 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5083 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5084 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5085 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5086 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5087 | } |
| 5088 | break; |
| 5089 | } |
| 5090 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5091 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5092 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5093 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5094 | // See the comment in instruction_simplifier_shared.cc. |
| 5095 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5096 | |
| 5097 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5098 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5099 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5100 | size_t offset = |
| 5101 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5102 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5103 | } else { |
| 5104 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5105 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5106 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5107 | value_loc, |
| 5108 | IP, |
| 5109 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5110 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5111 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5112 | DCHECK(!needs_write_barrier); |
| 5113 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5114 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5115 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5116 | |
| 5117 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5118 | Location temp1_loc = locations->GetTemp(0); |
| 5119 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5120 | Location temp2_loc = locations->GetTemp(1); |
| 5121 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5122 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5123 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5124 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5125 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5126 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5127 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5128 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5129 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5130 | codegen_->AddSlowPath(slow_path); |
| 5131 | if (instruction->GetValueCanBeNull()) { |
| 5132 | Label non_zero; |
| 5133 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5134 | if (index.IsConstant()) { |
| 5135 | size_t offset = |
| 5136 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5137 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5138 | } else { |
| 5139 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5140 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5141 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5142 | value_loc, |
| 5143 | IP, |
| 5144 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5145 | } |
| 5146 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5147 | __ b(&done); |
| 5148 | __ Bind(&non_zero); |
| 5149 | } |
| 5150 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5151 | // Note that when read barriers are enabled, the type checks |
| 5152 | // are performed without read barriers. This is fine, even in |
| 5153 | // the case where a class object is in the from-space after |
| 5154 | // the flip, as a comparison involving such a type would not |
| 5155 | // produce a false positive; it may of course produce a false |
| 5156 | // negative, in which case we would take the ArraySet slow |
| 5157 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5158 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5159 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5160 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5161 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5162 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5163 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5164 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5165 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5166 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5167 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5168 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5169 | // nor `temp2`, as we are comparing two poisoned references. |
| 5170 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5171 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5172 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5173 | Label do_put; |
| 5174 | __ b(&do_put, EQ); |
| 5175 | // If heap poisoning is enabled, the `temp1` reference has |
| 5176 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5177 | __ MaybeUnpoisonHeapReference(temp1); |
| 5178 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5179 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5180 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5181 | // If heap poisoning is enabled, no need to unpoison |
| 5182 | // `temp1`, as we are comparing against null below. |
| 5183 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5184 | __ Bind(&do_put); |
| 5185 | } else { |
| 5186 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5187 | } |
| 5188 | } |
| 5189 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5190 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5191 | if (kPoisonHeapReferences) { |
| 5192 | // Note that in the case where `value` is a null reference, |
| 5193 | // we do not enter this block, as a null reference does not |
| 5194 | // need poisoning. |
| 5195 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5196 | __ Mov(temp1, value); |
| 5197 | __ PoisonHeapReference(temp1); |
| 5198 | source = temp1; |
| 5199 | } |
| 5200 | |
| 5201 | if (index.IsConstant()) { |
| 5202 | size_t offset = |
| 5203 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5204 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5205 | } else { |
| 5206 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5207 | |
| 5208 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5209 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5210 | Location::RegisterLocation(source), |
| 5211 | IP, |
| 5212 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5213 | } |
| 5214 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5215 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5216 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5217 | } |
| 5218 | |
| 5219 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5220 | |
| 5221 | if (done.IsLinked()) { |
| 5222 | __ Bind(&done); |
| 5223 | } |
| 5224 | |
| 5225 | if (slow_path != nullptr) { |
| 5226 | __ Bind(slow_path->GetExitLabel()); |
| 5227 | } |
| 5228 | |
| 5229 | break; |
| 5230 | } |
| 5231 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5232 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5233 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5234 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5235 | size_t offset = |
| 5236 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5237 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5238 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5239 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5240 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5241 | } |
| 5242 | break; |
| 5243 | } |
| 5244 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5245 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5246 | Location value = locations->InAt(2); |
| 5247 | DCHECK(value.IsFpuRegister()); |
| 5248 | if (index.IsConstant()) { |
| 5249 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5250 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5251 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5252 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5253 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5254 | } |
| 5255 | break; |
| 5256 | } |
| 5257 | |
| 5258 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5259 | Location value = locations->InAt(2); |
| 5260 | DCHECK(value.IsFpuRegisterPair()); |
| 5261 | if (index.IsConstant()) { |
| 5262 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5263 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5264 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5265 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5266 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5267 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5268 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5269 | break; |
| 5270 | } |
| 5271 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5272 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5273 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5274 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5275 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5276 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5277 | // Objects are handled in the switch. |
| 5278 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5279 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5280 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5284 | LocationSummary* locations = |
| 5285 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5286 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5291 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5292 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5293 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5294 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5295 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5296 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5297 | // Mask out compression flag from String's array length. |
| 5298 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5299 | __ bic(out, out, ShifterOperand(1u << 31)); |
| 5300 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5301 | } |
| 5302 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5303 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5304 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5305 | DCHECK(!kEmitCompilerReadBarrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5306 | LocationSummary* locations = |
| 5307 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5308 | |
| 5309 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5310 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5312 | } |
| 5313 | |
| 5314 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5315 | LocationSummary* locations = instruction->GetLocations(); |
| 5316 | Location out = locations->Out(); |
| 5317 | Location first = locations->InAt(0); |
| 5318 | Location second = locations->InAt(1); |
| 5319 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5320 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5321 | DCHECK(!kEmitCompilerReadBarrier); |
| 5322 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5323 | if (second.IsRegister()) { |
| 5324 | __ add(out.AsRegister<Register>(), |
| 5325 | first.AsRegister<Register>(), |
| 5326 | ShifterOperand(second.AsRegister<Register>())); |
| 5327 | } else { |
| 5328 | __ AddConstant(out.AsRegister<Register>(), |
| 5329 | first.AsRegister<Register>(), |
| 5330 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5331 | } |
| 5332 | } |
| 5333 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5334 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5335 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5336 | InvokeRuntimeCallingConvention calling_convention; |
| 5337 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5338 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5339 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5340 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5341 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5345 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5346 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5347 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5348 | codegen_->AddSlowPath(slow_path); |
| 5349 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5350 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5351 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5352 | |
| 5353 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5354 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5355 | } |
| 5356 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5357 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5358 | Register card, |
| 5359 | Register object, |
| 5360 | Register value, |
| 5361 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5362 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5363 | if (can_be_null) { |
| 5364 | __ CompareAndBranchIfZero(value, &is_null); |
| 5365 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5366 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5368 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5369 | if (can_be_null) { |
| 5370 | __ Bind(&is_null); |
| 5371 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5372 | } |
| 5373 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5374 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5375 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5379 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5380 | } |
| 5381 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5382 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5383 | LocationSummary* locations = |
| 5384 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5385 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5389 | HBasicBlock* block = instruction->GetBlock(); |
| 5390 | if (block->GetLoopInformation() != nullptr) { |
| 5391 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5392 | // The back edge will generate the suspend check. |
| 5393 | return; |
| 5394 | } |
| 5395 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5396 | // The goto will generate the suspend check. |
| 5397 | return; |
| 5398 | } |
| 5399 | GenerateSuspendCheck(instruction, nullptr); |
| 5400 | } |
| 5401 | |
| 5402 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5403 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5404 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5405 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5406 | if (slow_path == nullptr) { |
| 5407 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5408 | instruction->SetSlowPath(slow_path); |
| 5409 | codegen_->AddSlowPath(slow_path); |
| 5410 | if (successor != nullptr) { |
| 5411 | DCHECK(successor->IsLoopHeader()); |
| 5412 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5413 | } |
| 5414 | } else { |
| 5415 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5416 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5417 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5418 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5419 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5420 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5421 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5422 | __ Bind(slow_path->GetReturnLabel()); |
| 5423 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5424 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5425 | __ b(slow_path->GetEntryLabel()); |
| 5426 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5427 | } |
| 5428 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5429 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5430 | return codegen_->GetAssembler(); |
| 5431 | } |
| 5432 | |
| 5433 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5434 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5435 | Location source = move->GetSource(); |
| 5436 | Location destination = move->GetDestination(); |
| 5437 | |
| 5438 | if (source.IsRegister()) { |
| 5439 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5440 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5441 | } else if (destination.IsFpuRegister()) { |
| 5442 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5443 | } else { |
| 5444 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5445 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5446 | SP, destination.GetStackIndex()); |
| 5447 | } |
| 5448 | } else if (source.IsStackSlot()) { |
| 5449 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5450 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5451 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5452 | } else if (destination.IsFpuRegister()) { |
| 5453 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5454 | } else { |
| 5455 | DCHECK(destination.IsStackSlot()); |
| 5456 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5457 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5458 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5459 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5460 | if (destination.IsRegister()) { |
| 5461 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5462 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5463 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5464 | } else { |
| 5465 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5466 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5467 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5468 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5469 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5470 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5471 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5472 | } else if (destination.IsRegisterPair()) { |
| 5473 | DCHECK(ExpectedPairLayout(destination)); |
| 5474 | __ LoadFromOffset( |
| 5475 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5476 | } else { |
| 5477 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5478 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5479 | SP, |
| 5480 | source.GetStackIndex()); |
| 5481 | } |
| 5482 | } else if (source.IsRegisterPair()) { |
| 5483 | if (destination.IsRegisterPair()) { |
| 5484 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5485 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5486 | } else if (destination.IsFpuRegisterPair()) { |
| 5487 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5488 | source.AsRegisterPairLow<Register>(), |
| 5489 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5490 | } else { |
| 5491 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5492 | DCHECK(ExpectedPairLayout(source)); |
| 5493 | __ StoreToOffset( |
| 5494 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5495 | } |
| 5496 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5497 | if (destination.IsRegisterPair()) { |
| 5498 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5499 | destination.AsRegisterPairHigh<Register>(), |
| 5500 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5501 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5502 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5503 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5504 | } else { |
| 5505 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5506 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5507 | SP, |
| 5508 | destination.GetStackIndex()); |
| 5509 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5510 | } else { |
| 5511 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5512 | HConstant* constant = source.GetConstant(); |
| 5513 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5514 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5515 | if (destination.IsRegister()) { |
| 5516 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5517 | } else { |
| 5518 | DCHECK(destination.IsStackSlot()); |
| 5519 | __ LoadImmediate(IP, value); |
| 5520 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5521 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5522 | } else if (constant->IsLongConstant()) { |
| 5523 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5524 | if (destination.IsRegisterPair()) { |
| 5525 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5526 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5527 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5528 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5529 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5530 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5531 | __ LoadImmediate(IP, High32Bits(value)); |
| 5532 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5533 | } |
| 5534 | } else if (constant->IsDoubleConstant()) { |
| 5535 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5536 | if (destination.IsFpuRegisterPair()) { |
| 5537 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5538 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5539 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5540 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5541 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5542 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5543 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5544 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5545 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5546 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5547 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5548 | float value = constant->AsFloatConstant()->GetValue(); |
| 5549 | if (destination.IsFpuRegister()) { |
| 5550 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5551 | } else { |
| 5552 | DCHECK(destination.IsStackSlot()); |
| 5553 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5554 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5555 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5556 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5561 | __ Mov(IP, reg); |
| 5562 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5563 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5564 | } |
| 5565 | |
| 5566 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5567 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5568 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5569 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5570 | SP, mem1 + stack_offset); |
| 5571 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5572 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5573 | SP, mem2 + stack_offset); |
| 5574 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5575 | } |
| 5576 | |
| 5577 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5578 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5579 | Location source = move->GetSource(); |
| 5580 | Location destination = move->GetDestination(); |
| 5581 | |
| 5582 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5583 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5584 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5585 | __ Mov(IP, source.AsRegister<Register>()); |
| 5586 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5587 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5588 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5589 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5590 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5591 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5592 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5593 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5594 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5595 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5596 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5597 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5598 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5599 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5600 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5601 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5602 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5603 | destination.AsRegisterPairHigh<Register>(), |
| 5604 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5605 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5606 | Register low_reg = source.IsRegisterPair() |
| 5607 | ? source.AsRegisterPairLow<Register>() |
| 5608 | : destination.AsRegisterPairLow<Register>(); |
| 5609 | int mem = source.IsRegisterPair() |
| 5610 | ? destination.GetStackIndex() |
| 5611 | : source.GetStackIndex(); |
| 5612 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5613 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5614 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5615 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5616 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5617 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5618 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5619 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5620 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5621 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5622 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5623 | DRegister reg = source.IsFpuRegisterPair() |
| 5624 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5625 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5626 | int mem = source.IsFpuRegisterPair() |
| 5627 | ? destination.GetStackIndex() |
| 5628 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5629 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5630 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5631 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5632 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5633 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5634 | : destination.AsFpuRegister<SRegister>(); |
| 5635 | int mem = source.IsFpuRegister() |
| 5636 | ? destination.GetStackIndex() |
| 5637 | : source.GetStackIndex(); |
| 5638 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5639 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5640 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5641 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5642 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5643 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5644 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5645 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5646 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5651 | __ Push(static_cast<Register>(reg)); |
| 5652 | } |
| 5653 | |
| 5654 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5655 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5656 | } |
| 5657 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5658 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5659 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5660 | switch (desired_class_load_kind) { |
| 5661 | case HLoadClass::LoadKind::kReferrersClass: |
| 5662 | break; |
| 5663 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5664 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5665 | break; |
| 5666 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5667 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5668 | break; |
| 5669 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5670 | break; |
| 5671 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5672 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5673 | break; |
| 5674 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5675 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5676 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5677 | // is incompatible with it. |
| 5678 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5679 | // with irreducible loops. |
| 5680 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5681 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5682 | } |
| 5683 | break; |
| 5684 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5685 | break; |
| 5686 | } |
| 5687 | return desired_class_load_kind; |
| 5688 | } |
| 5689 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5690 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5691 | if (cls->NeedsAccessCheck()) { |
| 5692 | InvokeRuntimeCallingConvention calling_convention; |
| 5693 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5694 | cls, |
| 5695 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5696 | Location::RegisterLocation(R0), |
| 5697 | /* code_generator_supports_read_barrier */ true); |
| 5698 | return; |
| 5699 | } |
| 5700 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5701 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5702 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5703 | ? LocationSummary::kCallOnSlowPath |
| 5704 | : LocationSummary::kNoCall; |
| 5705 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5706 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5707 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5708 | } |
| 5709 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5710 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5711 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5712 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5713 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5714 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5715 | } |
| 5716 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5720 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5721 | if (cls->NeedsAccessCheck()) { |
| 5722 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5723 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5724 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5725 | return; |
| 5726 | } |
| 5727 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5728 | Location out_loc = locations->Out(); |
| 5729 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5730 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5731 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5732 | bool generate_null_check = false; |
| 5733 | switch (cls->GetLoadKind()) { |
| 5734 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5735 | DCHECK(!cls->CanCallRuntime()); |
| 5736 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5737 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5738 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5739 | GenerateGcRootFieldLoad(cls, |
| 5740 | out_loc, |
| 5741 | current_method, |
| 5742 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5743 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5744 | break; |
| 5745 | } |
| 5746 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5747 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5748 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5749 | cls->GetTypeIndex())); |
| 5750 | break; |
| 5751 | } |
| 5752 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5753 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5754 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5755 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5756 | __ BindTrackedLabel(&labels->movw_label); |
| 5757 | __ movw(out, /* placeholder */ 0u); |
| 5758 | __ BindTrackedLabel(&labels->movt_label); |
| 5759 | __ movt(out, /* placeholder */ 0u); |
| 5760 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5761 | __ add(out, out, ShifterOperand(PC)); |
| 5762 | break; |
| 5763 | } |
| 5764 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5765 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5766 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5767 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5768 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5769 | break; |
| 5770 | } |
| 5771 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5772 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5773 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5774 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5775 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5776 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5777 | // and the remaining offset embedded in the load. |
| 5778 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5779 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5780 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5781 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5782 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5783 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5784 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5785 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5786 | generate_null_check = !cls->IsInDexCache(); |
| 5787 | break; |
| 5788 | } |
| 5789 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5790 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5791 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5792 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5793 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5794 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5795 | generate_null_check = !cls->IsInDexCache(); |
| 5796 | break; |
| 5797 | } |
| 5798 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5799 | // /* GcRoot<mirror::Class>[] */ out = |
| 5800 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5801 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5802 | __ LoadFromOffset(kLoadWord, |
| 5803 | out, |
| 5804 | current_method, |
| 5805 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5806 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5807 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5808 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5809 | generate_null_check = !cls->IsInDexCache(); |
| 5810 | } |
| 5811 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5812 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5813 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5814 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5815 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5816 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5817 | codegen_->AddSlowPath(slow_path); |
| 5818 | if (generate_null_check) { |
| 5819 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5820 | } |
| 5821 | if (cls->MustGenerateClinitCheck()) { |
| 5822 | GenerateClassInitializationCheck(slow_path, out); |
| 5823 | } else { |
| 5824 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5825 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5826 | } |
| 5827 | } |
| 5828 | |
| 5829 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5830 | LocationSummary* locations = |
| 5831 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5832 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5833 | if (check->HasUses()) { |
| 5834 | locations->SetOut(Location::SameAsFirstInput()); |
| 5835 | } |
| 5836 | } |
| 5837 | |
| 5838 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5839 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5840 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5841 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5842 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5843 | GenerateClassInitializationCheck(slow_path, |
| 5844 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5845 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5846 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5847 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5848 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5849 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5850 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5851 | __ b(slow_path->GetEntryLabel(), LT); |
| 5852 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5853 | // properly. Therefore, we do a memory fence. |
| 5854 | __ dmb(ISH); |
| 5855 | __ Bind(slow_path->GetExitLabel()); |
| 5856 | } |
| 5857 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5858 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5859 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5860 | switch (desired_string_load_kind) { |
| 5861 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5862 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5863 | break; |
| 5864 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5865 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5866 | break; |
| 5867 | case HLoadString::LoadKind::kBootImageAddress: |
| 5868 | break; |
| 5869 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5870 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5871 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5872 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5873 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5874 | break; |
| 5875 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5876 | break; |
| 5877 | } |
| 5878 | return desired_string_load_kind; |
| 5879 | } |
| 5880 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5881 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5882 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5883 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5884 | ? LocationSummary::kCallOnMainOnly |
| 5885 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5886 | : LocationSummary::kNoCall; |
| 5887 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5888 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5889 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5890 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5891 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5892 | } else { |
| 5893 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5894 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5895 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5896 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 5897 | // Note that IP may theoretically be clobbered by saving/restoring the live register |
| 5898 | // (only one thanks to the custom calling convention), so we request a different temp. |
| 5899 | locations->AddTemp(Location::RequiresRegister()); |
| 5900 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5901 | InvokeRuntimeCallingConvention calling_convention; |
| 5902 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5903 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5904 | // that the the kPrimNot result register is the same as the first argument register. |
| 5905 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5906 | } else { |
| 5907 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5908 | } |
| 5909 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5910 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5914 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5915 | Location out_loc = locations->Out(); |
| 5916 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5917 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5918 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5919 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5920 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5921 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5922 | load->GetStringIndex())); |
| 5923 | return; // No dex cache slow path. |
| 5924 | } |
| 5925 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5926 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5927 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5928 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5929 | __ BindTrackedLabel(&labels->movw_label); |
| 5930 | __ movw(out, /* placeholder */ 0u); |
| 5931 | __ BindTrackedLabel(&labels->movt_label); |
| 5932 | __ movt(out, /* placeholder */ 0u); |
| 5933 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5934 | __ add(out, out, ShifterOperand(PC)); |
| 5935 | return; // No dex cache slow path. |
| 5936 | } |
| 5937 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5938 | DCHECK_NE(load->GetAddress(), 0u); |
| 5939 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5940 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5941 | return; // No dex cache slow path. |
| 5942 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5943 | case HLoadString::LoadKind::kBssEntry: { |
| 5944 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5945 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5946 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5947 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5948 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5949 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5950 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5951 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5952 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5953 | __ add(temp, temp, ShifterOperand(PC)); |
| 5954 | GenerateGcRootFieldLoad(load, out_loc, temp, 0); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5955 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5956 | codegen_->AddSlowPath(slow_path); |
| 5957 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5958 | __ Bind(slow_path->GetExitLabel()); |
| 5959 | return; |
| 5960 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5961 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5962 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5963 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5964 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5965 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 5966 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5967 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5968 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5969 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex()); |
| 5970 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5971 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5972 | } |
| 5973 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5974 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5975 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5976 | } |
| 5977 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5978 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5979 | LocationSummary* locations = |
| 5980 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5981 | locations->SetOut(Location::RequiresRegister()); |
| 5982 | } |
| 5983 | |
| 5984 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5985 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5986 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5987 | } |
| 5988 | |
| 5989 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5990 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5991 | } |
| 5992 | |
| 5993 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5994 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5995 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5996 | } |
| 5997 | |
| 5998 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5999 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6000 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6001 | InvokeRuntimeCallingConvention calling_convention; |
| 6002 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6003 | } |
| 6004 | |
| 6005 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6006 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6007 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6008 | } |
| 6009 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6010 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6011 | return kEmitCompilerReadBarrier && |
| 6012 | (kUseBakerReadBarrier || |
| 6013 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6014 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6015 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6016 | } |
| 6017 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6018 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6019 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6020 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6021 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6022 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6023 | case TypeCheckKind::kExactCheck: |
| 6024 | case TypeCheckKind::kAbstractClassCheck: |
| 6025 | case TypeCheckKind::kClassHierarchyCheck: |
| 6026 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6027 | call_kind = |
| 6028 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6029 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6030 | break; |
| 6031 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6032 | case TypeCheckKind::kUnresolvedCheck: |
| 6033 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6034 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6035 | break; |
| 6036 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6037 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6038 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6039 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6040 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6041 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6042 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6043 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6044 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6045 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6046 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 6047 | // When read barriers are enabled, we need a temporary register for |
| 6048 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6049 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6050 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6051 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6052 | } |
| 6053 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6054 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6055 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6056 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6057 | Location obj_loc = locations->InAt(0); |
| 6058 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6059 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6060 | Location out_loc = locations->Out(); |
| 6061 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6062 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6063 | locations->GetTemp(0) : |
| 6064 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6065 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6066 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6067 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6068 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6069 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6070 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6071 | |
| 6072 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6073 | // avoid null check if we know obj is not null. |
| 6074 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6075 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6076 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6077 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6078 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6079 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6080 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6081 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6082 | case TypeCheckKind::kExactCheck: { |
| 6083 | __ cmp(out, ShifterOperand(cls)); |
| 6084 | // Classes must be equal for the instanceof to succeed. |
| 6085 | __ b(&zero, NE); |
| 6086 | __ LoadImmediate(out, 1); |
| 6087 | __ b(&done); |
| 6088 | break; |
| 6089 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6090 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6091 | case TypeCheckKind::kAbstractClassCheck: { |
| 6092 | // If the class is abstract, we eagerly fetch the super class of the |
| 6093 | // object to avoid doing a comparison we know will fail. |
| 6094 | Label loop; |
| 6095 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6096 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6097 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6098 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6099 | __ CompareAndBranchIfZero(out, &done); |
| 6100 | __ cmp(out, ShifterOperand(cls)); |
| 6101 | __ b(&loop, NE); |
| 6102 | __ LoadImmediate(out, 1); |
| 6103 | if (zero.IsLinked()) { |
| 6104 | __ b(&done); |
| 6105 | } |
| 6106 | break; |
| 6107 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6108 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6110 | // Walk over the class hierarchy to find a match. |
| 6111 | Label loop, success; |
| 6112 | __ Bind(&loop); |
| 6113 | __ cmp(out, ShifterOperand(cls)); |
| 6114 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6115 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6116 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6117 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6118 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6119 | __ b(&done); |
| 6120 | __ Bind(&success); |
| 6121 | __ LoadImmediate(out, 1); |
| 6122 | if (zero.IsLinked()) { |
| 6123 | __ b(&done); |
| 6124 | } |
| 6125 | break; |
| 6126 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6127 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6128 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6129 | // Do an exact check. |
| 6130 | Label exact_check; |
| 6131 | __ cmp(out, ShifterOperand(cls)); |
| 6132 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6133 | // 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] | 6134 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6135 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6136 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6137 | __ CompareAndBranchIfZero(out, &done); |
| 6138 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6139 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6140 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6141 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6142 | __ LoadImmediate(out, 1); |
| 6143 | __ b(&done); |
| 6144 | break; |
| 6145 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6146 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6147 | case TypeCheckKind::kArrayCheck: { |
| 6148 | __ cmp(out, ShifterOperand(cls)); |
| 6149 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6150 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6151 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6152 | codegen_->AddSlowPath(slow_path); |
| 6153 | __ b(slow_path->GetEntryLabel(), NE); |
| 6154 | __ LoadImmediate(out, 1); |
| 6155 | if (zero.IsLinked()) { |
| 6156 | __ b(&done); |
| 6157 | } |
| 6158 | break; |
| 6159 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6160 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6161 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6162 | case TypeCheckKind::kInterfaceCheck: { |
| 6163 | // 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] | 6164 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6165 | // cases. |
| 6166 | // |
| 6167 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6168 | // entry point without resorting to a type checking slow path |
| 6169 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6170 | // require to assign fixed registers for the inputs of this |
| 6171 | // HInstanceOf instruction (following the runtime calling |
| 6172 | // convention), which might be cluttered by the potential first |
| 6173 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6174 | // |
| 6175 | // TODO: Introduce a new runtime entry point taking the object |
| 6176 | // to test (instead of its class) as argument, and let it deal |
| 6177 | // with the read barrier issues. This will let us refactor this |
| 6178 | // case of the `switch` code as it was previously (with a direct |
| 6179 | // call to the runtime not using a type checking slow path). |
| 6180 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6181 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6182 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6183 | /* is_fatal */ false); |
| 6184 | codegen_->AddSlowPath(slow_path); |
| 6185 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6186 | if (zero.IsLinked()) { |
| 6187 | __ b(&done); |
| 6188 | } |
| 6189 | break; |
| 6190 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6191 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6192 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6193 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6194 | __ Bind(&zero); |
| 6195 | __ LoadImmediate(out, 0); |
| 6196 | } |
| 6197 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6198 | if (done.IsLinked()) { |
| 6199 | __ Bind(&done); |
| 6200 | } |
| 6201 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6202 | if (slow_path != nullptr) { |
| 6203 | __ Bind(slow_path->GetExitLabel()); |
| 6204 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6207 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6208 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6209 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6210 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6211 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6212 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6213 | case TypeCheckKind::kExactCheck: |
| 6214 | case TypeCheckKind::kAbstractClassCheck: |
| 6215 | case TypeCheckKind::kClassHierarchyCheck: |
| 6216 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6217 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6218 | LocationSummary::kCallOnSlowPath : |
| 6219 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6220 | break; |
| 6221 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6222 | case TypeCheckKind::kUnresolvedCheck: |
| 6223 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6224 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6225 | break; |
| 6226 | } |
| 6227 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6228 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6230 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6231 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 6232 | locations->AddTemp(Location::RequiresRegister()); |
| 6233 | // When read barriers are enabled, we need an additional temporary |
| 6234 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6235 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6236 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6237 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6241 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6242 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6243 | Location obj_loc = locations->InAt(0); |
| 6244 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6245 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6246 | Location temp_loc = locations->GetTemp(0); |
| 6247 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6248 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6249 | locations->GetTemp(1) : |
| 6250 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6251 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6252 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6253 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6254 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6255 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6256 | bool is_type_check_slow_path_fatal = |
| 6257 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6258 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6259 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6260 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6261 | !instruction->CanThrowIntoCatchBlock(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6262 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6263 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6264 | is_type_check_slow_path_fatal); |
| 6265 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6266 | |
| 6267 | Label done; |
| 6268 | // Avoid null check if we know obj is not null. |
| 6269 | if (instruction->MustDoNullCheck()) { |
| 6270 | __ CompareAndBranchIfZero(obj, &done); |
| 6271 | } |
| 6272 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6273 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6274 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6275 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6276 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6277 | case TypeCheckKind::kExactCheck: |
| 6278 | case TypeCheckKind::kArrayCheck: { |
| 6279 | __ cmp(temp, ShifterOperand(cls)); |
| 6280 | // Jump to slow path for throwing the exception or doing a |
| 6281 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6282 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6283 | break; |
| 6284 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6285 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6286 | case TypeCheckKind::kAbstractClassCheck: { |
| 6287 | // If the class is abstract, we eagerly fetch the super class of the |
| 6288 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6289 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6290 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6291 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6292 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6293 | |
| 6294 | // If the class reference currently in `temp` is not null, jump |
| 6295 | // to the `compare_classes` label to compare it with the checked |
| 6296 | // class. |
| 6297 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 6298 | // Otherwise, jump to the slow path to throw the exception. |
| 6299 | // |
| 6300 | // But before, move back the object's class into `temp` before |
| 6301 | // going into the slow path, as it has been overwritten in the |
| 6302 | // meantime. |
| 6303 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6304 | GenerateReferenceLoadTwoRegisters( |
| 6305 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6306 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6307 | |
| 6308 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6309 | __ cmp(temp, ShifterOperand(cls)); |
| 6310 | __ b(&loop, NE); |
| 6311 | break; |
| 6312 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6313 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6314 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6315 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6316 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6317 | __ Bind(&loop); |
| 6318 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6319 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6320 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6321 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6322 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6323 | |
| 6324 | // If the class reference currently in `temp` is not null, jump |
| 6325 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6326 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6327 | // Otherwise, jump to the slow path to throw the exception. |
| 6328 | // |
| 6329 | // But before, move back the object's class into `temp` before |
| 6330 | // going into the slow path, as it has been overwritten in the |
| 6331 | // meantime. |
| 6332 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6333 | GenerateReferenceLoadTwoRegisters( |
| 6334 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6335 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6336 | break; |
| 6337 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6338 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6339 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6340 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6341 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6342 | __ cmp(temp, ShifterOperand(cls)); |
| 6343 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6344 | |
| 6345 | // 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] | 6346 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6347 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6348 | |
| 6349 | // If the component type is not null (i.e. the object is indeed |
| 6350 | // an array), jump to label `check_non_primitive_component_type` |
| 6351 | // to further check that this component type is not a primitive |
| 6352 | // type. |
| 6353 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 6354 | // Otherwise, jump to the slow path to throw the exception. |
| 6355 | // |
| 6356 | // But before, move back the object's class into `temp` before |
| 6357 | // going into the slow path, as it has been overwritten in the |
| 6358 | // meantime. |
| 6359 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6360 | GenerateReferenceLoadTwoRegisters( |
| 6361 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6362 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6363 | |
| 6364 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6366 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 6367 | __ CompareAndBranchIfZero(temp, &done); |
| 6368 | // Same comment as above regarding `temp` and the slow path. |
| 6369 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6370 | GenerateReferenceLoadTwoRegisters( |
| 6371 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6372 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6373 | break; |
| 6374 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6375 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6376 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6377 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6378 | // We always go into the type check slow path for the unresolved |
| 6379 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6380 | // |
| 6381 | // We cannot directly call the CheckCast runtime entry point |
| 6382 | // without resorting to a type checking slow path here (i.e. by |
| 6383 | // calling InvokeRuntime directly), as it would require to |
| 6384 | // assign fixed registers for the inputs of this HInstanceOf |
| 6385 | // instruction (following the runtime calling convention), which |
| 6386 | // might be cluttered by the potential first read barrier |
| 6387 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6388 | // |
| 6389 | // TODO: Introduce a new runtime entry point taking the object |
| 6390 | // to test (instead of its class) as argument, and let it deal |
| 6391 | // with the read barrier issues. This will let us refactor this |
| 6392 | // case of the `switch` code as it was previously (with a direct |
| 6393 | // call to the runtime not using a type checking slow path). |
| 6394 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6395 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6396 | break; |
| 6397 | } |
| 6398 | __ Bind(&done); |
| 6399 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6400 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6401 | } |
| 6402 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6403 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6404 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6405 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6406 | InvokeRuntimeCallingConvention calling_convention; |
| 6407 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6408 | } |
| 6409 | |
| 6410 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6411 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6412 | instruction, |
| 6413 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6414 | if (instruction->IsEnter()) { |
| 6415 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6416 | } else { |
| 6417 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6418 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6419 | } |
| 6420 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6421 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6422 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6423 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6424 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6425 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6426 | LocationSummary* locations = |
| 6427 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6428 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6429 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6430 | // 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] | 6431 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6432 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6433 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6434 | } |
| 6435 | |
| 6436 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6437 | HandleBitwiseOperation(instruction); |
| 6438 | } |
| 6439 | |
| 6440 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6441 | HandleBitwiseOperation(instruction); |
| 6442 | } |
| 6443 | |
| 6444 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6445 | HandleBitwiseOperation(instruction); |
| 6446 | } |
| 6447 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6448 | |
| 6449 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6450 | LocationSummary* locations = |
| 6451 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6452 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6453 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6454 | |
| 6455 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6456 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6457 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6458 | } |
| 6459 | |
| 6460 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6461 | LocationSummary* locations = instruction->GetLocations(); |
| 6462 | Location first = locations->InAt(0); |
| 6463 | Location second = locations->InAt(1); |
| 6464 | Location out = locations->Out(); |
| 6465 | |
| 6466 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6467 | Register first_reg = first.AsRegister<Register>(); |
| 6468 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6469 | Register out_reg = out.AsRegister<Register>(); |
| 6470 | |
| 6471 | switch (instruction->GetOpKind()) { |
| 6472 | case HInstruction::kAnd: |
| 6473 | __ bic(out_reg, first_reg, second_reg); |
| 6474 | break; |
| 6475 | case HInstruction::kOr: |
| 6476 | __ orn(out_reg, first_reg, second_reg); |
| 6477 | break; |
| 6478 | // There is no EON on arm. |
| 6479 | case HInstruction::kXor: |
| 6480 | default: |
| 6481 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6482 | UNREACHABLE(); |
| 6483 | } |
| 6484 | return; |
| 6485 | |
| 6486 | } else { |
| 6487 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6488 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6489 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6490 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6491 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6492 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6493 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6494 | |
| 6495 | switch (instruction->GetOpKind()) { |
| 6496 | case HInstruction::kAnd: |
| 6497 | __ bic(out_low, first_low, second_low); |
| 6498 | __ bic(out_high, first_high, second_high); |
| 6499 | break; |
| 6500 | case HInstruction::kOr: |
| 6501 | __ orn(out_low, first_low, second_low); |
| 6502 | __ orn(out_high, first_high, second_high); |
| 6503 | break; |
| 6504 | // There is no EON on arm. |
| 6505 | case HInstruction::kXor: |
| 6506 | default: |
| 6507 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6508 | UNREACHABLE(); |
| 6509 | } |
| 6510 | } |
| 6511 | } |
| 6512 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6513 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6514 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6515 | if (value == 0xffffffffu) { |
| 6516 | if (out != first) { |
| 6517 | __ mov(out, ShifterOperand(first)); |
| 6518 | } |
| 6519 | return; |
| 6520 | } |
| 6521 | if (value == 0u) { |
| 6522 | __ mov(out, ShifterOperand(0)); |
| 6523 | return; |
| 6524 | } |
| 6525 | ShifterOperand so; |
| 6526 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6527 | __ and_(out, first, so); |
| 6528 | } else { |
| 6529 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6530 | __ bic(out, first, ShifterOperand(~value)); |
| 6531 | } |
| 6532 | } |
| 6533 | |
| 6534 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6535 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6536 | if (value == 0u) { |
| 6537 | if (out != first) { |
| 6538 | __ mov(out, ShifterOperand(first)); |
| 6539 | } |
| 6540 | return; |
| 6541 | } |
| 6542 | if (value == 0xffffffffu) { |
| 6543 | __ mvn(out, ShifterOperand(0)); |
| 6544 | return; |
| 6545 | } |
| 6546 | ShifterOperand so; |
| 6547 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6548 | __ orr(out, first, so); |
| 6549 | } else { |
| 6550 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6551 | __ orn(out, first, ShifterOperand(~value)); |
| 6552 | } |
| 6553 | } |
| 6554 | |
| 6555 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6556 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6557 | if (value == 0u) { |
| 6558 | if (out != first) { |
| 6559 | __ mov(out, ShifterOperand(first)); |
| 6560 | } |
| 6561 | return; |
| 6562 | } |
| 6563 | __ eor(out, first, ShifterOperand(value)); |
| 6564 | } |
| 6565 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6566 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6567 | Location first, |
| 6568 | uint64_t value) { |
| 6569 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6570 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6571 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6572 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6573 | uint32_t value_low = Low32Bits(value); |
| 6574 | uint32_t value_high = High32Bits(value); |
| 6575 | if (value_low == 0u) { |
| 6576 | if (out_low != first_low) { |
| 6577 | __ mov(out_low, ShifterOperand(first_low)); |
| 6578 | } |
| 6579 | __ AddConstant(out_high, first_high, value_high); |
| 6580 | return; |
| 6581 | } |
| 6582 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6583 | ShifterOperand so; |
| 6584 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6585 | __ adc(out_high, first_high, so); |
| 6586 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6587 | __ sbc(out_high, first_high, so); |
| 6588 | } else { |
| 6589 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6590 | UNREACHABLE(); |
| 6591 | } |
| 6592 | } |
| 6593 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6594 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6595 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6596 | Location first = locations->InAt(0); |
| 6597 | Location second = locations->InAt(1); |
| 6598 | Location out = locations->Out(); |
| 6599 | |
| 6600 | if (second.IsConstant()) { |
| 6601 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6602 | uint32_t value_low = Low32Bits(value); |
| 6603 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6604 | Register first_reg = first.AsRegister<Register>(); |
| 6605 | Register out_reg = out.AsRegister<Register>(); |
| 6606 | if (instruction->IsAnd()) { |
| 6607 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6608 | } else if (instruction->IsOr()) { |
| 6609 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6610 | } else { |
| 6611 | DCHECK(instruction->IsXor()); |
| 6612 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6613 | } |
| 6614 | } else { |
| 6615 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6616 | uint32_t value_high = High32Bits(value); |
| 6617 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6618 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6619 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6620 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6621 | if (instruction->IsAnd()) { |
| 6622 | GenerateAndConst(out_low, first_low, value_low); |
| 6623 | GenerateAndConst(out_high, first_high, value_high); |
| 6624 | } else if (instruction->IsOr()) { |
| 6625 | GenerateOrrConst(out_low, first_low, value_low); |
| 6626 | GenerateOrrConst(out_high, first_high, value_high); |
| 6627 | } else { |
| 6628 | DCHECK(instruction->IsXor()); |
| 6629 | GenerateEorConst(out_low, first_low, value_low); |
| 6630 | GenerateEorConst(out_high, first_high, value_high); |
| 6631 | } |
| 6632 | } |
| 6633 | return; |
| 6634 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6635 | |
| 6636 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6637 | Register first_reg = first.AsRegister<Register>(); |
| 6638 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6639 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6640 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6641 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6642 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6643 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6644 | } else { |
| 6645 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6646 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6647 | } |
| 6648 | } else { |
| 6649 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6650 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6651 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6652 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6653 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6654 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6655 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6656 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6657 | __ and_(out_low, first_low, second_low); |
| 6658 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6659 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6660 | __ orr(out_low, first_low, second_low); |
| 6661 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6662 | } else { |
| 6663 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6664 | __ eor(out_low, first_low, second_low); |
| 6665 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6666 | } |
| 6667 | } |
| 6668 | } |
| 6669 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6670 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6671 | Location out, |
| 6672 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6673 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6674 | Register out_reg = out.AsRegister<Register>(); |
| 6675 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6676 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6677 | if (kUseBakerReadBarrier) { |
| 6678 | // Load with fast path based Baker's read barrier. |
| 6679 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6680 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6681 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6682 | } else { |
| 6683 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6684 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6685 | // in the following move operation, as we will need it for the |
| 6686 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6687 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6688 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6689 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6690 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6691 | } |
| 6692 | } else { |
| 6693 | // Plain load with no read barrier. |
| 6694 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6695 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6696 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6701 | Location out, |
| 6702 | Location obj, |
| 6703 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6704 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6705 | Register out_reg = out.AsRegister<Register>(); |
| 6706 | Register obj_reg = obj.AsRegister<Register>(); |
| 6707 | if (kEmitCompilerReadBarrier) { |
| 6708 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6709 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6710 | // Load with fast path based Baker's read barrier. |
| 6711 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6712 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6713 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6714 | } else { |
| 6715 | // Load with slow path based read barrier. |
| 6716 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6717 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6718 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6719 | } |
| 6720 | } else { |
| 6721 | // Plain load with no read barrier. |
| 6722 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6723 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6724 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6729 | Location root, |
| 6730 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6731 | uint32_t offset, |
| 6732 | bool requires_read_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6733 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6734 | if (requires_read_barrier) { |
| 6735 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6736 | if (kUseBakerReadBarrier) { |
| 6737 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6738 | // Baker's read barrier are used: |
| 6739 | // |
| 6740 | // root = obj.field; |
| 6741 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6742 | // root = ReadBarrier::Mark(root) |
| 6743 | // } |
| 6744 | |
| 6745 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6746 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6747 | static_assert( |
| 6748 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6749 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6750 | "have different sizes."); |
| 6751 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6752 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6753 | "have different sizes."); |
| 6754 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6755 | // Slow path marking the GC root `root`. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6756 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6757 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6758 | codegen_->AddSlowPath(slow_path); |
| 6759 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6760 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6761 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6762 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6763 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6764 | __ Bind(slow_path->GetExitLabel()); |
| 6765 | } else { |
| 6766 | // GC root loaded through a slow path for read barriers other |
| 6767 | // than Baker's. |
| 6768 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6769 | __ AddConstant(root_reg, obj, offset); |
| 6770 | // /* mirror::Object* */ root = root->Read() |
| 6771 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6772 | } |
| 6773 | } else { |
| 6774 | // Plain GC root load with no read barrier. |
| 6775 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6776 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6777 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6778 | // do not have to unpoison `root_reg` here. |
| 6779 | } |
| 6780 | } |
| 6781 | |
| 6782 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6783 | Location ref, |
| 6784 | Register obj, |
| 6785 | uint32_t offset, |
| 6786 | Location temp, |
| 6787 | bool needs_null_check) { |
| 6788 | DCHECK(kEmitCompilerReadBarrier); |
| 6789 | DCHECK(kUseBakerReadBarrier); |
| 6790 | |
| 6791 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6792 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6793 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6794 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6795 | 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] | 6796 | } |
| 6797 | |
| 6798 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6799 | Location ref, |
| 6800 | Register obj, |
| 6801 | uint32_t data_offset, |
| 6802 | Location index, |
| 6803 | Location temp, |
| 6804 | bool needs_null_check) { |
| 6805 | DCHECK(kEmitCompilerReadBarrier); |
| 6806 | DCHECK(kUseBakerReadBarrier); |
| 6807 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6808 | static_assert( |
| 6809 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6810 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6811 | // /* HeapReference<Object> */ ref = |
| 6812 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6813 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6814 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6815 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6816 | } |
| 6817 | |
| 6818 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6819 | Location ref, |
| 6820 | Register obj, |
| 6821 | uint32_t offset, |
| 6822 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6823 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6824 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 6825 | bool needs_null_check, |
| 6826 | bool always_update_field, |
| 6827 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6828 | DCHECK(kEmitCompilerReadBarrier); |
| 6829 | DCHECK(kUseBakerReadBarrier); |
| 6830 | |
| 6831 | // In slow path based read barriers, the read barrier call is |
| 6832 | // inserted after the original load. However, in fast path based |
| 6833 | // Baker's read barriers, we need to perform the load of |
| 6834 | // mirror::Object::monitor_ *before* the original reference load. |
| 6835 | // This load-load ordering is required by the read barrier. |
| 6836 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6837 | // |
| 6838 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6839 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6840 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6841 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6842 | // if (is_gray) { |
| 6843 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6844 | // } |
| 6845 | // |
| 6846 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6847 | // slightly more complex as it performs additional checks that we do |
| 6848 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6849 | |
| 6850 | Register ref_reg = ref.AsRegister<Register>(); |
| 6851 | Register temp_reg = temp.AsRegister<Register>(); |
| 6852 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6853 | |
| 6854 | // /* int32_t */ monitor = obj->monitor_ |
| 6855 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6856 | if (needs_null_check) { |
| 6857 | MaybeRecordImplicitNullCheck(instruction); |
| 6858 | } |
| 6859 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6860 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6861 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6862 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6863 | // Introduce a dependency on the lock_word including the rb_state, |
| 6864 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6865 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 6866 | // `obj` is unchanged by this operation, but its value now depends |
| 6867 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6868 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6869 | |
| 6870 | // The actual reference load. |
| 6871 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 6872 | // Load types involving an "index": ArrayGet, |
| 6873 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6874 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6875 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6876 | if (index.IsConstant()) { |
| 6877 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6878 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6879 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6880 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6881 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 6882 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6883 | // intrinsics, which use a register pair as index ("long |
| 6884 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6885 | Register index_reg = index.IsRegisterPair() |
| 6886 | ? index.AsRegisterPairLow<Register>() |
| 6887 | : index.AsRegister<Register>(); |
| 6888 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6889 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6890 | } |
| 6891 | } else { |
| 6892 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6893 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6894 | } |
| 6895 | |
| 6896 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6897 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6898 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6899 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 6900 | SlowPathCodeARM* slow_path; |
| 6901 | if (always_update_field) { |
| 6902 | DCHECK(temp2 != nullptr); |
| 6903 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 6904 | // of the form `obj + field_offset`, where `obj` is a register and |
| 6905 | // `field_offset` is a register pair (of which only the lower half |
| 6906 | // is used). Thus `offset` and `scale_factor` above are expected |
| 6907 | // to be null in this code path. |
| 6908 | DCHECK_EQ(offset, 0u); |
| 6909 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 6910 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 6911 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 6912 | } else { |
| 6913 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 6914 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6915 | AddSlowPath(slow_path); |
| 6916 | |
| 6917 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6918 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6919 | // Given the numeric representation, it's enough to check the low bit of the |
| 6920 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6921 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6922 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6923 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6924 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6925 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6926 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6927 | __ Bind(slow_path->GetExitLabel()); |
| 6928 | } |
| 6929 | |
| 6930 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6931 | Location out, |
| 6932 | Location ref, |
| 6933 | Location obj, |
| 6934 | uint32_t offset, |
| 6935 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6936 | DCHECK(kEmitCompilerReadBarrier); |
| 6937 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6938 | // Insert a slow path based read barrier *after* the reference load. |
| 6939 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6940 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6941 | // reference will be carried out by the runtime within the slow |
| 6942 | // path. |
| 6943 | // |
| 6944 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6945 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6946 | // not used by the artReadBarrierSlow entry point. |
| 6947 | // |
| 6948 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6949 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6950 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6951 | AddSlowPath(slow_path); |
| 6952 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6953 | __ b(slow_path->GetEntryLabel()); |
| 6954 | __ Bind(slow_path->GetExitLabel()); |
| 6955 | } |
| 6956 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6957 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6958 | Location out, |
| 6959 | Location ref, |
| 6960 | Location obj, |
| 6961 | uint32_t offset, |
| 6962 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6963 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6964 | // Baker's read barriers shall be handled by the fast path |
| 6965 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6966 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6967 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6968 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6969 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6970 | } else if (kPoisonHeapReferences) { |
| 6971 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6972 | } |
| 6973 | } |
| 6974 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6975 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6976 | Location out, |
| 6977 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6978 | DCHECK(kEmitCompilerReadBarrier); |
| 6979 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6980 | // Insert a slow path based read barrier *after* the GC root load. |
| 6981 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6982 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6983 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6984 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6985 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6986 | AddSlowPath(slow_path); |
| 6987 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6988 | __ b(slow_path->GetEntryLabel()); |
| 6989 | __ Bind(slow_path->GetExitLabel()); |
| 6990 | } |
| 6991 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6992 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6993 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 6994 | HInvokeStaticOrDirect* invoke) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6995 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6996 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6997 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6998 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6999 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7000 | if (GetGraph()->HasIrreducibleLoops() && |
| 7001 | (dispatch_info.method_load_kind == |
| 7002 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 7003 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 7004 | } |
| 7005 | |
| 7006 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7007 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 7008 | if (&outer_dex_file != invoke->GetTargetMethod().dex_file) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7009 | // Calls across dex files are more likely to exceed the available BL range, |
| 7010 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 7011 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 7012 | (desired_dispatch_info.method_load_kind == |
| 7013 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 7014 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 7015 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 7016 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7017 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7018 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7019 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7020 | 0u |
| 7021 | }; |
| 7022 | } |
| 7023 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 7024 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7025 | } |
| 7026 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7027 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7028 | Register temp) { |
| 7029 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7030 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7031 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7032 | return location.AsRegister<Register>(); |
| 7033 | } |
| 7034 | // For intrinsics we allow any location, so it may be on the stack. |
| 7035 | if (!location.IsRegister()) { |
| 7036 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7037 | return temp; |
| 7038 | } |
| 7039 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7040 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7041 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7042 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7043 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7044 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7045 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 7046 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7047 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7048 | return temp; |
| 7049 | } |
| 7050 | return location.AsRegister<Register>(); |
| 7051 | } |
| 7052 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 7053 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7054 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7055 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7056 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 7057 | // LR = code address from literal pool with link-time patch. |
| 7058 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7059 | break; |
| 7060 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 7061 | // LR = invoke->GetDirectCodePtr(); |
| 7062 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7063 | break; |
| 7064 | default: |
| 7065 | break; |
| 7066 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7067 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7068 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7069 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7070 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7071 | uint32_t offset = |
| 7072 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7073 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7074 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7075 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7076 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7077 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7078 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7079 | break; |
| 7080 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7081 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7082 | break; |
| 7083 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 7084 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 7085 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 7086 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7087 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7088 | HArmDexCacheArraysBase* base = |
| 7089 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7090 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7091 | temp.AsRegister<Register>()); |
| 7092 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7093 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7094 | break; |
| 7095 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7096 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7097 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7098 | Register method_reg; |
| 7099 | Register reg = temp.AsRegister<Register>(); |
| 7100 | if (current_method.IsRegister()) { |
| 7101 | method_reg = current_method.AsRegister<Register>(); |
| 7102 | } else { |
| 7103 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7104 | DCHECK(!current_method.IsValid()); |
| 7105 | method_reg = reg; |
| 7106 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7107 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7108 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7109 | __ LoadFromOffset(kLoadWord, |
| 7110 | reg, |
| 7111 | method_reg, |
| 7112 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7113 | // temp = temp[index_in_cache]; |
| 7114 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7115 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7116 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7117 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7118 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7119 | } |
| 7120 | |
| 7121 | switch (invoke->GetCodePtrLocation()) { |
| 7122 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7123 | __ bl(GetFrameEntryLabel()); |
| 7124 | break; |
| 7125 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7126 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 7127 | invoke->GetTargetMethod().dex_method_index); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7128 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7129 | // Arbitrarily branch to the BL itself, override at link time. |
| 7130 | __ bl(&relative_call_patches_.back().label); |
| 7131 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7132 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 7133 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 7134 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7135 | // LR() |
| 7136 | __ blx(LR); |
| 7137 | break; |
| 7138 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7139 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7140 | __ LoadFromOffset( |
| 7141 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7142 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7143 | // LR() |
| 7144 | __ blx(LR); |
| 7145 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7146 | } |
| 7147 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7148 | DCHECK(!IsLeafMethod()); |
| 7149 | } |
| 7150 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7151 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7152 | Register temp = temp_location.AsRegister<Register>(); |
| 7153 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7154 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7155 | |
| 7156 | // Use the calling convention instead of the location of the receiver, as |
| 7157 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7158 | // slow path, the arguments have been moved to the right place, so here we are |
| 7159 | // guaranteed that the receiver is the first register of the calling convention. |
| 7160 | InvokeDexCallingConvention calling_convention; |
| 7161 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7162 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7163 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7164 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7165 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7166 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7167 | // emit a read barrier for the previous class reference load. |
| 7168 | // However this is not required in practice, as this is an |
| 7169 | // intermediate/temporary reference and because the current |
| 7170 | // concurrent copying collector keeps the from-space memory |
| 7171 | // intact/accessible until the end of the marking phase (the |
| 7172 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7173 | __ MaybeUnpoisonHeapReference(temp); |
| 7174 | // temp = temp->GetMethodAt(method_offset); |
| 7175 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7176 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7177 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7178 | // LR = temp->GetEntryPoint(); |
| 7179 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7180 | // LR(); |
| 7181 | __ blx(LR); |
| 7182 | } |
| 7183 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7184 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 7185 | const DexFile& dex_file, uint32_t string_index) { |
| 7186 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 7187 | } |
| 7188 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7189 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 7190 | const DexFile& dex_file, uint32_t type_index) { |
| 7191 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 7192 | } |
| 7193 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7194 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7195 | const DexFile& dex_file, uint32_t element_offset) { |
| 7196 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7197 | } |
| 7198 | |
| 7199 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7200 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7201 | patches->emplace_back(dex_file, offset_or_index); |
| 7202 | return &patches->back(); |
| 7203 | } |
| 7204 | |
| 7205 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 7206 | uint32_t string_index) { |
| 7207 | return boot_image_string_patches_.GetOrCreate( |
| 7208 | StringReference(&dex_file, string_index), |
| 7209 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7210 | } |
| 7211 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7212 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 7213 | uint32_t type_index) { |
| 7214 | return boot_image_type_patches_.GetOrCreate( |
| 7215 | TypeReference(&dex_file, type_index), |
| 7216 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7217 | } |
| 7218 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7219 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7220 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7221 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7222 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7223 | } |
| 7224 | |
| 7225 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 7226 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 7227 | } |
| 7228 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7229 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7230 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7231 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7232 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7233 | for (const PcRelativePatchInfo& info : infos) { |
| 7234 | const DexFile& dex_file = info.target_dex_file; |
| 7235 | size_t offset_or_index = info.offset_or_index; |
| 7236 | DCHECK(info.add_pc_label.IsBound()); |
| 7237 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7238 | // Add MOVW patch. |
| 7239 | DCHECK(info.movw_label.IsBound()); |
| 7240 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7241 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7242 | // Add MOVT patch. |
| 7243 | DCHECK(info.movt_label.IsBound()); |
| 7244 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7245 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7246 | } |
| 7247 | } |
| 7248 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7249 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7250 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7251 | size_t size = |
| 7252 | method_patches_.size() + |
| 7253 | call_patches_.size() + |
| 7254 | relative_call_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7255 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7256 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7257 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7258 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7259 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7260 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7261 | linker_patches->reserve(size); |
| 7262 | for (const auto& entry : method_patches_) { |
| 7263 | const MethodReference& target_method = entry.first; |
| 7264 | Literal* literal = entry.second; |
| 7265 | DCHECK(literal->GetLabel()->IsBound()); |
| 7266 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7267 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 7268 | target_method.dex_file, |
| 7269 | target_method.dex_method_index)); |
| 7270 | } |
| 7271 | for (const auto& entry : call_patches_) { |
| 7272 | const MethodReference& target_method = entry.first; |
| 7273 | Literal* literal = entry.second; |
| 7274 | DCHECK(literal->GetLabel()->IsBound()); |
| 7275 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7276 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 7277 | target_method.dex_file, |
| 7278 | target_method.dex_method_index)); |
| 7279 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7280 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7281 | uint32_t literal_offset = info.label.Position(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7282 | linker_patches->push_back( |
| 7283 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7284 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7285 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7286 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7287 | for (const auto& entry : boot_image_string_patches_) { |
| 7288 | const StringReference& target_string = entry.first; |
| 7289 | Literal* literal = entry.second; |
| 7290 | DCHECK(literal->GetLabel()->IsBound()); |
| 7291 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7292 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7293 | target_string.dex_file, |
| 7294 | target_string.string_index)); |
| 7295 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7296 | if (!GetCompilerOptions().IsBootImage()) { |
| 7297 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7298 | linker_patches); |
| 7299 | } else { |
| 7300 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7301 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7302 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7303 | for (const auto& entry : boot_image_type_patches_) { |
| 7304 | const TypeReference& target_type = entry.first; |
| 7305 | Literal* literal = entry.second; |
| 7306 | DCHECK(literal->GetLabel()->IsBound()); |
| 7307 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7308 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7309 | target_type.dex_file, |
| 7310 | target_type.type_index)); |
| 7311 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7312 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7313 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7314 | for (const auto& entry : boot_image_address_patches_) { |
| 7315 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7316 | Literal* literal = entry.second; |
| 7317 | DCHECK(literal->GetLabel()->IsBound()); |
| 7318 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7319 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7324 | return map->GetOrCreate( |
| 7325 | value, |
| 7326 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7327 | } |
| 7328 | |
| 7329 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7330 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7331 | return map->GetOrCreate( |
| 7332 | target_method, |
| 7333 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 7337 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 7338 | } |
| 7339 | |
| 7340 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 7341 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 7342 | } |
| 7343 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7344 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7345 | LocationSummary* locations = |
| 7346 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7347 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7348 | Location::RequiresRegister()); |
| 7349 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7350 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7351 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7352 | } |
| 7353 | |
| 7354 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7355 | LocationSummary* locations = instr->GetLocations(); |
| 7356 | Register res = locations->Out().AsRegister<Register>(); |
| 7357 | Register accumulator = |
| 7358 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7359 | Register mul_left = |
| 7360 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7361 | Register mul_right = |
| 7362 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7363 | |
| 7364 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7365 | __ mla(res, mul_left, mul_right, accumulator); |
| 7366 | } else { |
| 7367 | __ mls(res, mul_left, mul_right, accumulator); |
| 7368 | } |
| 7369 | } |
| 7370 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7371 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7372 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7373 | LOG(FATAL) << "Unreachable"; |
| 7374 | } |
| 7375 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7376 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7377 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7378 | LOG(FATAL) << "Unreachable"; |
| 7379 | } |
| 7380 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7381 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7382 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7383 | LocationSummary* locations = |
| 7384 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7385 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7386 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7387 | codegen_->GetAssembler()->IsThumb()) { |
| 7388 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7389 | if (switch_instr->GetStartValue() != 0) { |
| 7390 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7391 | } |
| 7392 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7393 | } |
| 7394 | |
| 7395 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7396 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7397 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7398 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7399 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7400 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7401 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7402 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7403 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7404 | Register temp_reg = IP; |
| 7405 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7406 | // the immediate, because IP is used as the destination register. For the other |
| 7407 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7408 | // and they can be encoded in the instruction without making use of IP register. |
| 7409 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7410 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7411 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7412 | // Jump to successors[0] if value == lower_bound. |
| 7413 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7414 | int32_t last_index = 0; |
| 7415 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7416 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7417 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7418 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7419 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7420 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7421 | } |
| 7422 | if (num_entries - last_index == 2) { |
| 7423 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7424 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7425 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7426 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7427 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7428 | // And the default for any other value. |
| 7429 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7430 | __ b(codegen_->GetLabelOf(default_block)); |
| 7431 | } |
| 7432 | } else { |
| 7433 | // Create a table lookup. |
| 7434 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7435 | |
| 7436 | // Materialize a pointer to the switch table |
| 7437 | std::vector<Label*> labels(num_entries); |
| 7438 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7439 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7440 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7441 | } |
| 7442 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7443 | |
| 7444 | // Remove the bias. |
| 7445 | Register key_reg; |
| 7446 | if (lower_bound != 0) { |
| 7447 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7448 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7449 | } else { |
| 7450 | key_reg = value_reg; |
| 7451 | } |
| 7452 | |
| 7453 | // Check whether the value is in the table, jump to default block if not. |
| 7454 | __ CmpConstant(key_reg, num_entries - 1); |
| 7455 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7456 | |
| 7457 | // Load the displacement from the table. |
| 7458 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7459 | |
| 7460 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7461 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7462 | } |
| 7463 | } |
| 7464 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7465 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7466 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7467 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7468 | } |
| 7469 | |
| 7470 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7471 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7472 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7473 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7474 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7475 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7476 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7477 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7478 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7479 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7480 | } |
| 7481 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7482 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7483 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7484 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7485 | return; |
| 7486 | } |
| 7487 | |
| 7488 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7489 | |
| 7490 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7491 | if (return_loc.Equals(trg)) { |
| 7492 | return; |
| 7493 | } |
| 7494 | |
| 7495 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7496 | // with the last branch. |
| 7497 | if (type == Primitive::kPrimLong) { |
| 7498 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7499 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7500 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7501 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7502 | } else if (type == Primitive::kPrimDouble) { |
| 7503 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7504 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7505 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7506 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7507 | } else { |
| 7508 | // Let the parallel move resolver take care of all of this. |
| 7509 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7510 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7511 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7512 | } |
| 7513 | } |
| 7514 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7515 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7516 | LocationSummary* locations = |
| 7517 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7518 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7519 | locations->SetOut(Location::RequiresRegister()); |
| 7520 | } |
| 7521 | |
| 7522 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7523 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7524 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7525 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7526 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7527 | __ LoadFromOffset(kLoadWord, |
| 7528 | locations->Out().AsRegister<Register>(), |
| 7529 | locations->InAt(0).AsRegister<Register>(), |
| 7530 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7531 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7532 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7533 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7534 | __ LoadFromOffset(kLoadWord, |
| 7535 | locations->Out().AsRegister<Register>(), |
| 7536 | locations->InAt(0).AsRegister<Register>(), |
| 7537 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7538 | __ LoadFromOffset(kLoadWord, |
| 7539 | locations->Out().AsRegister<Register>(), |
| 7540 | locations->Out().AsRegister<Register>(), |
| 7541 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7542 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7543 | } |
| 7544 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7545 | #undef __ |
| 7546 | #undef QUICK_ENTRY_POINT |
| 7547 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7548 | } // namespace arm |
| 7549 | } // namespace art |