Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 66 | static constexpr int kRegListThreshold = 4; |
| 67 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame^] | 68 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 69 | // for each live D registers they treat two corresponding S registers as live ones. |
| 70 | // |
| 71 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 72 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 73 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 74 | // - decreasing code size |
| 75 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 76 | // restored and then used in regular non SlowPath code as D register. |
| 77 | // |
| 78 | // For the following example (v means the S register is live): |
| 79 | // D names: | D0 | D1 | D2 | D4 | ... |
| 80 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 81 | // Live? | | v | v | v | v | v | v | | ... |
| 82 | // |
| 83 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 84 | // as D registers. |
| 85 | static size_t SaveContiguousSRegisterList(size_t first, |
| 86 | size_t last, |
| 87 | CodeGenerator* codegen, |
| 88 | size_t stack_offset) { |
| 89 | DCHECK_LE(first, last); |
| 90 | if ((first == last) && (first == 0)) { |
| 91 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 92 | return stack_offset; |
| 93 | } |
| 94 | if (first % 2 == 1) { |
| 95 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 96 | } |
| 97 | |
| 98 | bool save_last = false; |
| 99 | if (last % 2 == 0) { |
| 100 | save_last = true; |
| 101 | --last; |
| 102 | } |
| 103 | |
| 104 | if (first < last) { |
| 105 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 106 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 107 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 108 | |
| 109 | if (number_of_d_regs == 1) { |
| 110 | __ StoreDToOffset(d_reg, SP, stack_offset); |
| 111 | } else if (number_of_d_regs > 1) { |
| 112 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 113 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 114 | } |
| 115 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 116 | } |
| 117 | |
| 118 | if (save_last) { |
| 119 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 120 | } |
| 121 | |
| 122 | return stack_offset; |
| 123 | } |
| 124 | |
| 125 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 126 | size_t last, |
| 127 | CodeGenerator* codegen, |
| 128 | size_t stack_offset) { |
| 129 | DCHECK_LE(first, last); |
| 130 | if ((first == last) && (first == 0)) { |
| 131 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 132 | return stack_offset; |
| 133 | } |
| 134 | if (first % 2 == 1) { |
| 135 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 136 | } |
| 137 | |
| 138 | bool restore_last = false; |
| 139 | if (last % 2 == 0) { |
| 140 | restore_last = true; |
| 141 | --last; |
| 142 | } |
| 143 | |
| 144 | if (first < last) { |
| 145 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 146 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 147 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 148 | if (number_of_d_regs == 1) { |
| 149 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 150 | } else if (number_of_d_regs > 1) { |
| 151 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 152 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 153 | } |
| 154 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 155 | } |
| 156 | |
| 157 | if (restore_last) { |
| 158 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 159 | } |
| 160 | |
| 161 | return stack_offset; |
| 162 | } |
| 163 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 164 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 165 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 166 | size_t orig_offset = stack_offset; |
| 167 | |
| 168 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 169 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 170 | // If the register holds an object, update the stack mask. |
| 171 | if (locations->RegisterContainsObject(i)) { |
| 172 | locations->SetStackBit(stack_offset / kVRegSize); |
| 173 | } |
| 174 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 175 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 176 | saved_core_stack_offsets_[i] = stack_offset; |
| 177 | stack_offset += kArmWordSize; |
| 178 | } |
| 179 | |
| 180 | int reg_num = POPCOUNT(core_spills); |
| 181 | if (reg_num != 0) { |
| 182 | if (reg_num > kRegListThreshold) { |
| 183 | __ StoreList(RegList(core_spills), orig_offset); |
| 184 | } else { |
| 185 | stack_offset = orig_offset; |
| 186 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 187 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame^] | 192 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 193 | orig_offset = stack_offset; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 194 | for (size_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()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 278 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 279 | // Live registers will be restored in the catch block if caught. |
| 280 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 281 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 282 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 283 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 286 | bool IsFatal() const OVERRIDE { return true; } |
| 287 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 288 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 289 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 290 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 291 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 292 | }; |
| 293 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 294 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 295 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 297 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 298 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 300 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 301 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 302 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 303 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 304 | if (successor_ == nullptr) { |
| 305 | __ b(GetReturnLabel()); |
| 306 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 307 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 308 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 311 | Label* GetReturnLabel() { |
| 312 | DCHECK(successor_ == nullptr); |
| 313 | return &return_label_; |
| 314 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 315 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 316 | HBasicBlock* GetSuccessor() const { |
| 317 | return successor_; |
| 318 | } |
| 319 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 320 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 321 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 322 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 323 | // If not null, the block to branch to after the suspend check. |
| 324 | HBasicBlock* const successor_; |
| 325 | |
| 326 | // 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] | 327 | Label return_label_; |
| 328 | |
| 329 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 330 | }; |
| 331 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 332 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 333 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 334 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 335 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 336 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 337 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 338 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 339 | LocationSummary* locations = instruction_->GetLocations(); |
| 340 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 341 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 342 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 343 | // Live registers will be restored in the catch block if caught. |
| 344 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 345 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 346 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 347 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 348 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 349 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 350 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 351 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 352 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 353 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 354 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 355 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 356 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 357 | ? kQuickThrowStringBounds |
| 358 | : kQuickThrowArrayBounds; |
| 359 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 360 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 361 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 364 | bool IsFatal() const OVERRIDE { return true; } |
| 365 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 366 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 367 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 368 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 369 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 370 | }; |
| 371 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 372 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 373 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 374 | LoadClassSlowPathARM(HLoadClass* cls, |
| 375 | HInstruction* at, |
| 376 | uint32_t dex_pc, |
| 377 | bool do_clinit) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 378 | : 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] | 379 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 380 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 381 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 382 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 383 | LocationSummary* locations = at_->GetLocations(); |
| 384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 385 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 386 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 387 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 388 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 389 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 390 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 391 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 392 | : kQuickInitializeType; |
| 393 | arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 394 | if (do_clinit_) { |
| 395 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 396 | } else { |
| 397 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 398 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 399 | |
| 400 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 401 | Location out = locations->Out(); |
| 402 | if (out.IsValid()) { |
| 403 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 404 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 405 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 406 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 407 | __ b(GetExitLabel()); |
| 408 | } |
| 409 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 410 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 411 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 412 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 413 | // The class this slow path will load. |
| 414 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 415 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 416 | // The instruction where this slow path is happening. |
| 417 | // (Might be the load class or an initialization check). |
| 418 | HInstruction* const at_; |
| 419 | |
| 420 | // The dex PC of `at_`. |
| 421 | const uint32_t dex_pc_; |
| 422 | |
| 423 | // Whether to initialize the class. |
| 424 | const bool do_clinit_; |
| 425 | |
| 426 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 427 | }; |
| 428 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 429 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 430 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 431 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 432 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 433 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 434 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 435 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 436 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 437 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 438 | DCHECK(instruction_->IsCheckCast() |
| 439 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 440 | |
| 441 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 442 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 443 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 444 | if (!is_fatal_) { |
| 445 | SaveLiveRegisters(codegen, locations); |
| 446 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 447 | |
| 448 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 449 | // move resolver. |
| 450 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 451 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 452 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 453 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 454 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 455 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 456 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 457 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 458 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 459 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 460 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 461 | instruction_, |
| 462 | instruction_->GetDexPc(), |
| 463 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 464 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 465 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 466 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 467 | } else { |
| 468 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 469 | arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 470 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 471 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 472 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 473 | if (!is_fatal_) { |
| 474 | RestoreLiveRegisters(codegen, locations); |
| 475 | __ b(GetExitLabel()); |
| 476 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 479 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 480 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 481 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 482 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 483 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 484 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 485 | |
| 486 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 487 | }; |
| 488 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 489 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 490 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 491 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 492 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 493 | |
| 494 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 495 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 496 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 497 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 498 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 501 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 502 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 504 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 505 | }; |
| 506 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 507 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 508 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 509 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 510 | |
| 511 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 512 | LocationSummary* locations = instruction_->GetLocations(); |
| 513 | __ Bind(GetEntryLabel()); |
| 514 | SaveLiveRegisters(codegen, locations); |
| 515 | |
| 516 | InvokeRuntimeCallingConvention calling_convention; |
| 517 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 518 | parallel_move.AddMove( |
| 519 | locations->InAt(0), |
| 520 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 521 | Primitive::kPrimNot, |
| 522 | nullptr); |
| 523 | parallel_move.AddMove( |
| 524 | locations->InAt(1), |
| 525 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 526 | Primitive::kPrimInt, |
| 527 | nullptr); |
| 528 | parallel_move.AddMove( |
| 529 | locations->InAt(2), |
| 530 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 531 | Primitive::kPrimNot, |
| 532 | nullptr); |
| 533 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 534 | |
| 535 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 536 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 537 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 538 | RestoreLiveRegisters(codegen, locations); |
| 539 | __ b(GetExitLabel()); |
| 540 | } |
| 541 | |
| 542 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 543 | |
| 544 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 545 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 546 | }; |
| 547 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 548 | // Slow path marking an object during a read barrier. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 549 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 550 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 551 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 552 | : SlowPathCodeARM(instruction), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 553 | DCHECK(kEmitCompilerReadBarrier); |
| 554 | } |
| 555 | |
| 556 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 557 | |
| 558 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 559 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 560 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 561 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 562 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 563 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 564 | instruction_->IsStaticFieldGet() || |
| 565 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 566 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 567 | instruction_->IsLoadClass() || |
| 568 | instruction_->IsLoadString() || |
| 569 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 570 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 571 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 572 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 573 | << "Unexpected instruction in read barrier marking slow path: " |
| 574 | << instruction_->DebugName(); |
| 575 | |
| 576 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 577 | // No need to save live registers; it's taken care of by the |
| 578 | // entrypoint. Also, there is no need to update the stack mask, |
| 579 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 580 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 581 | DCHECK_NE(reg, SP); |
| 582 | DCHECK_NE(reg, LR); |
| 583 | DCHECK_NE(reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 584 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 585 | // as a temporary, it cannot be the entry point's input/output. |
| 586 | DCHECK_NE(reg, IP); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 587 | DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg; |
| 588 | // "Compact" slow path, saving two moves. |
| 589 | // |
| 590 | // Instead of using the standard runtime calling convention (input |
| 591 | // and output in R0): |
| 592 | // |
| 593 | // R0 <- obj |
| 594 | // R0 <- ReadBarrierMark(R0) |
| 595 | // obj <- R0 |
| 596 | // |
| 597 | // we just use rX (the register holding `obj`) as input and output |
| 598 | // of a dedicated entrypoint: |
| 599 | // |
| 600 | // rX <- ReadBarrierMarkRegX(rX) |
| 601 | // |
| 602 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 603 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 604 | // This runtime call does not require a stack map. |
| 605 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 606 | __ b(GetExitLabel()); |
| 607 | } |
| 608 | |
| 609 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 610 | const Location obj_; |
| 611 | |
| 612 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 613 | }; |
| 614 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 615 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 616 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 617 | public: |
| 618 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 619 | Location out, |
| 620 | Location ref, |
| 621 | Location obj, |
| 622 | uint32_t offset, |
| 623 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 624 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 625 | out_(out), |
| 626 | ref_(ref), |
| 627 | obj_(obj), |
| 628 | offset_(offset), |
| 629 | index_(index) { |
| 630 | DCHECK(kEmitCompilerReadBarrier); |
| 631 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 632 | // has been overwritten by (or after) the heap object reference load |
| 633 | // to be instrumented, e.g.: |
| 634 | // |
| 635 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 636 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 637 | // |
| 638 | // In that case, we have lost the information about the original |
| 639 | // object, and the emitted read barrier cannot work properly. |
| 640 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 641 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 642 | } |
| 643 | |
| 644 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 645 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 646 | LocationSummary* locations = instruction_->GetLocations(); |
| 647 | Register reg_out = out_.AsRegister<Register>(); |
| 648 | DCHECK(locations->CanCall()); |
| 649 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 650 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 651 | instruction_->IsStaticFieldGet() || |
| 652 | instruction_->IsArrayGet() || |
| 653 | instruction_->IsInstanceOf() || |
| 654 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 655 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 656 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 657 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 658 | |
| 659 | __ Bind(GetEntryLabel()); |
| 660 | SaveLiveRegisters(codegen, locations); |
| 661 | |
| 662 | // We may have to change the index's value, but as `index_` is a |
| 663 | // constant member (like other "inputs" of this slow path), |
| 664 | // introduce a copy of it, `index`. |
| 665 | Location index = index_; |
| 666 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 667 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 668 | if (instruction_->IsArrayGet()) { |
| 669 | // Compute the actual memory offset and store it in `index`. |
| 670 | Register index_reg = index_.AsRegister<Register>(); |
| 671 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 672 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 673 | // We are about to change the value of `index_reg` (see the |
| 674 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 675 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 676 | // not been saved by the previous call to |
| 677 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 678 | // callee-save register -- |
| 679 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 680 | // callee-save registers, as it has been designed with the |
| 681 | // assumption that callee-save registers are supposed to be |
| 682 | // handled by the called function. So, as a callee-save |
| 683 | // register, `index_reg` _would_ eventually be saved onto |
| 684 | // the stack, but it would be too late: we would have |
| 685 | // changed its value earlier. Therefore, we manually save |
| 686 | // it here into another freely available register, |
| 687 | // `free_reg`, chosen of course among the caller-save |
| 688 | // registers (as a callee-save `free_reg` register would |
| 689 | // exhibit the same problem). |
| 690 | // |
| 691 | // Note we could have requested a temporary register from |
| 692 | // the register allocator instead; but we prefer not to, as |
| 693 | // this is a slow path, and we know we can find a |
| 694 | // caller-save register that is available. |
| 695 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 696 | __ Mov(free_reg, index_reg); |
| 697 | index_reg = free_reg; |
| 698 | index = Location::RegisterLocation(index_reg); |
| 699 | } else { |
| 700 | // The initial register stored in `index_` has already been |
| 701 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 702 | // (as it is not a callee-save register), so we can freely |
| 703 | // use it. |
| 704 | } |
| 705 | // Shifting the index value contained in `index_reg` by the scale |
| 706 | // factor (2) cannot overflow in practice, as the runtime is |
| 707 | // unable to allocate object arrays with a size larger than |
| 708 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 709 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 710 | static_assert( |
| 711 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 712 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 713 | __ AddConstant(index_reg, index_reg, offset_); |
| 714 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 715 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 716 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 717 | // (as in the case of ArrayGet), as it is actually an offset |
| 718 | // to an object field within an object. |
| 719 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 720 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 721 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 722 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 723 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 724 | DCHECK_EQ(offset_, 0U); |
| 725 | DCHECK(index_.IsRegisterPair()); |
| 726 | // UnsafeGet's offset location is a register pair, the low |
| 727 | // part contains the correct offset. |
| 728 | index = index_.ToLow(); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | // We're moving two or three locations to locations that could |
| 733 | // overlap, so we need a parallel move resolver. |
| 734 | InvokeRuntimeCallingConvention calling_convention; |
| 735 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 736 | parallel_move.AddMove(ref_, |
| 737 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 738 | Primitive::kPrimNot, |
| 739 | nullptr); |
| 740 | parallel_move.AddMove(obj_, |
| 741 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 742 | Primitive::kPrimNot, |
| 743 | nullptr); |
| 744 | if (index.IsValid()) { |
| 745 | parallel_move.AddMove(index, |
| 746 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 747 | Primitive::kPrimInt, |
| 748 | nullptr); |
| 749 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 750 | } else { |
| 751 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 752 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 753 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 754 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 755 | CheckEntrypointTypes< |
| 756 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 757 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 758 | |
| 759 | RestoreLiveRegisters(codegen, locations); |
| 760 | __ b(GetExitLabel()); |
| 761 | } |
| 762 | |
| 763 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 764 | |
| 765 | private: |
| 766 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 767 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 768 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 769 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 770 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 771 | return static_cast<Register>(i); |
| 772 | } |
| 773 | } |
| 774 | // We shall never fail to find a free caller-save register, as |
| 775 | // there are more than two core caller-save registers on ARM |
| 776 | // (meaning it is possible to find one which is different from |
| 777 | // `ref` and `obj`). |
| 778 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 779 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 780 | UNREACHABLE(); |
| 781 | } |
| 782 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 783 | const Location out_; |
| 784 | const Location ref_; |
| 785 | const Location obj_; |
| 786 | const uint32_t offset_; |
| 787 | // An additional location containing an index to an array. |
| 788 | // Only used for HArrayGet and the UnsafeGetObject & |
| 789 | // UnsafeGetObjectVolatile intrinsics. |
| 790 | const Location index_; |
| 791 | |
| 792 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 793 | }; |
| 794 | |
| 795 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 796 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 797 | public: |
| 798 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 799 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 800 | DCHECK(kEmitCompilerReadBarrier); |
| 801 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 802 | |
| 803 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 804 | LocationSummary* locations = instruction_->GetLocations(); |
| 805 | Register reg_out = out_.AsRegister<Register>(); |
| 806 | DCHECK(locations->CanCall()); |
| 807 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 808 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 809 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 810 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 811 | |
| 812 | __ Bind(GetEntryLabel()); |
| 813 | SaveLiveRegisters(codegen, locations); |
| 814 | |
| 815 | InvokeRuntimeCallingConvention calling_convention; |
| 816 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 817 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 818 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 819 | instruction_, |
| 820 | instruction_->GetDexPc(), |
| 821 | this); |
| 822 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 823 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 824 | |
| 825 | RestoreLiveRegisters(codegen, locations); |
| 826 | __ b(GetExitLabel()); |
| 827 | } |
| 828 | |
| 829 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 830 | |
| 831 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 832 | const Location out_; |
| 833 | const Location root_; |
| 834 | |
| 835 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 836 | }; |
| 837 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 838 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 839 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 840 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 841 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 842 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 843 | switch (cond) { |
| 844 | case kCondEQ: return EQ; |
| 845 | case kCondNE: return NE; |
| 846 | case kCondLT: return LT; |
| 847 | case kCondLE: return LE; |
| 848 | case kCondGT: return GT; |
| 849 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 850 | case kCondB: return LO; |
| 851 | case kCondBE: return LS; |
| 852 | case kCondA: return HI; |
| 853 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 854 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 855 | LOG(FATAL) << "Unreachable"; |
| 856 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 859 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 860 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 861 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 862 | case kCondEQ: return EQ; |
| 863 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 864 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 865 | case kCondLT: return LO; |
| 866 | case kCondLE: return LS; |
| 867 | case kCondGT: return HI; |
| 868 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 869 | // Unsigned remain unchanged. |
| 870 | case kCondB: return LO; |
| 871 | case kCondBE: return LS; |
| 872 | case kCondA: return HI; |
| 873 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 874 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 875 | LOG(FATAL) << "Unreachable"; |
| 876 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 879 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 880 | // The ARM condition codes can express all the necessary branches, see the |
| 881 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 882 | // There is no dex instruction or HIR that would need the missing conditions |
| 883 | // "equal or unordered" or "not equal". |
| 884 | switch (cond) { |
| 885 | case kCondEQ: return EQ; |
| 886 | case kCondNE: return NE /* unordered */; |
| 887 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 888 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 889 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 890 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 891 | default: |
| 892 | LOG(FATAL) << "UNREACHABLE"; |
| 893 | UNREACHABLE(); |
| 894 | } |
| 895 | } |
| 896 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 897 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 898 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 902 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 903 | } |
| 904 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 905 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 906 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 907 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 910 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 911 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 912 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 915 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 916 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 917 | return kArmWordSize; |
| 918 | } |
| 919 | |
| 920 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 921 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 922 | return kArmWordSize; |
| 923 | } |
| 924 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 925 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 926 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 927 | const CompilerOptions& compiler_options, |
| 928 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 929 | : CodeGenerator(graph, |
| 930 | kNumberOfCoreRegisters, |
| 931 | kNumberOfSRegisters, |
| 932 | kNumberOfRegisterPairs, |
| 933 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 934 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 935 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 936 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 937 | compiler_options, |
| 938 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 939 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 940 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 941 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 942 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 943 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 944 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 945 | uint32_literals_(std::less<uint32_t>(), |
| 946 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 947 | method_patches_(MethodReferenceComparator(), |
| 948 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 949 | call_patches_(MethodReferenceComparator(), |
| 950 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 951 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 952 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 953 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 954 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 955 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 956 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 957 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 958 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 959 | boot_image_address_patches_(std::less<uint32_t>(), |
| 960 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 961 | // Always save the LR register to mimic Quick. |
| 962 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 965 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 966 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 967 | __ FinalizeCode(); |
| 968 | |
| 969 | // Adjust native pc offsets in stack maps. |
| 970 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 971 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 972 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 973 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 974 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 975 | // Adjust pc offsets for the disassembly information. |
| 976 | if (disasm_info_ != nullptr) { |
| 977 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 978 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 979 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 980 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 981 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 982 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 983 | } |
| 984 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 985 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 986 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 987 | } |
| 988 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 989 | |
| 990 | CodeGenerator::Finalize(allocator); |
| 991 | } |
| 992 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 993 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 994 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 995 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 996 | |
| 997 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 998 | blocked_core_registers_[SP] = true; |
| 999 | blocked_core_registers_[LR] = true; |
| 1000 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1001 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1002 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1003 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1004 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1005 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1006 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1007 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1008 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1009 | // Stubs do not save callee-save floating point registers. If the graph |
| 1010 | // is debuggable, we need to deal with these registers differently. For |
| 1011 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1012 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1013 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1014 | } |
| 1015 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1016 | |
| 1017 | UpdateBlockedPairRegisters(); |
| 1018 | } |
| 1019 | |
| 1020 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 1021 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 1022 | ArmManagedRegister current = |
| 1023 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 1024 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 1025 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 1026 | blocked_register_pairs_[i] = true; |
| 1027 | } |
| 1028 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1031 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1032 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1033 | assembler_(codegen->GetAssembler()), |
| 1034 | codegen_(codegen) {} |
| 1035 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1036 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1037 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1038 | 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] | 1039 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1040 | // restore another arbitrary register. |
| 1041 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1042 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1043 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1044 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1045 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1046 | // but in the range. |
| 1047 | if (fpu_spill_mask_ != 0) { |
| 1048 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1049 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1050 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1051 | fpu_spill_mask_ |= (1 << i); |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1056 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1057 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1061 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1064 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1065 | bool skip_overflow_check = |
| 1066 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1067 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1068 | __ Bind(&frame_entry_label_); |
| 1069 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1070 | if (HasEmptyFrame()) { |
| 1071 | return; |
| 1072 | } |
| 1073 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1074 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1075 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1076 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1077 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1078 | } |
| 1079 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1080 | __ PushList(core_spill_mask_); |
| 1081 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1082 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1083 | if (fpu_spill_mask_ != 0) { |
| 1084 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1085 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1086 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1087 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1088 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1089 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1090 | __ AddConstant(SP, -adjust); |
| 1091 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1092 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1096 | if (HasEmptyFrame()) { |
| 1097 | __ bx(LR); |
| 1098 | return; |
| 1099 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1100 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1101 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1102 | __ AddConstant(SP, adjust); |
| 1103 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1104 | if (fpu_spill_mask_ != 0) { |
| 1105 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1106 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1107 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1108 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1109 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1110 | // Pop LR into PC to return. |
| 1111 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1112 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1113 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1114 | __ cfi().RestoreState(); |
| 1115 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1118 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1119 | Label* label = GetLabelOf(block); |
| 1120 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1123 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1124 | switch (type) { |
| 1125 | case Primitive::kPrimBoolean: |
| 1126 | case Primitive::kPrimByte: |
| 1127 | case Primitive::kPrimChar: |
| 1128 | case Primitive::kPrimShort: |
| 1129 | case Primitive::kPrimInt: |
| 1130 | case Primitive::kPrimNot: { |
| 1131 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1132 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1133 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1134 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1135 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1136 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1137 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1138 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1139 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1140 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1141 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1142 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1143 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1144 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1145 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1146 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1147 | // Skip R1, and use R2_R3 instead. |
| 1148 | gp_index_++; |
| 1149 | index++; |
| 1150 | } |
| 1151 | } |
| 1152 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1153 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1154 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1155 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1156 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1157 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1158 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1159 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | case Primitive::kPrimFloat: { |
| 1164 | uint32_t stack_index = stack_index_++; |
| 1165 | if (float_index_ % 2 == 0) { |
| 1166 | float_index_ = std::max(double_index_, float_index_); |
| 1167 | } |
| 1168 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1169 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1170 | } else { |
| 1171 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | case Primitive::kPrimDouble: { |
| 1176 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1177 | uint32_t stack_index = stack_index_; |
| 1178 | stack_index_ += 2; |
| 1179 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1180 | uint32_t index = double_index_; |
| 1181 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1182 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1183 | calling_convention.GetFpuRegisterAt(index), |
| 1184 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1185 | DCHECK(ExpectedPairLayout(result)); |
| 1186 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1187 | } else { |
| 1188 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1192 | case Primitive::kPrimVoid: |
| 1193 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1194 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1195 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1196 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1197 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1198 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1199 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1200 | switch (type) { |
| 1201 | case Primitive::kPrimBoolean: |
| 1202 | case Primitive::kPrimByte: |
| 1203 | case Primitive::kPrimChar: |
| 1204 | case Primitive::kPrimShort: |
| 1205 | case Primitive::kPrimInt: |
| 1206 | case Primitive::kPrimNot: { |
| 1207 | return Location::RegisterLocation(R0); |
| 1208 | } |
| 1209 | |
| 1210 | case Primitive::kPrimFloat: { |
| 1211 | return Location::FpuRegisterLocation(S0); |
| 1212 | } |
| 1213 | |
| 1214 | case Primitive::kPrimLong: { |
| 1215 | return Location::RegisterPairLocation(R0, R1); |
| 1216 | } |
| 1217 | |
| 1218 | case Primitive::kPrimDouble: { |
| 1219 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1220 | } |
| 1221 | |
| 1222 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1223 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1224 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1225 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1226 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1229 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1230 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1231 | } |
| 1232 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1233 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1234 | if (source.Equals(destination)) { |
| 1235 | return; |
| 1236 | } |
| 1237 | if (destination.IsRegister()) { |
| 1238 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1239 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1240 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1241 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1242 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1243 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1244 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1245 | } else if (destination.IsFpuRegister()) { |
| 1246 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1247 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1248 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1249 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1250 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1251 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1253 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1254 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1255 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1256 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1257 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1258 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1259 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1260 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1262 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1268 | if (source.Equals(destination)) { |
| 1269 | return; |
| 1270 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1271 | if (destination.IsRegisterPair()) { |
| 1272 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1273 | EmitParallelMoves( |
| 1274 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1275 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1276 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1277 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1278 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1279 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1280 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1281 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1282 | } else if (source.IsFpuRegisterPair()) { |
| 1283 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1284 | destination.AsRegisterPairHigh<Register>(), |
| 1285 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1286 | } else { |
| 1287 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1288 | DCHECK(ExpectedPairLayout(destination)); |
| 1289 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1290 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1291 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1292 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1293 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1294 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1295 | SP, |
| 1296 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1297 | } else if (source.IsRegisterPair()) { |
| 1298 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1299 | source.AsRegisterPairLow<Register>(), |
| 1300 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1301 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1302 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1303 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1304 | } else { |
| 1305 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1306 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1307 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1308 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1309 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1310 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1311 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1312 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1313 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1314 | SP, destination.GetStackIndex()); |
| 1315 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1316 | } else if (source.IsFpuRegisterPair()) { |
| 1317 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1318 | SP, |
| 1319 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1320 | } else { |
| 1321 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1322 | EmitParallelMoves( |
| 1323 | Location::StackSlot(source.GetStackIndex()), |
| 1324 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1325 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1326 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1327 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1328 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1333 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1334 | DCHECK(location.IsRegister()); |
| 1335 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1336 | } |
| 1337 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1338 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1339 | HParallelMove move(GetGraph()->GetArena()); |
| 1340 | move.AddMove(src, dst, dst_type, nullptr); |
| 1341 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1345 | if (location.IsRegister()) { |
| 1346 | locations->AddTemp(location); |
| 1347 | } else if (location.IsRegisterPair()) { |
| 1348 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1349 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1350 | } else { |
| 1351 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1352 | } |
| 1353 | } |
| 1354 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1355 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1356 | HInstruction* instruction, |
| 1357 | uint32_t dex_pc, |
| 1358 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1359 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1360 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1361 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1362 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1363 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1366 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1367 | HInstruction* instruction, |
| 1368 | SlowPathCode* slow_path) { |
| 1369 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1370 | GenerateInvokeRuntime(entry_point_offset); |
| 1371 | } |
| 1372 | |
| 1373 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1374 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1375 | __ blx(LR); |
| 1376 | } |
| 1377 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1378 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1379 | DCHECK(!successor->IsExitBlock()); |
| 1380 | |
| 1381 | HBasicBlock* block = got->GetBlock(); |
| 1382 | HInstruction* previous = got->GetPrevious(); |
| 1383 | |
| 1384 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1385 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1386 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1387 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1392 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1393 | } |
| 1394 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1395 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1399 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1400 | got->SetLocations(nullptr); |
| 1401 | } |
| 1402 | |
| 1403 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1404 | HandleGoto(got, got->GetSuccessor()); |
| 1405 | } |
| 1406 | |
| 1407 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1408 | try_boundary->SetLocations(nullptr); |
| 1409 | } |
| 1410 | |
| 1411 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1412 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1413 | if (!successor->IsExitBlock()) { |
| 1414 | HandleGoto(try_boundary, successor); |
| 1415 | } |
| 1416 | } |
| 1417 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1418 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1419 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1422 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1425 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1426 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1427 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1428 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1429 | if (rhs_loc.IsConstant()) { |
| 1430 | // 0.0 is the only immediate that can be encoded directly in |
| 1431 | // a VCMP instruction. |
| 1432 | // |
| 1433 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1434 | // specify that in a floating-point comparison, positive zero |
| 1435 | // and negative zero are considered equal, so we can use the |
| 1436 | // literal 0.0 for both cases here. |
| 1437 | // |
| 1438 | // Note however that some methods (Float.equal, Float.compare, |
| 1439 | // Float.compareTo, Double.equal, Double.compare, |
| 1440 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1441 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1442 | // -0.0. So if we ever translate calls to these methods into a |
| 1443 | // HCompare instruction, we must handle the -0.0 case with |
| 1444 | // care here. |
| 1445 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1446 | if (type == Primitive::kPrimFloat) { |
| 1447 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1448 | } else { |
| 1449 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1450 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1451 | } |
| 1452 | } else { |
| 1453 | if (type == Primitive::kPrimFloat) { |
| 1454 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1455 | } else { |
| 1456 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1457 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1458 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1463 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1464 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1465 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1466 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1467 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1471 | Label* true_label, |
| 1472 | Label* false_label) { |
| 1473 | LocationSummary* locations = cond->GetLocations(); |
| 1474 | Location left = locations->InAt(0); |
| 1475 | Location right = locations->InAt(1); |
| 1476 | IfCondition if_cond = cond->GetCondition(); |
| 1477 | |
| 1478 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1479 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1480 | IfCondition true_high_cond = if_cond; |
| 1481 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1482 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1483 | |
| 1484 | // Set the conditions for the test, remembering that == needs to be |
| 1485 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1486 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1487 | switch (if_cond) { |
| 1488 | case kCondEQ: |
| 1489 | case kCondNE: |
| 1490 | // Nothing to do. |
| 1491 | break; |
| 1492 | case kCondLT: |
| 1493 | false_high_cond = kCondGT; |
| 1494 | break; |
| 1495 | case kCondLE: |
| 1496 | true_high_cond = kCondLT; |
| 1497 | break; |
| 1498 | case kCondGT: |
| 1499 | false_high_cond = kCondLT; |
| 1500 | break; |
| 1501 | case kCondGE: |
| 1502 | true_high_cond = kCondGT; |
| 1503 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1504 | case kCondB: |
| 1505 | false_high_cond = kCondA; |
| 1506 | break; |
| 1507 | case kCondBE: |
| 1508 | true_high_cond = kCondB; |
| 1509 | break; |
| 1510 | case kCondA: |
| 1511 | false_high_cond = kCondB; |
| 1512 | break; |
| 1513 | case kCondAE: |
| 1514 | true_high_cond = kCondA; |
| 1515 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1516 | } |
| 1517 | if (right.IsConstant()) { |
| 1518 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1519 | int32_t val_low = Low32Bits(value); |
| 1520 | int32_t val_high = High32Bits(value); |
| 1521 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1522 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1523 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1524 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1525 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1526 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1527 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1528 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1529 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1530 | } |
| 1531 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1532 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1533 | } else { |
| 1534 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1535 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1536 | |
| 1537 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1538 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1539 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1540 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1541 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1542 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1543 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1544 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1545 | } |
| 1546 | // Must be equal high, so compare the lows. |
| 1547 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1548 | } |
| 1549 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1550 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1551 | __ b(true_label, final_condition); |
| 1552 | } |
| 1553 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1555 | Label* true_target_in, |
| 1556 | Label* false_target_in) { |
| 1557 | // Generated branching requires both targets to be explicit. If either of the |
| 1558 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1559 | Label fallthrough_target; |
| 1560 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1561 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1562 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1563 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1564 | switch (type) { |
| 1565 | case Primitive::kPrimLong: |
| 1566 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1567 | break; |
| 1568 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1569 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1570 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1571 | GenerateFPJumps(condition, true_target, false_target); |
| 1572 | break; |
| 1573 | default: |
| 1574 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1575 | } |
| 1576 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1577 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1578 | __ b(false_target); |
| 1579 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1580 | |
| 1581 | if (fallthrough_target.IsLinked()) { |
| 1582 | __ Bind(&fallthrough_target); |
| 1583 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1586 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1587 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1588 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1589 | Label* false_target) { |
| 1590 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1591 | |
| 1592 | if (true_target == nullptr && false_target == nullptr) { |
| 1593 | // Nothing to do. The code always falls through. |
| 1594 | return; |
| 1595 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1596 | // Constant condition, statically compared against "true" (integer value 1). |
| 1597 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | if (true_target != nullptr) { |
| 1599 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1600 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1601 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1602 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1603 | if (false_target != nullptr) { |
| 1604 | __ b(false_target); |
| 1605 | } |
| 1606 | } |
| 1607 | return; |
| 1608 | } |
| 1609 | |
| 1610 | // The following code generates these patterns: |
| 1611 | // (1) true_target == nullptr && false_target != nullptr |
| 1612 | // - opposite condition true => branch to false_target |
| 1613 | // (2) true_target != nullptr && false_target == nullptr |
| 1614 | // - condition true => branch to true_target |
| 1615 | // (3) true_target != nullptr && false_target != nullptr |
| 1616 | // - condition true => branch to true_target |
| 1617 | // - branch to false_target |
| 1618 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1619 | // Condition has been materialized, compare the output to 0. |
| 1620 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1621 | DCHECK(cond_val.IsRegister()); |
| 1622 | if (true_target == nullptr) { |
| 1623 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1624 | } else { |
| 1625 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1626 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1627 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1628 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1629 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1630 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1631 | |
| 1632 | // If this is a long or FP comparison that has been folded into |
| 1633 | // the HCondition, generate the comparison directly. |
| 1634 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1635 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1636 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1637 | return; |
| 1638 | } |
| 1639 | |
| 1640 | LocationSummary* locations = cond->GetLocations(); |
| 1641 | DCHECK(locations->InAt(0).IsRegister()); |
| 1642 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1643 | Location right = locations->InAt(1); |
| 1644 | if (right.IsRegister()) { |
| 1645 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1646 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1647 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1648 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1649 | } |
| 1650 | if (true_target == nullptr) { |
| 1651 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1652 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1653 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1654 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1655 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1656 | |
| 1657 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1658 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1659 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1660 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1664 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1665 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1666 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1667 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1672 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1673 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1674 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1675 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1676 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1677 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1678 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1682 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1683 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 239d6ea | 2016-09-05 10:44:04 +0100 | [diff] [blame] | 1684 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1685 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1686 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1691 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1692 | GenerateTestAndBranch(deoptimize, |
| 1693 | /* condition_input_index */ 0, |
| 1694 | slow_path->GetEntryLabel(), |
| 1695 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1696 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1697 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1698 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1699 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1700 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1702 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1703 | } else { |
| 1704 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1705 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1706 | } |
| 1707 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1708 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1709 | } |
| 1710 | locations->SetOut(Location::SameAsFirstInput()); |
| 1711 | } |
| 1712 | |
| 1713 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1714 | LocationSummary* locations = select->GetLocations(); |
| 1715 | Label false_target; |
| 1716 | GenerateTestAndBranch(select, |
| 1717 | /* condition_input_index */ 2, |
| 1718 | /* true_target */ nullptr, |
| 1719 | &false_target); |
| 1720 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1721 | __ Bind(&false_target); |
| 1722 | } |
| 1723 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1724 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1725 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1726 | } |
| 1727 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1728 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1729 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | void CodeGeneratorARM::GenerateNop() { |
| 1733 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1736 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1737 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1738 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1739 | // Handle the long/FP comparisons made in instruction simplification. |
| 1740 | switch (cond->InputAt(0)->GetType()) { |
| 1741 | case Primitive::kPrimLong: |
| 1742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1743 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1744 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1745 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1746 | } |
| 1747 | break; |
| 1748 | |
| 1749 | case Primitive::kPrimFloat: |
| 1750 | case Primitive::kPrimDouble: |
| 1751 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1752 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1753 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1754 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1755 | } |
| 1756 | break; |
| 1757 | |
| 1758 | default: |
| 1759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1760 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1761 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1762 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1763 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1764 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1767 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1768 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1769 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1770 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1771 | |
| 1772 | LocationSummary* locations = cond->GetLocations(); |
| 1773 | Location left = locations->InAt(0); |
| 1774 | Location right = locations->InAt(1); |
| 1775 | Register out = locations->Out().AsRegister<Register>(); |
| 1776 | Label true_label, false_label; |
| 1777 | |
| 1778 | switch (cond->InputAt(0)->GetType()) { |
| 1779 | default: { |
| 1780 | // Integer case. |
| 1781 | if (right.IsRegister()) { |
| 1782 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1783 | } else { |
| 1784 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1785 | __ CmpConstant(left.AsRegister<Register>(), |
| 1786 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1787 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1788 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1789 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1790 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1791 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1792 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1793 | return; |
| 1794 | } |
| 1795 | case Primitive::kPrimLong: |
| 1796 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1797 | break; |
| 1798 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1799 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1800 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1801 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1802 | break; |
| 1803 | } |
| 1804 | |
| 1805 | // Convert the jumps into the result. |
| 1806 | Label done_label; |
| 1807 | |
| 1808 | // False case: result = 0. |
| 1809 | __ Bind(&false_label); |
| 1810 | __ LoadImmediate(out, 0); |
| 1811 | __ b(&done_label); |
| 1812 | |
| 1813 | // True case: result = 1. |
| 1814 | __ Bind(&true_label); |
| 1815 | __ LoadImmediate(out, 1); |
| 1816 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1832 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1836 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1840 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1844 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1848 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1852 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1856 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1860 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1864 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1867 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1868 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1872 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1876 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1880 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1884 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1888 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1892 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1896 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1899 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1900 | LocationSummary* locations = |
| 1901 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1902 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1905 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1906 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1909 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1910 | LocationSummary* locations = |
| 1911 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1912 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1913 | } |
| 1914 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1915 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1916 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1919 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1920 | LocationSummary* locations = |
| 1921 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1922 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1923 | } |
| 1924 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1925 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1926 | // Will be generated at use site. |
| 1927 | } |
| 1928 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1929 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1930 | LocationSummary* locations = |
| 1931 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1932 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1933 | } |
| 1934 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1935 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1936 | // Will be generated at use site. |
| 1937 | } |
| 1938 | |
| 1939 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1940 | LocationSummary* locations = |
| 1941 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1942 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1943 | } |
| 1944 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1945 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1946 | // Will be generated at use site. |
| 1947 | } |
| 1948 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1949 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1950 | memory_barrier->SetLocations(nullptr); |
| 1951 | } |
| 1952 | |
| 1953 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1954 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1955 | } |
| 1956 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1957 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1958 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1961 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1962 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1965 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1966 | LocationSummary* locations = |
| 1967 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1968 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1971 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1972 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1975 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1976 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1977 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1978 | // the method_idx. |
| 1979 | HandleInvoke(invoke); |
| 1980 | } |
| 1981 | |
| 1982 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1983 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1984 | } |
| 1985 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1986 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1987 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1988 | // art::PrepareForRegisterAllocation. |
| 1989 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1990 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 1991 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1992 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1993 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1994 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1995 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1996 | return; |
| 1997 | } |
| 1998 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1999 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2000 | |
| 2001 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2002 | if (invoke->HasPcRelativeDexCache()) { |
| 2003 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2004 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2007 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2008 | if (invoke->GetLocations()->Intrinsified()) { |
| 2009 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2010 | intrinsic.Dispatch(invoke); |
| 2011 | return true; |
| 2012 | } |
| 2013 | return false; |
| 2014 | } |
| 2015 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2016 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2017 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2018 | // art::PrepareForRegisterAllocation. |
| 2019 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2020 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2021 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2022 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2023 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2024 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2025 | LocationSummary* locations = invoke->GetLocations(); |
| 2026 | codegen_->GenerateStaticOrDirectCall( |
| 2027 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2028 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2029 | } |
| 2030 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2031 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2032 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2033 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2036 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2037 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2038 | if (intrinsic.TryDispatch(invoke)) { |
| 2039 | return; |
| 2040 | } |
| 2041 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2042 | HandleInvoke(invoke); |
| 2043 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2044 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2045 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2046 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2047 | return; |
| 2048 | } |
| 2049 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2050 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2051 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2052 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2055 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2056 | HandleInvoke(invoke); |
| 2057 | // Add the hidden argument. |
| 2058 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2059 | } |
| 2060 | |
| 2061 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2062 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2063 | LocationSummary* locations = invoke->GetLocations(); |
| 2064 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2065 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2066 | Location receiver = locations->InAt(0); |
| 2067 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2068 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2069 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2070 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2071 | DCHECK_EQ(R12, hidden_reg); |
| 2072 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2073 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2074 | if (receiver.IsStackSlot()) { |
| 2075 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2076 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2077 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2078 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2079 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2080 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2081 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2082 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2083 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2084 | // emit a read barrier for the previous class reference load. |
| 2085 | // However this is not required in practice, as this is an |
| 2086 | // intermediate/temporary reference and because the current |
| 2087 | // concurrent copying collector keeps the from-space memory |
| 2088 | // intact/accessible until the end of the marking phase (the |
| 2089 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2090 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2091 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2092 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2093 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2094 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2095 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2096 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2097 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2098 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2099 | // LR = temp->GetEntryPoint(); |
| 2100 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2101 | // LR(); |
| 2102 | __ blx(LR); |
| 2103 | DCHECK(!codegen_->IsLeafMethod()); |
| 2104 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2105 | } |
| 2106 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2107 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2108 | LocationSummary* locations = |
| 2109 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2110 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2111 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2112 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2113 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2114 | break; |
| 2115 | } |
| 2116 | case Primitive::kPrimLong: { |
| 2117 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2118 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2119 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2120 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2121 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2122 | case Primitive::kPrimFloat: |
| 2123 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2124 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2125 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2126 | break; |
| 2127 | |
| 2128 | default: |
| 2129 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2134 | LocationSummary* locations = neg->GetLocations(); |
| 2135 | Location out = locations->Out(); |
| 2136 | Location in = locations->InAt(0); |
| 2137 | switch (neg->GetResultType()) { |
| 2138 | case Primitive::kPrimInt: |
| 2139 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2140 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2141 | break; |
| 2142 | |
| 2143 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2144 | DCHECK(in.IsRegisterPair()); |
| 2145 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2146 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2147 | in.AsRegisterPairLow<Register>(), |
| 2148 | ShifterOperand(0)); |
| 2149 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2150 | // instruction here, as it does not exist in the Thumb-2 |
| 2151 | // instruction set. We use the following approach |
| 2152 | // using SBC and SUB instead. |
| 2153 | // |
| 2154 | // out.hi = -C |
| 2155 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2156 | out.AsRegisterPairHigh<Register>(), |
| 2157 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2158 | // out.hi = out.hi - in.hi |
| 2159 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2160 | out.AsRegisterPairHigh<Register>(), |
| 2161 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2162 | break; |
| 2163 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2164 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2165 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2166 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2167 | break; |
| 2168 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2169 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2170 | DCHECK(in.IsFpuRegisterPair()); |
| 2171 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2172 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2173 | break; |
| 2174 | |
| 2175 | default: |
| 2176 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2177 | } |
| 2178 | } |
| 2179 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2180 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2181 | Primitive::Type result_type = conversion->GetResultType(); |
| 2182 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2183 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2184 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2185 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2186 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2187 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2188 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2189 | && result_type == Primitive::kPrimLong) |
| 2190 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2191 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2192 | : LocationSummary::kNoCall; |
| 2193 | LocationSummary* locations = |
| 2194 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2195 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2196 | // The Java language does not allow treating boolean as an integral type but |
| 2197 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2198 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2199 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2200 | case Primitive::kPrimByte: |
| 2201 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2202 | case Primitive::kPrimLong: |
| 2203 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2204 | case Primitive::kPrimBoolean: |
| 2205 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2206 | case Primitive::kPrimShort: |
| 2207 | case Primitive::kPrimInt: |
| 2208 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2209 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2212 | break; |
| 2213 | |
| 2214 | default: |
| 2215 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2216 | << " to " << result_type; |
| 2217 | } |
| 2218 | break; |
| 2219 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimShort: |
| 2221 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2222 | case Primitive::kPrimLong: |
| 2223 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2224 | case Primitive::kPrimBoolean: |
| 2225 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2226 | case Primitive::kPrimByte: |
| 2227 | case Primitive::kPrimInt: |
| 2228 | case Primitive::kPrimChar: |
| 2229 | // Processing a Dex `int-to-short' instruction. |
| 2230 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2231 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2232 | break; |
| 2233 | |
| 2234 | default: |
| 2235 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2236 | << " to " << result_type; |
| 2237 | } |
| 2238 | break; |
| 2239 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2240 | case Primitive::kPrimInt: |
| 2241 | switch (input_type) { |
| 2242 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2243 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2244 | locations->SetInAt(0, Location::Any()); |
| 2245 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2246 | break; |
| 2247 | |
| 2248 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2249 | // Processing a Dex `float-to-int' instruction. |
| 2250 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2251 | locations->SetOut(Location::RequiresRegister()); |
| 2252 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2253 | break; |
| 2254 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2255 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2256 | // Processing a Dex `double-to-int' instruction. |
| 2257 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2258 | locations->SetOut(Location::RequiresRegister()); |
| 2259 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2260 | break; |
| 2261 | |
| 2262 | default: |
| 2263 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2264 | << " to " << result_type; |
| 2265 | } |
| 2266 | break; |
| 2267 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimLong: |
| 2269 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimBoolean: |
| 2271 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimByte: |
| 2273 | case Primitive::kPrimShort: |
| 2274 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2275 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2276 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2277 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2278 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2279 | break; |
| 2280 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimFloat: { |
| 2282 | // Processing a Dex `float-to-long' instruction. |
| 2283 | InvokeRuntimeCallingConvention calling_convention; |
| 2284 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2285 | calling_convention.GetFpuRegisterAt(0))); |
| 2286 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2287 | break; |
| 2288 | } |
| 2289 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimDouble: { |
| 2291 | // Processing a Dex `double-to-long' instruction. |
| 2292 | InvokeRuntimeCallingConvention calling_convention; |
| 2293 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2294 | calling_convention.GetFpuRegisterAt(0), |
| 2295 | calling_convention.GetFpuRegisterAt(1))); |
| 2296 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2297 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2298 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2299 | |
| 2300 | default: |
| 2301 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2302 | << " to " << result_type; |
| 2303 | } |
| 2304 | break; |
| 2305 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2306 | case Primitive::kPrimChar: |
| 2307 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2308 | case Primitive::kPrimLong: |
| 2309 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimBoolean: |
| 2311 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimByte: |
| 2313 | case Primitive::kPrimShort: |
| 2314 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2315 | // Processing a Dex `int-to-char' instruction. |
| 2316 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2317 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2318 | break; |
| 2319 | |
| 2320 | default: |
| 2321 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2322 | << " to " << result_type; |
| 2323 | } |
| 2324 | break; |
| 2325 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2327 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2328 | case Primitive::kPrimBoolean: |
| 2329 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimByte: |
| 2331 | case Primitive::kPrimShort: |
| 2332 | case Primitive::kPrimInt: |
| 2333 | case Primitive::kPrimChar: |
| 2334 | // Processing a Dex `int-to-float' instruction. |
| 2335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2336 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2337 | break; |
| 2338 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2339 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2340 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2341 | InvokeRuntimeCallingConvention calling_convention; |
| 2342 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2343 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2344 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2345 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2346 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2347 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2348 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2349 | // Processing a Dex `double-to-float' instruction. |
| 2350 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2351 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2352 | break; |
| 2353 | |
| 2354 | default: |
| 2355 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2356 | << " to " << result_type; |
| 2357 | }; |
| 2358 | break; |
| 2359 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2361 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2362 | case Primitive::kPrimBoolean: |
| 2363 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimByte: |
| 2365 | case Primitive::kPrimShort: |
| 2366 | case Primitive::kPrimInt: |
| 2367 | case Primitive::kPrimChar: |
| 2368 | // Processing a Dex `int-to-double' instruction. |
| 2369 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2370 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2371 | break; |
| 2372 | |
| 2373 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2374 | // Processing a Dex `long-to-double' instruction. |
| 2375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2376 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2377 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2378 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2379 | break; |
| 2380 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2382 | // Processing a Dex `float-to-double' instruction. |
| 2383 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2384 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2389 | << " to " << result_type; |
| 2390 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | |
| 2393 | default: |
| 2394 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2395 | << " to " << result_type; |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2400 | LocationSummary* locations = conversion->GetLocations(); |
| 2401 | Location out = locations->Out(); |
| 2402 | Location in = locations->InAt(0); |
| 2403 | Primitive::Type result_type = conversion->GetResultType(); |
| 2404 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2405 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2406 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimByte: |
| 2408 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimLong: |
| 2410 | // Type conversion from long to byte is a result of code transformations. |
| 2411 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2412 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimBoolean: |
| 2414 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimShort: |
| 2416 | case Primitive::kPrimInt: |
| 2417 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2418 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2419 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2420 | break; |
| 2421 | |
| 2422 | default: |
| 2423 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2424 | << " to " << result_type; |
| 2425 | } |
| 2426 | break; |
| 2427 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimShort: |
| 2429 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimLong: |
| 2431 | // Type conversion from long to short is a result of code transformations. |
| 2432 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2433 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimBoolean: |
| 2435 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2436 | case Primitive::kPrimByte: |
| 2437 | case Primitive::kPrimInt: |
| 2438 | case Primitive::kPrimChar: |
| 2439 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2440 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2445 | << " to " << result_type; |
| 2446 | } |
| 2447 | break; |
| 2448 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2449 | case Primitive::kPrimInt: |
| 2450 | switch (input_type) { |
| 2451 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2452 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2453 | DCHECK(out.IsRegister()); |
| 2454 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2455 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2456 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2457 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2458 | } else { |
| 2459 | DCHECK(in.IsConstant()); |
| 2460 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2461 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2462 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2463 | } |
| 2464 | break; |
| 2465 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2466 | case Primitive::kPrimFloat: { |
| 2467 | // Processing a Dex `float-to-int' instruction. |
| 2468 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2469 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2470 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2471 | break; |
| 2472 | } |
| 2473 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimDouble: { |
| 2475 | // Processing a Dex `double-to-int' instruction. |
| 2476 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2477 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2478 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2479 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2480 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2481 | |
| 2482 | default: |
| 2483 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2484 | << " to " << result_type; |
| 2485 | } |
| 2486 | break; |
| 2487 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2488 | case Primitive::kPrimLong: |
| 2489 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimBoolean: |
| 2491 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimByte: |
| 2493 | case Primitive::kPrimShort: |
| 2494 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2496 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2497 | DCHECK(out.IsRegisterPair()); |
| 2498 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2499 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2500 | // Sign extension. |
| 2501 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2502 | out.AsRegisterPairLow<Register>(), |
| 2503 | 31); |
| 2504 | break; |
| 2505 | |
| 2506 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2507 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2508 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2509 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2510 | break; |
| 2511 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2513 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2514 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2515 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2516 | break; |
| 2517 | |
| 2518 | default: |
| 2519 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2520 | << " to " << result_type; |
| 2521 | } |
| 2522 | break; |
| 2523 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2524 | case Primitive::kPrimChar: |
| 2525 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimLong: |
| 2527 | // Type conversion from long to char is a result of code transformations. |
| 2528 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2529 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimBoolean: |
| 2531 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimByte: |
| 2533 | case Primitive::kPrimShort: |
| 2534 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2535 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2536 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | |
| 2539 | default: |
| 2540 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2541 | << " to " << result_type; |
| 2542 | } |
| 2543 | break; |
| 2544 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2546 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimBoolean: |
| 2548 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2549 | case Primitive::kPrimByte: |
| 2550 | case Primitive::kPrimShort: |
| 2551 | case Primitive::kPrimInt: |
| 2552 | case Primitive::kPrimChar: { |
| 2553 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2554 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2555 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | } |
| 2558 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2559 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2560 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2561 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2562 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2563 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2564 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2566 | // Processing a Dex `double-to-float' instruction. |
| 2567 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2568 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2569 | break; |
| 2570 | |
| 2571 | default: |
| 2572 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2573 | << " to " << result_type; |
| 2574 | }; |
| 2575 | break; |
| 2576 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2577 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2578 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2579 | case Primitive::kPrimBoolean: |
| 2580 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2581 | case Primitive::kPrimByte: |
| 2582 | case Primitive::kPrimShort: |
| 2583 | case Primitive::kPrimInt: |
| 2584 | case Primitive::kPrimChar: { |
| 2585 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2586 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2587 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2588 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2589 | break; |
| 2590 | } |
| 2591 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimLong: { |
| 2593 | // Processing a Dex `long-to-double' instruction. |
| 2594 | Register low = in.AsRegisterPairLow<Register>(); |
| 2595 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2596 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2597 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2598 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2599 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2600 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2601 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2602 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2603 | // temp_d = int-to-double(high) |
| 2604 | __ vmovsr(temp_s, high); |
| 2605 | __ vcvtdi(temp_d, temp_s); |
| 2606 | // constant_d = k2Pow32EncodingForDouble |
| 2607 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2608 | // out_d = unsigned-to-double(low) |
| 2609 | __ vmovsr(out_s, low); |
| 2610 | __ vcvtdu(out_d, out_s); |
| 2611 | // out_d += temp_d * constant_d |
| 2612 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2613 | break; |
| 2614 | } |
| 2615 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2617 | // Processing a Dex `float-to-double' instruction. |
| 2618 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2619 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2620 | break; |
| 2621 | |
| 2622 | default: |
| 2623 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2624 | << " to " << result_type; |
| 2625 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | |
| 2628 | default: |
| 2629 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2630 | << " to " << result_type; |
| 2631 | } |
| 2632 | } |
| 2633 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2634 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2635 | LocationSummary* locations = |
| 2636 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2637 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2639 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2640 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2641 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2642 | break; |
| 2643 | } |
| 2644 | |
| 2645 | case Primitive::kPrimLong: { |
| 2646 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2647 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2648 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2649 | break; |
| 2650 | } |
| 2651 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2652 | case Primitive::kPrimFloat: |
| 2653 | case Primitive::kPrimDouble: { |
| 2654 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2655 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2656 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2657 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2658 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2659 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2660 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2661 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2662 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2666 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2667 | Location out = locations->Out(); |
| 2668 | Location first = locations->InAt(0); |
| 2669 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2670 | switch (add->GetResultType()) { |
| 2671 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2672 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2673 | __ add(out.AsRegister<Register>(), |
| 2674 | first.AsRegister<Register>(), |
| 2675 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2676 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2677 | __ AddConstant(out.AsRegister<Register>(), |
| 2678 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2679 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2680 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2681 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2682 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2683 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2684 | if (second.IsConstant()) { |
| 2685 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2686 | GenerateAddLongConst(out, first, value); |
| 2687 | } else { |
| 2688 | DCHECK(second.IsRegisterPair()); |
| 2689 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2690 | first.AsRegisterPairLow<Register>(), |
| 2691 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2692 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2693 | first.AsRegisterPairHigh<Register>(), |
| 2694 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2695 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2696 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2697 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2698 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2699 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2700 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2701 | first.AsFpuRegister<SRegister>(), |
| 2702 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2706 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2707 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2708 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2709 | break; |
| 2710 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2711 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2712 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2716 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2717 | LocationSummary* locations = |
| 2718 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2719 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2720 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2721 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2722 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2723 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2724 | break; |
| 2725 | } |
| 2726 | |
| 2727 | case Primitive::kPrimLong: { |
| 2728 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2729 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2730 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2731 | break; |
| 2732 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2733 | case Primitive::kPrimFloat: |
| 2734 | case Primitive::kPrimDouble: { |
| 2735 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2736 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2737 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2738 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2739 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2740 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2741 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2742 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2746 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2747 | Location out = locations->Out(); |
| 2748 | Location first = locations->InAt(0); |
| 2749 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2750 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2751 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2752 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2753 | __ sub(out.AsRegister<Register>(), |
| 2754 | first.AsRegister<Register>(), |
| 2755 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2756 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2757 | __ AddConstant(out.AsRegister<Register>(), |
| 2758 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2759 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2760 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2761 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2762 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2763 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2764 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2765 | if (second.IsConstant()) { |
| 2766 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2767 | GenerateAddLongConst(out, first, -value); |
| 2768 | } else { |
| 2769 | DCHECK(second.IsRegisterPair()); |
| 2770 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2771 | first.AsRegisterPairLow<Register>(), |
| 2772 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2773 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2774 | first.AsRegisterPairHigh<Register>(), |
| 2775 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2776 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2777 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2778 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2779 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2780 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2781 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2782 | first.AsFpuRegister<SRegister>(), |
| 2783 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2784 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2788 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2789 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2790 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2791 | break; |
| 2792 | } |
| 2793 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2794 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2795 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2796 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2800 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2801 | LocationSummary* locations = |
| 2802 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2803 | switch (mul->GetResultType()) { |
| 2804 | case Primitive::kPrimInt: |
| 2805 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2807 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2808 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2809 | break; |
| 2810 | } |
| 2811 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2812 | case Primitive::kPrimFloat: |
| 2813 | case Primitive::kPrimDouble: { |
| 2814 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2815 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2816 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2817 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2818 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2819 | |
| 2820 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2821 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2826 | LocationSummary* locations = mul->GetLocations(); |
| 2827 | Location out = locations->Out(); |
| 2828 | Location first = locations->InAt(0); |
| 2829 | Location second = locations->InAt(1); |
| 2830 | switch (mul->GetResultType()) { |
| 2831 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2832 | __ mul(out.AsRegister<Register>(), |
| 2833 | first.AsRegister<Register>(), |
| 2834 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2835 | break; |
| 2836 | } |
| 2837 | case Primitive::kPrimLong: { |
| 2838 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2839 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2840 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2841 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2842 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2843 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2844 | |
| 2845 | // Extra checks to protect caused by the existence of R1_R2. |
| 2846 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2847 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2848 | DCHECK_NE(out_hi, in1_lo); |
| 2849 | DCHECK_NE(out_hi, in2_lo); |
| 2850 | |
| 2851 | // input: in1 - 64 bits, in2 - 64 bits |
| 2852 | // output: out |
| 2853 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2854 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2855 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2856 | |
| 2857 | // IP <- in1.lo * in2.hi |
| 2858 | __ mul(IP, in1_lo, in2_hi); |
| 2859 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2860 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2861 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2862 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2863 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2864 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2865 | break; |
| 2866 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2867 | |
| 2868 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2869 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2870 | first.AsFpuRegister<SRegister>(), |
| 2871 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2872 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2876 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2877 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2878 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2879 | break; |
| 2880 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2881 | |
| 2882 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2883 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2884 | } |
| 2885 | } |
| 2886 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2887 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2888 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2889 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2890 | |
| 2891 | LocationSummary* locations = instruction->GetLocations(); |
| 2892 | Location second = locations->InAt(1); |
| 2893 | DCHECK(second.IsConstant()); |
| 2894 | |
| 2895 | Register out = locations->Out().AsRegister<Register>(); |
| 2896 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2897 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2898 | DCHECK(imm == 1 || imm == -1); |
| 2899 | |
| 2900 | if (instruction->IsRem()) { |
| 2901 | __ LoadImmediate(out, 0); |
| 2902 | } else { |
| 2903 | if (imm == 1) { |
| 2904 | __ Mov(out, dividend); |
| 2905 | } else { |
| 2906 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2907 | } |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2912 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2913 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2914 | |
| 2915 | LocationSummary* locations = instruction->GetLocations(); |
| 2916 | Location second = locations->InAt(1); |
| 2917 | DCHECK(second.IsConstant()); |
| 2918 | |
| 2919 | Register out = locations->Out().AsRegister<Register>(); |
| 2920 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2921 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2922 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2923 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2924 | int ctz_imm = CTZ(abs_imm); |
| 2925 | |
| 2926 | if (ctz_imm == 1) { |
| 2927 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2928 | } else { |
| 2929 | __ Asr(temp, dividend, 31); |
| 2930 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2931 | } |
| 2932 | __ add(out, temp, ShifterOperand(dividend)); |
| 2933 | |
| 2934 | if (instruction->IsDiv()) { |
| 2935 | __ Asr(out, out, ctz_imm); |
| 2936 | if (imm < 0) { |
| 2937 | __ rsb(out, out, ShifterOperand(0)); |
| 2938 | } |
| 2939 | } else { |
| 2940 | __ ubfx(out, out, 0, ctz_imm); |
| 2941 | __ sub(out, out, ShifterOperand(temp)); |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2946 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2947 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2948 | |
| 2949 | LocationSummary* locations = instruction->GetLocations(); |
| 2950 | Location second = locations->InAt(1); |
| 2951 | DCHECK(second.IsConstant()); |
| 2952 | |
| 2953 | Register out = locations->Out().AsRegister<Register>(); |
| 2954 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2955 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2956 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2957 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2958 | |
| 2959 | int64_t magic; |
| 2960 | int shift; |
| 2961 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2962 | |
| 2963 | __ LoadImmediate(temp1, magic); |
| 2964 | __ smull(temp2, temp1, dividend, temp1); |
| 2965 | |
| 2966 | if (imm > 0 && magic < 0) { |
| 2967 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2968 | } else if (imm < 0 && magic > 0) { |
| 2969 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2970 | } |
| 2971 | |
| 2972 | if (shift != 0) { |
| 2973 | __ Asr(temp1, temp1, shift); |
| 2974 | } |
| 2975 | |
| 2976 | if (instruction->IsDiv()) { |
| 2977 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2978 | } else { |
| 2979 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2980 | // TODO: Strength reduction for mls. |
| 2981 | __ LoadImmediate(temp2, imm); |
| 2982 | __ mls(out, temp1, temp2, dividend); |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2987 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2988 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2989 | |
| 2990 | LocationSummary* locations = instruction->GetLocations(); |
| 2991 | Location second = locations->InAt(1); |
| 2992 | DCHECK(second.IsConstant()); |
| 2993 | |
| 2994 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2995 | if (imm == 0) { |
| 2996 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2997 | } else if (imm == 1 || imm == -1) { |
| 2998 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2999 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3000 | DivRemByPowerOfTwo(instruction); |
| 3001 | } else { |
| 3002 | DCHECK(imm <= -2 || imm >= 2); |
| 3003 | GenerateDivRemWithAnyConstant(instruction); |
| 3004 | } |
| 3005 | } |
| 3006 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3007 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3008 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3009 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3010 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3011 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3012 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3013 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3014 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3015 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3016 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3017 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3020 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3021 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3022 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3023 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3024 | if (div->InputAt(1)->IsConstant()) { |
| 3025 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3026 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3027 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3028 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3029 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3030 | // No temp register required. |
| 3031 | } else { |
| 3032 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3033 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3034 | locations->AddTemp(Location::RequiresRegister()); |
| 3035 | } |
| 3036 | } |
| 3037 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3039 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3040 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3041 | } else { |
| 3042 | InvokeRuntimeCallingConvention calling_convention; |
| 3043 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3044 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3045 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3046 | // we only need the former. |
| 3047 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3048 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3049 | break; |
| 3050 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3051 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3052 | InvokeRuntimeCallingConvention calling_convention; |
| 3053 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3054 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3055 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3056 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3057 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3058 | break; |
| 3059 | } |
| 3060 | case Primitive::kPrimFloat: |
| 3061 | case Primitive::kPrimDouble: { |
| 3062 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3063 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3064 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3065 | break; |
| 3066 | } |
| 3067 | |
| 3068 | default: |
| 3069 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3074 | LocationSummary* locations = div->GetLocations(); |
| 3075 | Location out = locations->Out(); |
| 3076 | Location first = locations->InAt(0); |
| 3077 | Location second = locations->InAt(1); |
| 3078 | |
| 3079 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3080 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3081 | if (second.IsConstant()) { |
| 3082 | GenerateDivRemConstantIntegral(div); |
| 3083 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3084 | __ sdiv(out.AsRegister<Register>(), |
| 3085 | first.AsRegister<Register>(), |
| 3086 | second.AsRegister<Register>()); |
| 3087 | } else { |
| 3088 | InvokeRuntimeCallingConvention calling_convention; |
| 3089 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3090 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3091 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3092 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3093 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3094 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3095 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3096 | break; |
| 3097 | } |
| 3098 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3099 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3100 | InvokeRuntimeCallingConvention calling_convention; |
| 3101 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3102 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3103 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3104 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3105 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3106 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3107 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3108 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3109 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | |
| 3113 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3114 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3115 | first.AsFpuRegister<SRegister>(), |
| 3116 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
| 3120 | case Primitive::kPrimDouble: { |
| 3121 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3122 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3123 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3124 | break; |
| 3125 | } |
| 3126 | |
| 3127 | default: |
| 3128 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3129 | } |
| 3130 | } |
| 3131 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3132 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3133 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3134 | |
| 3135 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3136 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3137 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3138 | // sdiv will be replaced by other instruction sequence. |
| 3139 | call_kind = LocationSummary::kNoCall; |
| 3140 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3141 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3142 | // Have hardware divide instruction for int, do it with three instructions. |
| 3143 | call_kind = LocationSummary::kNoCall; |
| 3144 | } |
| 3145 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3146 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3147 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3148 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3149 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3150 | if (rem->InputAt(1)->IsConstant()) { |
| 3151 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3152 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3153 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3154 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3155 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3156 | // No temp register required. |
| 3157 | } else { |
| 3158 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3159 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3160 | locations->AddTemp(Location::RequiresRegister()); |
| 3161 | } |
| 3162 | } |
| 3163 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3164 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3165 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3166 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3167 | locations->AddTemp(Location::RequiresRegister()); |
| 3168 | } else { |
| 3169 | InvokeRuntimeCallingConvention calling_convention; |
| 3170 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3171 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3172 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3173 | // we only need the latter. |
| 3174 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3175 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3176 | break; |
| 3177 | } |
| 3178 | case Primitive::kPrimLong: { |
| 3179 | InvokeRuntimeCallingConvention calling_convention; |
| 3180 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3181 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3182 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3183 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3184 | // The runtime helper puts the output in R2,R3. |
| 3185 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3186 | break; |
| 3187 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3188 | case Primitive::kPrimFloat: { |
| 3189 | InvokeRuntimeCallingConvention calling_convention; |
| 3190 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3191 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3192 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3193 | break; |
| 3194 | } |
| 3195 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3196 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3197 | InvokeRuntimeCallingConvention calling_convention; |
| 3198 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3199 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3200 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3201 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3202 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3203 | break; |
| 3204 | } |
| 3205 | |
| 3206 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3207 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3212 | LocationSummary* locations = rem->GetLocations(); |
| 3213 | Location out = locations->Out(); |
| 3214 | Location first = locations->InAt(0); |
| 3215 | Location second = locations->InAt(1); |
| 3216 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3217 | Primitive::Type type = rem->GetResultType(); |
| 3218 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3219 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3220 | if (second.IsConstant()) { |
| 3221 | GenerateDivRemConstantIntegral(rem); |
| 3222 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3223 | Register reg1 = first.AsRegister<Register>(); |
| 3224 | Register reg2 = second.AsRegister<Register>(); |
| 3225 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3226 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3227 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3228 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3229 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3230 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3231 | } else { |
| 3232 | InvokeRuntimeCallingConvention calling_convention; |
| 3233 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3234 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3235 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3236 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3237 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3238 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3239 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3240 | break; |
| 3241 | } |
| 3242 | |
| 3243 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3244 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3245 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3246 | break; |
| 3247 | } |
| 3248 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3249 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3250 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3251 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3252 | break; |
| 3253 | } |
| 3254 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3255 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3256 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3257 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3258 | break; |
| 3259 | } |
| 3260 | |
| 3261 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3262 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3263 | } |
| 3264 | } |
| 3265 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3266 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3267 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3268 | ? LocationSummary::kCallOnSlowPath |
| 3269 | : LocationSummary::kNoCall; |
| 3270 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3271 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3272 | if (instruction->HasUses()) { |
| 3273 | locations->SetOut(Location::SameAsFirstInput()); |
| 3274 | } |
| 3275 | } |
| 3276 | |
| 3277 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3278 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3279 | codegen_->AddSlowPath(slow_path); |
| 3280 | |
| 3281 | LocationSummary* locations = instruction->GetLocations(); |
| 3282 | Location value = locations->InAt(0); |
| 3283 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3284 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3285 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3286 | case Primitive::kPrimByte: |
| 3287 | case Primitive::kPrimChar: |
| 3288 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3289 | case Primitive::kPrimInt: { |
| 3290 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3291 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3292 | } else { |
| 3293 | DCHECK(value.IsConstant()) << value; |
| 3294 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3295 | __ b(slow_path->GetEntryLabel()); |
| 3296 | } |
| 3297 | } |
| 3298 | break; |
| 3299 | } |
| 3300 | case Primitive::kPrimLong: { |
| 3301 | if (value.IsRegisterPair()) { |
| 3302 | __ orrs(IP, |
| 3303 | value.AsRegisterPairLow<Register>(), |
| 3304 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3305 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3306 | } else { |
| 3307 | DCHECK(value.IsConstant()) << value; |
| 3308 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3309 | __ b(slow_path->GetEntryLabel()); |
| 3310 | } |
| 3311 | } |
| 3312 | break; |
| 3313 | default: |
| 3314 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3315 | } |
| 3316 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3319 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3320 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3321 | Location rhs = locations->InAt(1); |
| 3322 | Register out = locations->Out().AsRegister<Register>(); |
| 3323 | |
| 3324 | if (rhs.IsConstant()) { |
| 3325 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3326 | // so map all rotations to a +ve. equivalent in that range. |
| 3327 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3328 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3329 | if (rot) { |
| 3330 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3331 | // (e.g. left by 2 bits == right by 30.) |
| 3332 | __ Ror(out, in, rot); |
| 3333 | } else if (out != in) { |
| 3334 | __ Mov(out, in); |
| 3335 | } |
| 3336 | } else { |
| 3337 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3342 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3343 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3344 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3345 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3346 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3347 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3348 | Location rhs = locations->InAt(1); |
| 3349 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3350 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3351 | |
| 3352 | if (rhs.IsConstant()) { |
| 3353 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3354 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3355 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3356 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3357 | // logic below to a simple pair of binary orr. |
| 3358 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3359 | if (rot >= kArmBitsPerWord) { |
| 3360 | rot -= kArmBitsPerWord; |
| 3361 | std::swap(in_reg_hi, in_reg_lo); |
| 3362 | } |
| 3363 | // Rotate, or mov to out for zero or word size rotations. |
| 3364 | if (rot != 0u) { |
| 3365 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3366 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3367 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3368 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3369 | } else { |
| 3370 | __ Mov(out_reg_lo, in_reg_lo); |
| 3371 | __ Mov(out_reg_hi, in_reg_hi); |
| 3372 | } |
| 3373 | } else { |
| 3374 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3375 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3376 | Label end; |
| 3377 | Label shift_by_32_plus_shift_right; |
| 3378 | |
| 3379 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3380 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3381 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3382 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3383 | |
| 3384 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3385 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3386 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3387 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3388 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3389 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3390 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3391 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3392 | __ b(&end); |
| 3393 | |
| 3394 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3395 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3396 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3397 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3398 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3399 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3400 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3401 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3402 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3403 | |
| 3404 | __ Bind(&end); |
| 3405 | } |
| 3406 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3407 | |
| 3408 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3409 | LocationSummary* locations = |
| 3410 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3411 | switch (ror->GetResultType()) { |
| 3412 | case Primitive::kPrimInt: { |
| 3413 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3414 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3415 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3416 | break; |
| 3417 | } |
| 3418 | case Primitive::kPrimLong: { |
| 3419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3420 | if (ror->InputAt(1)->IsConstant()) { |
| 3421 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3422 | } else { |
| 3423 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3424 | locations->AddTemp(Location::RequiresRegister()); |
| 3425 | locations->AddTemp(Location::RequiresRegister()); |
| 3426 | } |
| 3427 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3428 | break; |
| 3429 | } |
| 3430 | default: |
| 3431 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3432 | } |
| 3433 | } |
| 3434 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3435 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3436 | LocationSummary* locations = ror->GetLocations(); |
| 3437 | Primitive::Type type = ror->GetResultType(); |
| 3438 | switch (type) { |
| 3439 | case Primitive::kPrimInt: { |
| 3440 | HandleIntegerRotate(locations); |
| 3441 | break; |
| 3442 | } |
| 3443 | case Primitive::kPrimLong: { |
| 3444 | HandleLongRotate(locations); |
| 3445 | break; |
| 3446 | } |
| 3447 | default: |
| 3448 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3449 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3453 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3454 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3455 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3456 | LocationSummary* locations = |
| 3457 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3458 | |
| 3459 | switch (op->GetResultType()) { |
| 3460 | case Primitive::kPrimInt: { |
| 3461 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3462 | if (op->InputAt(1)->IsConstant()) { |
| 3463 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3464 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3465 | } else { |
| 3466 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3467 | // Make the output overlap, as it will be used to hold the masked |
| 3468 | // second input. |
| 3469 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3470 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| 3473 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3474 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3475 | if (op->InputAt(1)->IsConstant()) { |
| 3476 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3477 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3478 | // don't clash with high registers which the register allocator currently guarantees. |
| 3479 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3480 | } else { |
| 3481 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3482 | locations->AddTemp(Location::RequiresRegister()); |
| 3483 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3484 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3485 | break; |
| 3486 | } |
| 3487 | default: |
| 3488 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3493 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3494 | |
| 3495 | LocationSummary* locations = op->GetLocations(); |
| 3496 | Location out = locations->Out(); |
| 3497 | Location first = locations->InAt(0); |
| 3498 | Location second = locations->InAt(1); |
| 3499 | |
| 3500 | Primitive::Type type = op->GetResultType(); |
| 3501 | switch (type) { |
| 3502 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3503 | Register out_reg = out.AsRegister<Register>(); |
| 3504 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3505 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3506 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3507 | // 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] | 3508 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3509 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3510 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3511 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3512 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3513 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3514 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3515 | } |
| 3516 | } else { |
| 3517 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3518 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3519 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3520 | __ Mov(out_reg, first_reg); |
| 3521 | } else if (op->IsShl()) { |
| 3522 | __ Lsl(out_reg, first_reg, shift_value); |
| 3523 | } else if (op->IsShr()) { |
| 3524 | __ Asr(out_reg, first_reg, shift_value); |
| 3525 | } else { |
| 3526 | __ Lsr(out_reg, first_reg, shift_value); |
| 3527 | } |
| 3528 | } |
| 3529 | break; |
| 3530 | } |
| 3531 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3532 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3533 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3534 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3535 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3536 | Register low = first.AsRegisterPairLow<Register>(); |
| 3537 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3538 | if (second.IsRegister()) { |
| 3539 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3540 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3541 | Register second_reg = second.AsRegister<Register>(); |
| 3542 | |
| 3543 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3544 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3545 | // Shift the high part |
| 3546 | __ Lsl(o_h, high, o_l); |
| 3547 | // Shift the low part and `or` what overflew on the high part |
| 3548 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3549 | __ Lsr(temp, low, temp); |
| 3550 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3551 | // If the shift is > 32 bits, override the high part |
| 3552 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3553 | __ it(PL); |
| 3554 | __ Lsl(o_h, low, temp, PL); |
| 3555 | // Shift the low part |
| 3556 | __ Lsl(o_l, low, o_l); |
| 3557 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3558 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3559 | // Shift the low part |
| 3560 | __ Lsr(o_l, low, o_h); |
| 3561 | // Shift the high part and `or` what underflew on the low part |
| 3562 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3563 | __ Lsl(temp, high, temp); |
| 3564 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3565 | // If the shift is > 32 bits, override the low part |
| 3566 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3567 | __ it(PL); |
| 3568 | __ Asr(o_l, high, temp, PL); |
| 3569 | // Shift the high part |
| 3570 | __ Asr(o_h, high, o_h); |
| 3571 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3572 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3573 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3574 | __ Lsr(o_l, low, o_h); |
| 3575 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3576 | __ Lsl(temp, high, temp); |
| 3577 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3578 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3579 | __ it(PL); |
| 3580 | __ Lsr(o_l, high, temp, PL); |
| 3581 | __ Lsr(o_h, high, o_h); |
| 3582 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3583 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3584 | // Register allocator doesn't create partial overlap. |
| 3585 | DCHECK_NE(o_l, high); |
| 3586 | DCHECK_NE(o_h, low); |
| 3587 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3588 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3589 | if (shift_value > 32) { |
| 3590 | if (op->IsShl()) { |
| 3591 | __ Lsl(o_h, low, shift_value - 32); |
| 3592 | __ LoadImmediate(o_l, 0); |
| 3593 | } else if (op->IsShr()) { |
| 3594 | __ Asr(o_l, high, shift_value - 32); |
| 3595 | __ Asr(o_h, high, 31); |
| 3596 | } else { |
| 3597 | __ Lsr(o_l, high, shift_value - 32); |
| 3598 | __ LoadImmediate(o_h, 0); |
| 3599 | } |
| 3600 | } else if (shift_value == 32) { |
| 3601 | if (op->IsShl()) { |
| 3602 | __ mov(o_h, ShifterOperand(low)); |
| 3603 | __ LoadImmediate(o_l, 0); |
| 3604 | } else if (op->IsShr()) { |
| 3605 | __ mov(o_l, ShifterOperand(high)); |
| 3606 | __ Asr(o_h, high, 31); |
| 3607 | } else { |
| 3608 | __ mov(o_l, ShifterOperand(high)); |
| 3609 | __ LoadImmediate(o_h, 0); |
| 3610 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3611 | } else if (shift_value == 1) { |
| 3612 | if (op->IsShl()) { |
| 3613 | __ Lsls(o_l, low, 1); |
| 3614 | __ adc(o_h, high, ShifterOperand(high)); |
| 3615 | } else if (op->IsShr()) { |
| 3616 | __ Asrs(o_h, high, 1); |
| 3617 | __ Rrx(o_l, low); |
| 3618 | } else { |
| 3619 | __ Lsrs(o_h, high, 1); |
| 3620 | __ Rrx(o_l, low); |
| 3621 | } |
| 3622 | } else { |
| 3623 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3624 | if (op->IsShl()) { |
| 3625 | __ Lsl(o_h, high, shift_value); |
| 3626 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3627 | __ Lsl(o_l, low, shift_value); |
| 3628 | } else if (op->IsShr()) { |
| 3629 | __ Lsr(o_l, low, shift_value); |
| 3630 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3631 | __ Asr(o_h, high, shift_value); |
| 3632 | } else { |
| 3633 | __ Lsr(o_l, low, shift_value); |
| 3634 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3635 | __ Lsr(o_h, high, shift_value); |
| 3636 | } |
| 3637 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3638 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3639 | break; |
| 3640 | } |
| 3641 | default: |
| 3642 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3643 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3644 | } |
| 3645 | } |
| 3646 | |
| 3647 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3648 | HandleShift(shl); |
| 3649 | } |
| 3650 | |
| 3651 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3652 | HandleShift(shl); |
| 3653 | } |
| 3654 | |
| 3655 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3656 | HandleShift(shr); |
| 3657 | } |
| 3658 | |
| 3659 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3660 | HandleShift(shr); |
| 3661 | } |
| 3662 | |
| 3663 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3664 | HandleShift(ushr); |
| 3665 | } |
| 3666 | |
| 3667 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3668 | HandleShift(ushr); |
| 3669 | } |
| 3670 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3671 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3672 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3673 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3674 | if (instruction->IsStringAlloc()) { |
| 3675 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3676 | } else { |
| 3677 | InvokeRuntimeCallingConvention calling_convention; |
| 3678 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3679 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3680 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3681 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3685 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3686 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3687 | if (instruction->IsStringAlloc()) { |
| 3688 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3689 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3690 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3691 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3692 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3693 | __ blx(LR); |
| 3694 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3695 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3696 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3697 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3698 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3699 | } |
| 3700 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3701 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3702 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3703 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3704 | InvokeRuntimeCallingConvention calling_convention; |
| 3705 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3706 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3707 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3708 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3712 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3713 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3714 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3715 | // of poisoning the reference. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3716 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3717 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3718 | } |
| 3719 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3720 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3721 | LocationSummary* locations = |
| 3722 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3723 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3724 | if (location.IsStackSlot()) { |
| 3725 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3726 | } else if (location.IsDoubleStackSlot()) { |
| 3727 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3728 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3729 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3730 | } |
| 3731 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3732 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3733 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3734 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3738 | LocationSummary* locations = |
| 3739 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3740 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3741 | } |
| 3742 | |
| 3743 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3744 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3745 | } |
| 3746 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3747 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3748 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3749 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3750 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3751 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3752 | } |
| 3753 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3754 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3755 | LocationSummary* locations = not_->GetLocations(); |
| 3756 | Location out = locations->Out(); |
| 3757 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3758 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3759 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3760 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3761 | break; |
| 3762 | |
| 3763 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3764 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3765 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3766 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3767 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3768 | break; |
| 3769 | |
| 3770 | default: |
| 3771 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3772 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3773 | } |
| 3774 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3775 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3776 | LocationSummary* locations = |
| 3777 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3778 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3779 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3780 | } |
| 3781 | |
| 3782 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3783 | LocationSummary* locations = bool_not->GetLocations(); |
| 3784 | Location out = locations->Out(); |
| 3785 | Location in = locations->InAt(0); |
| 3786 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3787 | } |
| 3788 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3789 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3790 | LocationSummary* locations = |
| 3791 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3792 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3793 | case Primitive::kPrimBoolean: |
| 3794 | case Primitive::kPrimByte: |
| 3795 | case Primitive::kPrimShort: |
| 3796 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3797 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3798 | case Primitive::kPrimLong: { |
| 3799 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3800 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3801 | // Output overlaps because it is written before doing the low comparison. |
| 3802 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3803 | break; |
| 3804 | } |
| 3805 | case Primitive::kPrimFloat: |
| 3806 | case Primitive::kPrimDouble: { |
| 3807 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3808 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3809 | locations->SetOut(Location::RequiresRegister()); |
| 3810 | break; |
| 3811 | } |
| 3812 | default: |
| 3813 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3814 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3818 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3819 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3820 | Location left = locations->InAt(0); |
| 3821 | Location right = locations->InAt(1); |
| 3822 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3823 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3824 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3825 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3826 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3827 | case Primitive::kPrimBoolean: |
| 3828 | case Primitive::kPrimByte: |
| 3829 | case Primitive::kPrimShort: |
| 3830 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3831 | case Primitive::kPrimInt: { |
| 3832 | __ LoadImmediate(out, 0); |
| 3833 | __ cmp(left.AsRegister<Register>(), |
| 3834 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3835 | less_cond = LT; |
| 3836 | break; |
| 3837 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3838 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3839 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3840 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3841 | __ b(&less, LT); |
| 3842 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3843 | // 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] | 3844 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3845 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3846 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3847 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3848 | break; |
| 3849 | } |
| 3850 | case Primitive::kPrimFloat: |
| 3851 | case Primitive::kPrimDouble: { |
| 3852 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3853 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3854 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3855 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3856 | break; |
| 3857 | } |
| 3858 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3859 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3860 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3861 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3862 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3863 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3864 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3865 | |
| 3866 | __ Bind(&greater); |
| 3867 | __ LoadImmediate(out, 1); |
| 3868 | __ b(&done); |
| 3869 | |
| 3870 | __ Bind(&less); |
| 3871 | __ LoadImmediate(out, -1); |
| 3872 | |
| 3873 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3874 | } |
| 3875 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3876 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3877 | LocationSummary* locations = |
| 3878 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3879 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3880 | locations->SetInAt(i, Location::Any()); |
| 3881 | } |
| 3882 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3883 | } |
| 3884 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3885 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3886 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3887 | } |
| 3888 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3889 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3890 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3891 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3892 | switch (kind) { |
| 3893 | case MemBarrierKind::kAnyStore: |
| 3894 | case MemBarrierKind::kLoadAny: |
| 3895 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3896 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3897 | break; |
| 3898 | } |
| 3899 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3900 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3901 | break; |
| 3902 | } |
| 3903 | default: |
| 3904 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3905 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3906 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3910 | uint32_t offset, |
| 3911 | Register out_lo, |
| 3912 | Register out_hi) { |
| 3913 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3914 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3915 | // `offset` into `out_lo` does not clutter `addr`. |
| 3916 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3917 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3918 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3919 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3920 | } |
| 3921 | __ ldrexd(out_lo, out_hi, addr); |
| 3922 | } |
| 3923 | |
| 3924 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3925 | uint32_t offset, |
| 3926 | Register value_lo, |
| 3927 | Register value_hi, |
| 3928 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3929 | Register temp2, |
| 3930 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3931 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3932 | if (offset != 0) { |
| 3933 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3934 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3935 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3936 | } |
| 3937 | __ Bind(&fail); |
| 3938 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3939 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3940 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3941 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3942 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3943 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3947 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3948 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3949 | LocationSummary* locations = |
| 3950 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3951 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3952 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3953 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3954 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3955 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3956 | } else { |
| 3957 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3958 | } |
| 3959 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3960 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3961 | bool generate_volatile = field_info.IsVolatile() |
| 3962 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3963 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3964 | bool needs_write_barrier = |
| 3965 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3966 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3967 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3968 | if (needs_write_barrier) { |
| 3969 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3970 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3971 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3972 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3973 | // - registers need to be consecutive |
| 3974 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3975 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3976 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3977 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3978 | |
| 3979 | locations->AddTemp(Location::RequiresRegister()); |
| 3980 | locations->AddTemp(Location::RequiresRegister()); |
| 3981 | if (field_type == Primitive::kPrimDouble) { |
| 3982 | // For doubles we need two more registers to copy the value. |
| 3983 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3984 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3985 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3986 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3987 | } |
| 3988 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3989 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3990 | const FieldInfo& field_info, |
| 3991 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3992 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3993 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3994 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3995 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3996 | Location value = locations->InAt(1); |
| 3997 | |
| 3998 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3999 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4000 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4001 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4002 | bool needs_write_barrier = |
| 4003 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4004 | |
| 4005 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4006 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4007 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4008 | |
| 4009 | switch (field_type) { |
| 4010 | case Primitive::kPrimBoolean: |
| 4011 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4012 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4013 | break; |
| 4014 | } |
| 4015 | |
| 4016 | case Primitive::kPrimShort: |
| 4017 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4018 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4019 | break; |
| 4020 | } |
| 4021 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4022 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4023 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4024 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4025 | // Note that in the case where `value` is a null reference, |
| 4026 | // we do not enter this block, as a null reference does not |
| 4027 | // need poisoning. |
| 4028 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4029 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4030 | __ Mov(temp, value.AsRegister<Register>()); |
| 4031 | __ PoisonHeapReference(temp); |
| 4032 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4033 | } else { |
| 4034 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4035 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4036 | break; |
| 4037 | } |
| 4038 | |
| 4039 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4040 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4041 | GenerateWideAtomicStore(base, offset, |
| 4042 | value.AsRegisterPairLow<Register>(), |
| 4043 | value.AsRegisterPairHigh<Register>(), |
| 4044 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4045 | locations->GetTemp(1).AsRegister<Register>(), |
| 4046 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4047 | } else { |
| 4048 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4049 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4050 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4051 | break; |
| 4052 | } |
| 4053 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4054 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4055 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4056 | break; |
| 4057 | } |
| 4058 | |
| 4059 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4060 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4061 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4062 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4063 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4064 | |
| 4065 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4066 | |
| 4067 | GenerateWideAtomicStore(base, offset, |
| 4068 | value_reg_lo, |
| 4069 | value_reg_hi, |
| 4070 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4071 | locations->GetTemp(3).AsRegister<Register>(), |
| 4072 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4073 | } else { |
| 4074 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4075 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4076 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4077 | break; |
| 4078 | } |
| 4079 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4080 | case Primitive::kPrimVoid: |
| 4081 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4082 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4083 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4084 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4085 | // Longs and doubles are handled in the switch. |
| 4086 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4087 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4088 | } |
| 4089 | |
| 4090 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4091 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4092 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4093 | codegen_->MarkGCCard( |
| 4094 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4095 | } |
| 4096 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4097 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4098 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4099 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4100 | } |
| 4101 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4102 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4103 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4104 | |
| 4105 | bool object_field_get_with_read_barrier = |
| 4106 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4107 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4108 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4109 | object_field_get_with_read_barrier ? |
| 4110 | LocationSummary::kCallOnSlowPath : |
| 4111 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4112 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4113 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 4114 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4115 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4116 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4117 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4118 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4119 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4120 | // The output overlaps in case of volatile long: we don't want the |
| 4121 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4122 | // object's location. Likewise, in the case of an object field get |
| 4123 | // with read barriers enabled, we do not want the load to overwrite |
| 4124 | // the object's location, as we need it to emit the read barrier. |
| 4125 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4126 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4127 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4128 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4129 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4130 | } else { |
| 4131 | locations->SetOut(Location::RequiresRegister(), |
| 4132 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4133 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4134 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4135 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4136 | // - registers need to be consecutive |
| 4137 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4138 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4139 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4140 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4141 | locations->AddTemp(Location::RequiresRegister()); |
| 4142 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4143 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4144 | // We need a temporary register for the read barrier marking slow |
| 4145 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4146 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4147 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4148 | } |
| 4149 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4150 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4151 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4152 | << input->GetType(); |
| 4153 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4154 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4155 | return Location::ConstantLocation(input->AsConstant()); |
| 4156 | } else { |
| 4157 | return Location::RequiresFpuRegister(); |
| 4158 | } |
| 4159 | } |
| 4160 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4161 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4162 | Opcode opcode) { |
| 4163 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4164 | if (constant->IsConstant() && |
| 4165 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4166 | return Location::ConstantLocation(constant->AsConstant()); |
| 4167 | } |
| 4168 | return Location::RequiresRegister(); |
| 4169 | } |
| 4170 | |
| 4171 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4172 | Opcode opcode) { |
| 4173 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4174 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4175 | Opcode high_opcode = opcode; |
| 4176 | SetCc low_set_cc = kCcDontCare; |
| 4177 | switch (opcode) { |
| 4178 | case SUB: |
| 4179 | // Flip the operation to an ADD. |
| 4180 | value = -value; |
| 4181 | opcode = ADD; |
| 4182 | FALLTHROUGH_INTENDED; |
| 4183 | case ADD: |
| 4184 | if (Low32Bits(value) == 0u) { |
| 4185 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4186 | } |
| 4187 | high_opcode = ADC; |
| 4188 | low_set_cc = kCcSet; |
| 4189 | break; |
| 4190 | default: |
| 4191 | break; |
| 4192 | } |
| 4193 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4194 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4195 | } else { |
| 4196 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4197 | } |
| 4198 | } |
| 4199 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4200 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4201 | Opcode opcode, |
| 4202 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4203 | ShifterOperand so; |
| 4204 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4205 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4206 | return true; |
| 4207 | } |
| 4208 | Opcode neg_opcode = kNoOperand; |
| 4209 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4210 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4211 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4212 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4213 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4214 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4215 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4216 | default: |
| 4217 | return false; |
| 4218 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4219 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4220 | } |
| 4221 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4222 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4223 | const FieldInfo& field_info) { |
| 4224 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4225 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4227 | Location base_loc = locations->InAt(0); |
| 4228 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4229 | Location out = locations->Out(); |
| 4230 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4231 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4232 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4233 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4234 | |
| 4235 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4236 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4237 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4238 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4239 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4240 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4241 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4242 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4243 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4244 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4245 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4246 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4247 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4248 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4249 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4250 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4251 | |
| 4252 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4253 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4254 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4255 | |
| 4256 | case Primitive::kPrimNot: { |
| 4257 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4258 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4259 | Location temp_loc = locations->GetTemp(0); |
| 4260 | // Note that a potential implicit null check is handled in this |
| 4261 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4262 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4263 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4264 | if (is_volatile) { |
| 4265 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4266 | } |
| 4267 | } else { |
| 4268 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4269 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4270 | if (is_volatile) { |
| 4271 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4272 | } |
| 4273 | // If read barriers are enabled, emit read barriers other than |
| 4274 | // Baker's using a slow path (and also unpoison the loaded |
| 4275 | // reference, if heap poisoning is enabled). |
| 4276 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4277 | } |
| 4278 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4279 | } |
| 4280 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4281 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4282 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4283 | GenerateWideAtomicLoad(base, offset, |
| 4284 | out.AsRegisterPairLow<Register>(), |
| 4285 | out.AsRegisterPairHigh<Register>()); |
| 4286 | } else { |
| 4287 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4288 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4289 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4290 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4291 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4292 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4293 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4294 | |
| 4295 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4296 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4297 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4298 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4299 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4300 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4301 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4302 | __ vmovdrr(out_reg, lo, hi); |
| 4303 | } else { |
| 4304 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4306 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4307 | break; |
| 4308 | } |
| 4309 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4310 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4311 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4312 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4313 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4314 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4315 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4316 | // Potential implicit null checks, in the case of reference or |
| 4317 | // double fields, are handled in the previous switch statement. |
| 4318 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4319 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4320 | } |
| 4321 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4322 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4323 | if (field_type == Primitive::kPrimNot) { |
| 4324 | // Memory barriers, in the case of references, are also handled |
| 4325 | // in the previous switch statement. |
| 4326 | } else { |
| 4327 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4328 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4329 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4333 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4334 | } |
| 4335 | |
| 4336 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4337 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4341 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4342 | } |
| 4343 | |
| 4344 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4345 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4346 | } |
| 4347 | |
| 4348 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4349 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4350 | } |
| 4351 | |
| 4352 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4353 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4354 | } |
| 4355 | |
| 4356 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4357 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4358 | } |
| 4359 | |
| 4360 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4361 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4362 | } |
| 4363 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4364 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4365 | HUnresolvedInstanceFieldGet* instruction) { |
| 4366 | FieldAccessCallingConventionARM calling_convention; |
| 4367 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4368 | instruction, instruction->GetFieldType(), calling_convention); |
| 4369 | } |
| 4370 | |
| 4371 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4372 | HUnresolvedInstanceFieldGet* instruction) { |
| 4373 | FieldAccessCallingConventionARM calling_convention; |
| 4374 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4375 | instruction->GetFieldType(), |
| 4376 | instruction->GetFieldIndex(), |
| 4377 | instruction->GetDexPc(), |
| 4378 | calling_convention); |
| 4379 | } |
| 4380 | |
| 4381 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4382 | HUnresolvedInstanceFieldSet* instruction) { |
| 4383 | FieldAccessCallingConventionARM calling_convention; |
| 4384 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4385 | instruction, instruction->GetFieldType(), calling_convention); |
| 4386 | } |
| 4387 | |
| 4388 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4389 | HUnresolvedInstanceFieldSet* instruction) { |
| 4390 | FieldAccessCallingConventionARM calling_convention; |
| 4391 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4392 | instruction->GetFieldType(), |
| 4393 | instruction->GetFieldIndex(), |
| 4394 | instruction->GetDexPc(), |
| 4395 | calling_convention); |
| 4396 | } |
| 4397 | |
| 4398 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4399 | HUnresolvedStaticFieldGet* instruction) { |
| 4400 | FieldAccessCallingConventionARM calling_convention; |
| 4401 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4402 | instruction, instruction->GetFieldType(), calling_convention); |
| 4403 | } |
| 4404 | |
| 4405 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4406 | HUnresolvedStaticFieldGet* instruction) { |
| 4407 | FieldAccessCallingConventionARM calling_convention; |
| 4408 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4409 | instruction->GetFieldType(), |
| 4410 | instruction->GetFieldIndex(), |
| 4411 | instruction->GetDexPc(), |
| 4412 | calling_convention); |
| 4413 | } |
| 4414 | |
| 4415 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4416 | HUnresolvedStaticFieldSet* instruction) { |
| 4417 | FieldAccessCallingConventionARM calling_convention; |
| 4418 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4419 | instruction, instruction->GetFieldType(), calling_convention); |
| 4420 | } |
| 4421 | |
| 4422 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4423 | HUnresolvedStaticFieldSet* instruction) { |
| 4424 | FieldAccessCallingConventionARM calling_convention; |
| 4425 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4426 | instruction->GetFieldType(), |
| 4427 | instruction->GetFieldIndex(), |
| 4428 | instruction->GetDexPc(), |
| 4429 | calling_convention); |
| 4430 | } |
| 4431 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4432 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 3b7537b | 2016-09-13 11:56:01 +0000 | [diff] [blame] | 4433 | codegen_->CreateNullCheckLocations(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4434 | } |
| 4435 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4436 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4437 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4438 | return; |
| 4439 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4440 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4441 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4442 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4443 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4444 | } |
| 4445 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4446 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4447 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4448 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4449 | |
| 4450 | LocationSummary* locations = instruction->GetLocations(); |
| 4451 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4452 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4453 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4454 | } |
| 4455 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4456 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4457 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4460 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4461 | switch (type) { |
| 4462 | case Primitive::kPrimNot: |
| 4463 | return kLoadWord; |
| 4464 | case Primitive::kPrimBoolean: |
| 4465 | return kLoadUnsignedByte; |
| 4466 | case Primitive::kPrimByte: |
| 4467 | return kLoadSignedByte; |
| 4468 | case Primitive::kPrimChar: |
| 4469 | return kLoadUnsignedHalfword; |
| 4470 | case Primitive::kPrimShort: |
| 4471 | return kLoadSignedHalfword; |
| 4472 | case Primitive::kPrimInt: |
| 4473 | return kLoadWord; |
| 4474 | case Primitive::kPrimLong: |
| 4475 | return kLoadWordPair; |
| 4476 | case Primitive::kPrimFloat: |
| 4477 | return kLoadSWord; |
| 4478 | case Primitive::kPrimDouble: |
| 4479 | return kLoadDWord; |
| 4480 | default: |
| 4481 | LOG(FATAL) << "Unreachable type " << type; |
| 4482 | UNREACHABLE(); |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4487 | switch (type) { |
| 4488 | case Primitive::kPrimNot: |
| 4489 | return kStoreWord; |
| 4490 | case Primitive::kPrimBoolean: |
| 4491 | case Primitive::kPrimByte: |
| 4492 | return kStoreByte; |
| 4493 | case Primitive::kPrimChar: |
| 4494 | case Primitive::kPrimShort: |
| 4495 | return kStoreHalfword; |
| 4496 | case Primitive::kPrimInt: |
| 4497 | return kStoreWord; |
| 4498 | case Primitive::kPrimLong: |
| 4499 | return kStoreWordPair; |
| 4500 | case Primitive::kPrimFloat: |
| 4501 | return kStoreSWord; |
| 4502 | case Primitive::kPrimDouble: |
| 4503 | return kStoreDWord; |
| 4504 | default: |
| 4505 | LOG(FATAL) << "Unreachable type " << type; |
| 4506 | UNREACHABLE(); |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4511 | Location out_loc, |
| 4512 | Register base, |
| 4513 | Register reg_offset, |
| 4514 | Condition cond) { |
| 4515 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4516 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4517 | |
| 4518 | switch (type) { |
| 4519 | case Primitive::kPrimByte: |
| 4520 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4521 | break; |
| 4522 | case Primitive::kPrimBoolean: |
| 4523 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4524 | break; |
| 4525 | case Primitive::kPrimShort: |
| 4526 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4527 | break; |
| 4528 | case Primitive::kPrimChar: |
| 4529 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4530 | break; |
| 4531 | case Primitive::kPrimNot: |
| 4532 | case Primitive::kPrimInt: |
| 4533 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4534 | break; |
| 4535 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4536 | case Primitive::kPrimLong: |
| 4537 | case Primitive::kPrimFloat: |
| 4538 | case Primitive::kPrimDouble: |
| 4539 | default: |
| 4540 | LOG(FATAL) << "Unreachable type " << type; |
| 4541 | UNREACHABLE(); |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4546 | Location loc, |
| 4547 | Register base, |
| 4548 | Register reg_offset, |
| 4549 | Condition cond) { |
| 4550 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4551 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4552 | |
| 4553 | switch (type) { |
| 4554 | case Primitive::kPrimByte: |
| 4555 | case Primitive::kPrimBoolean: |
| 4556 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4557 | break; |
| 4558 | case Primitive::kPrimShort: |
| 4559 | case Primitive::kPrimChar: |
| 4560 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4561 | break; |
| 4562 | case Primitive::kPrimNot: |
| 4563 | case Primitive::kPrimInt: |
| 4564 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4565 | break; |
| 4566 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4567 | case Primitive::kPrimLong: |
| 4568 | case Primitive::kPrimFloat: |
| 4569 | case Primitive::kPrimDouble: |
| 4570 | default: |
| 4571 | LOG(FATAL) << "Unreachable type " << type; |
| 4572 | UNREACHABLE(); |
| 4573 | } |
| 4574 | } |
| 4575 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4576 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4577 | bool object_array_get_with_read_barrier = |
| 4578 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4579 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4580 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4581 | object_array_get_with_read_barrier ? |
| 4582 | LocationSummary::kCallOnSlowPath : |
| 4583 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4584 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4585 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 4586 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4587 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4588 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4589 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4590 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4591 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4592 | // The output overlaps in the case of an object array get with |
| 4593 | // read barriers enabled: we do not want the move to overwrite the |
| 4594 | // array's location, as we need it to emit the read barrier. |
| 4595 | locations->SetOut( |
| 4596 | Location::RequiresRegister(), |
| 4597 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4598 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4599 | // We need a temporary register for the read barrier marking slow |
| 4600 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4601 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4602 | locations->AddTemp(Location::RequiresRegister()); |
| 4603 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4607 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4608 | Location obj_loc = locations->InAt(0); |
| 4609 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4611 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4612 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4613 | Primitive::Type type = instruction->GetType(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4614 | HInstruction* array_instr = instruction->GetArray(); |
| 4615 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4616 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4617 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4618 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4619 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4620 | case Primitive::kPrimBoolean: |
| 4621 | case Primitive::kPrimByte: |
| 4622 | case Primitive::kPrimShort: |
| 4623 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4624 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4625 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4626 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4627 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 4628 | |
| 4629 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4630 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4631 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4632 | Register temp = IP; |
| 4633 | |
| 4634 | if (has_intermediate_address) { |
| 4635 | // We do not need to compute the intermediate address from the array: the |
| 4636 | // input instruction has done it already. See the comment in |
| 4637 | // `TryExtractArrayAccessAddress()`. |
| 4638 | if (kIsDebugBuild) { |
| 4639 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4640 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4641 | } |
| 4642 | temp = obj; |
| 4643 | } else { |
| 4644 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4645 | } |
| 4646 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4647 | } |
| 4648 | break; |
| 4649 | } |
| 4650 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4651 | case Primitive::kPrimNot: { |
| 4652 | static_assert( |
| 4653 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4654 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4655 | // /* HeapReference<Object> */ out = |
| 4656 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4657 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4658 | Location temp = locations->GetTemp(0); |
| 4659 | // Note that a potential implicit null check is handled in this |
| 4660 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4661 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4662 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4663 | } else { |
| 4664 | Register out = out_loc.AsRegister<Register>(); |
| 4665 | if (index.IsConstant()) { |
| 4666 | size_t offset = |
| 4667 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4668 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4669 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4670 | // If read barriers are enabled, emit read barriers other than |
| 4671 | // Baker's using a slow path (and also unpoison the loaded |
| 4672 | // reference, if heap poisoning is enabled). |
| 4673 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4674 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4675 | Register temp = IP; |
| 4676 | |
| 4677 | if (has_intermediate_address) { |
| 4678 | // We do not need to compute the intermediate address from the array: the |
| 4679 | // input instruction has done it already. See the comment in |
| 4680 | // `TryExtractArrayAccessAddress()`. |
| 4681 | if (kIsDebugBuild) { |
| 4682 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4683 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4684 | } |
| 4685 | temp = obj; |
| 4686 | } else { |
| 4687 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4688 | } |
| 4689 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4690 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4691 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4692 | // If read barriers are enabled, emit read barriers other than |
| 4693 | // Baker's using a slow path (and also unpoison the loaded |
| 4694 | // reference, if heap poisoning is enabled). |
| 4695 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4696 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4697 | } |
| 4698 | } |
| 4699 | break; |
| 4700 | } |
| 4701 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4703 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4704 | size_t offset = |
| 4705 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4706 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4707 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4708 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4709 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4710 | } |
| 4711 | break; |
| 4712 | } |
| 4713 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4714 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4715 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4716 | if (index.IsConstant()) { |
| 4717 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4718 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4719 | } else { |
| 4720 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4721 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4722 | } |
| 4723 | break; |
| 4724 | } |
| 4725 | |
| 4726 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4727 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4728 | if (index.IsConstant()) { |
| 4729 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4730 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4731 | } else { |
| 4732 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4733 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4734 | } |
| 4735 | break; |
| 4736 | } |
| 4737 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4738 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4739 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4740 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4741 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4742 | |
| 4743 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4744 | // Potential implicit null checks, in the case of reference |
| 4745 | // arrays, are handled in the previous switch statement. |
| 4746 | } else { |
| 4747 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4748 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4752 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4753 | |
| 4754 | bool needs_write_barrier = |
| 4755 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4756 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4757 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4758 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4760 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4761 | LocationSummary::kCallOnSlowPath : |
| 4762 | LocationSummary::kNoCall); |
| 4763 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4764 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4765 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4766 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4767 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4768 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4769 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4770 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4771 | if (needs_write_barrier) { |
| 4772 | // Temporary registers for the write barrier. |
| 4773 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4774 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4775 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4779 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4780 | Location array_loc = locations->InAt(0); |
| 4781 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4782 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4783 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4784 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4785 | bool needs_write_barrier = |
| 4786 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4787 | uint32_t data_offset = |
| 4788 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 4789 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4790 | HInstruction* array_instr = instruction->GetArray(); |
| 4791 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 4792 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 4793 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4794 | |
| 4795 | switch (value_type) { |
| 4796 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4797 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4798 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4799 | case Primitive::kPrimChar: |
| 4800 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4801 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4802 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4803 | uint32_t full_offset = |
| 4804 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 4805 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 4806 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4807 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4808 | Register temp = IP; |
| 4809 | |
| 4810 | if (has_intermediate_address) { |
| 4811 | // We do not need to compute the intermediate address from the array: the |
| 4812 | // input instruction has done it already. See the comment in |
| 4813 | // `TryExtractArrayAccessAddress()`. |
| 4814 | if (kIsDebugBuild) { |
| 4815 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4816 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 4817 | } |
| 4818 | temp = array; |
| 4819 | } else { |
| 4820 | __ add(temp, array, ShifterOperand(data_offset)); |
| 4821 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4822 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4823 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4824 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4825 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4826 | } |
| 4827 | break; |
| 4828 | } |
| 4829 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4830 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4831 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4832 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 4833 | // See the comment in instruction_simplifier_shared.cc. |
| 4834 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4835 | |
| 4836 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4837 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4838 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4839 | size_t offset = |
| 4840 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4841 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4842 | } else { |
| 4843 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4844 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4845 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4846 | value_loc, |
| 4847 | IP, |
| 4848 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4849 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4850 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4851 | DCHECK(!needs_write_barrier); |
| 4852 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4853 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4854 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4855 | |
| 4856 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4857 | Location temp1_loc = locations->GetTemp(0); |
| 4858 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 4859 | Location temp2_loc = locations->GetTemp(1); |
| 4860 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4861 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4862 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4863 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4864 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4865 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4866 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4867 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4868 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4869 | codegen_->AddSlowPath(slow_path); |
| 4870 | if (instruction->GetValueCanBeNull()) { |
| 4871 | Label non_zero; |
| 4872 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4873 | if (index.IsConstant()) { |
| 4874 | size_t offset = |
| 4875 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4876 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4877 | } else { |
| 4878 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4879 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4880 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4881 | value_loc, |
| 4882 | IP, |
| 4883 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4884 | } |
| 4885 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4886 | __ b(&done); |
| 4887 | __ Bind(&non_zero); |
| 4888 | } |
| 4889 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4890 | // Note that when read barriers are enabled, the type checks |
| 4891 | // are performed without read barriers. This is fine, even in |
| 4892 | // the case where a class object is in the from-space after |
| 4893 | // the flip, as a comparison involving such a type would not |
| 4894 | // produce a false positive; it may of course produce a false |
| 4895 | // negative, in which case we would take the ArraySet slow |
| 4896 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4897 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4898 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4899 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4900 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4901 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4902 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4903 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4904 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4905 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4906 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4907 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4908 | // nor `temp2`, as we are comparing two poisoned references. |
| 4909 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4910 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4911 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4912 | Label do_put; |
| 4913 | __ b(&do_put, EQ); |
| 4914 | // If heap poisoning is enabled, the `temp1` reference has |
| 4915 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4916 | __ MaybeUnpoisonHeapReference(temp1); |
| 4917 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4918 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4919 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4920 | // If heap poisoning is enabled, no need to unpoison |
| 4921 | // `temp1`, as we are comparing against null below. |
| 4922 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4923 | __ Bind(&do_put); |
| 4924 | } else { |
| 4925 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4926 | } |
| 4927 | } |
| 4928 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4929 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4930 | if (kPoisonHeapReferences) { |
| 4931 | // Note that in the case where `value` is a null reference, |
| 4932 | // we do not enter this block, as a null reference does not |
| 4933 | // need poisoning. |
| 4934 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4935 | __ Mov(temp1, value); |
| 4936 | __ PoisonHeapReference(temp1); |
| 4937 | source = temp1; |
| 4938 | } |
| 4939 | |
| 4940 | if (index.IsConstant()) { |
| 4941 | size_t offset = |
| 4942 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4943 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4944 | } else { |
| 4945 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4946 | |
| 4947 | __ add(IP, array, ShifterOperand(data_offset)); |
| 4948 | codegen_->StoreToShiftedRegOffset(value_type, |
| 4949 | Location::RegisterLocation(source), |
| 4950 | IP, |
| 4951 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4952 | } |
| 4953 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4954 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4955 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4956 | } |
| 4957 | |
| 4958 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4959 | |
| 4960 | if (done.IsLinked()) { |
| 4961 | __ Bind(&done); |
| 4962 | } |
| 4963 | |
| 4964 | if (slow_path != nullptr) { |
| 4965 | __ Bind(slow_path->GetExitLabel()); |
| 4966 | } |
| 4967 | |
| 4968 | break; |
| 4969 | } |
| 4970 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4971 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4972 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4973 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4974 | size_t offset = |
| 4975 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4976 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4977 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4978 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4979 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4980 | } |
| 4981 | break; |
| 4982 | } |
| 4983 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4984 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4985 | Location value = locations->InAt(2); |
| 4986 | DCHECK(value.IsFpuRegister()); |
| 4987 | if (index.IsConstant()) { |
| 4988 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4989 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4990 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4991 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4992 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4993 | } |
| 4994 | break; |
| 4995 | } |
| 4996 | |
| 4997 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4998 | Location value = locations->InAt(2); |
| 4999 | DCHECK(value.IsFpuRegisterPair()); |
| 5000 | if (index.IsConstant()) { |
| 5001 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5002 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5003 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5004 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5005 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5006 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5007 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5008 | break; |
| 5009 | } |
| 5010 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5011 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5012 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5013 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5014 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5015 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5016 | // Objects are handled in the switch. |
| 5017 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5018 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5019 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5023 | LocationSummary* locations = |
| 5024 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5025 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5026 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5030 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5031 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5032 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5033 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5034 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5035 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5036 | } |
| 5037 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5038 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5039 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5040 | DCHECK(!kEmitCompilerReadBarrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5041 | LocationSummary* locations = |
| 5042 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5043 | |
| 5044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5045 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5046 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5047 | } |
| 5048 | |
| 5049 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5050 | LocationSummary* locations = instruction->GetLocations(); |
| 5051 | Location out = locations->Out(); |
| 5052 | Location first = locations->InAt(0); |
| 5053 | Location second = locations->InAt(1); |
| 5054 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 5055 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 5056 | DCHECK(!kEmitCompilerReadBarrier); |
| 5057 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5058 | if (second.IsRegister()) { |
| 5059 | __ add(out.AsRegister<Register>(), |
| 5060 | first.AsRegister<Register>(), |
| 5061 | ShifterOperand(second.AsRegister<Register>())); |
| 5062 | } else { |
| 5063 | __ AddConstant(out.AsRegister<Register>(), |
| 5064 | first.AsRegister<Register>(), |
| 5065 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5066 | } |
| 5067 | } |
| 5068 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5070 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5071 | ? LocationSummary::kCallOnSlowPath |
| 5072 | : LocationSummary::kNoCall; |
| 5073 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5075 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5076 | if (instruction->HasUses()) { |
| 5077 | locations->SetOut(Location::SameAsFirstInput()); |
| 5078 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5082 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5083 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5084 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5085 | codegen_->AddSlowPath(slow_path); |
| 5086 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5087 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5088 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5089 | |
| 5090 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5091 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | } |
| 5093 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5094 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5095 | Register card, |
| 5096 | Register object, |
| 5097 | Register value, |
| 5098 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5099 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5100 | if (can_be_null) { |
| 5101 | __ CompareAndBranchIfZero(value, &is_null); |
| 5102 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5103 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5105 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5106 | if (can_be_null) { |
| 5107 | __ Bind(&is_null); |
| 5108 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5109 | } |
| 5110 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5111 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5112 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5116 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5117 | } |
| 5118 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5119 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5120 | LocationSummary* locations = |
| 5121 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5122 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5126 | HBasicBlock* block = instruction->GetBlock(); |
| 5127 | if (block->GetLoopInformation() != nullptr) { |
| 5128 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5129 | // The back edge will generate the suspend check. |
| 5130 | return; |
| 5131 | } |
| 5132 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5133 | // The goto will generate the suspend check. |
| 5134 | return; |
| 5135 | } |
| 5136 | GenerateSuspendCheck(instruction, nullptr); |
| 5137 | } |
| 5138 | |
| 5139 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5140 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5141 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5142 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5143 | if (slow_path == nullptr) { |
| 5144 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5145 | instruction->SetSlowPath(slow_path); |
| 5146 | codegen_->AddSlowPath(slow_path); |
| 5147 | if (successor != nullptr) { |
| 5148 | DCHECK(successor->IsLoopHeader()); |
| 5149 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5150 | } |
| 5151 | } else { |
| 5152 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5153 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5154 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5155 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5156 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5157 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5158 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5159 | __ Bind(slow_path->GetReturnLabel()); |
| 5160 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5161 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5162 | __ b(slow_path->GetEntryLabel()); |
| 5163 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5166 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5167 | return codegen_->GetAssembler(); |
| 5168 | } |
| 5169 | |
| 5170 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5171 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5172 | Location source = move->GetSource(); |
| 5173 | Location destination = move->GetDestination(); |
| 5174 | |
| 5175 | if (source.IsRegister()) { |
| 5176 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5177 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5178 | } else if (destination.IsFpuRegister()) { |
| 5179 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5180 | } else { |
| 5181 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5182 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5183 | SP, destination.GetStackIndex()); |
| 5184 | } |
| 5185 | } else if (source.IsStackSlot()) { |
| 5186 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5187 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5188 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5189 | } else if (destination.IsFpuRegister()) { |
| 5190 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5191 | } else { |
| 5192 | DCHECK(destination.IsStackSlot()); |
| 5193 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5194 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5195 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5196 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5197 | if (destination.IsRegister()) { |
| 5198 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5199 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5200 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5201 | } else { |
| 5202 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5203 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5204 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5205 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5206 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5207 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5208 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5209 | } else if (destination.IsRegisterPair()) { |
| 5210 | DCHECK(ExpectedPairLayout(destination)); |
| 5211 | __ LoadFromOffset( |
| 5212 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5213 | } else { |
| 5214 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5215 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5216 | SP, |
| 5217 | source.GetStackIndex()); |
| 5218 | } |
| 5219 | } else if (source.IsRegisterPair()) { |
| 5220 | if (destination.IsRegisterPair()) { |
| 5221 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5222 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5223 | } else if (destination.IsFpuRegisterPair()) { |
| 5224 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5225 | source.AsRegisterPairLow<Register>(), |
| 5226 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5227 | } else { |
| 5228 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5229 | DCHECK(ExpectedPairLayout(source)); |
| 5230 | __ StoreToOffset( |
| 5231 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5232 | } |
| 5233 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5234 | if (destination.IsRegisterPair()) { |
| 5235 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5236 | destination.AsRegisterPairHigh<Register>(), |
| 5237 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5238 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5239 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5240 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5241 | } else { |
| 5242 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5243 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5244 | SP, |
| 5245 | destination.GetStackIndex()); |
| 5246 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5247 | } else { |
| 5248 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5249 | HConstant* constant = source.GetConstant(); |
| 5250 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5251 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5252 | if (destination.IsRegister()) { |
| 5253 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5254 | } else { |
| 5255 | DCHECK(destination.IsStackSlot()); |
| 5256 | __ LoadImmediate(IP, value); |
| 5257 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5258 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5259 | } else if (constant->IsLongConstant()) { |
| 5260 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5261 | if (destination.IsRegisterPair()) { |
| 5262 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5263 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5264 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5265 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5266 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5267 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5268 | __ LoadImmediate(IP, High32Bits(value)); |
| 5269 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5270 | } |
| 5271 | } else if (constant->IsDoubleConstant()) { |
| 5272 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5273 | if (destination.IsFpuRegisterPair()) { |
| 5274 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5275 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5276 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5277 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5278 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5279 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5280 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5281 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5282 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5283 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5284 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5285 | float value = constant->AsFloatConstant()->GetValue(); |
| 5286 | if (destination.IsFpuRegister()) { |
| 5287 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5288 | } else { |
| 5289 | DCHECK(destination.IsStackSlot()); |
| 5290 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5291 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5292 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5293 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5298 | __ Mov(IP, reg); |
| 5299 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5300 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5301 | } |
| 5302 | |
| 5303 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5304 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5305 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5306 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5307 | SP, mem1 + stack_offset); |
| 5308 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5309 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5310 | SP, mem2 + stack_offset); |
| 5311 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5312 | } |
| 5313 | |
| 5314 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5315 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5316 | Location source = move->GetSource(); |
| 5317 | Location destination = move->GetDestination(); |
| 5318 | |
| 5319 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5320 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5321 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5322 | __ Mov(IP, source.AsRegister<Register>()); |
| 5323 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5324 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5325 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5326 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5327 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5328 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5329 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5330 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5331 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5332 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5333 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5334 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5335 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5336 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5337 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5338 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5339 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5340 | destination.AsRegisterPairHigh<Register>(), |
| 5341 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5342 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5343 | Register low_reg = source.IsRegisterPair() |
| 5344 | ? source.AsRegisterPairLow<Register>() |
| 5345 | : destination.AsRegisterPairLow<Register>(); |
| 5346 | int mem = source.IsRegisterPair() |
| 5347 | ? destination.GetStackIndex() |
| 5348 | : source.GetStackIndex(); |
| 5349 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5350 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5351 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5352 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5353 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5354 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5355 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5356 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5357 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5358 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5359 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5360 | DRegister reg = source.IsFpuRegisterPair() |
| 5361 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5362 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5363 | int mem = source.IsFpuRegisterPair() |
| 5364 | ? destination.GetStackIndex() |
| 5365 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5366 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5367 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5368 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5369 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5370 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5371 | : destination.AsFpuRegister<SRegister>(); |
| 5372 | int mem = source.IsFpuRegister() |
| 5373 | ? destination.GetStackIndex() |
| 5374 | : source.GetStackIndex(); |
| 5375 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5376 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5377 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5378 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5379 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5380 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5381 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5382 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5383 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5388 | __ Push(static_cast<Register>(reg)); |
| 5389 | } |
| 5390 | |
| 5391 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5392 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5393 | } |
| 5394 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5395 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5396 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5397 | switch (desired_class_load_kind) { |
| 5398 | case HLoadClass::LoadKind::kReferrersClass: |
| 5399 | break; |
| 5400 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5401 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5402 | break; |
| 5403 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5404 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5405 | break; |
| 5406 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5407 | break; |
| 5408 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5409 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5410 | break; |
| 5411 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5412 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5413 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5414 | // is incompatible with it. |
| 5415 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5416 | // with irreducible loops. |
| 5417 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5418 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5419 | } |
| 5420 | break; |
| 5421 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5422 | break; |
| 5423 | } |
| 5424 | return desired_class_load_kind; |
| 5425 | } |
| 5426 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5427 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5428 | if (cls->NeedsAccessCheck()) { |
| 5429 | InvokeRuntimeCallingConvention calling_convention; |
| 5430 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5431 | cls, |
| 5432 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5433 | Location::RegisterLocation(R0), |
| 5434 | /* code_generator_supports_read_barrier */ true); |
| 5435 | return; |
| 5436 | } |
| 5437 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5438 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5439 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5440 | ? LocationSummary::kCallOnSlowPath |
| 5441 | : LocationSummary::kNoCall; |
| 5442 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5443 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5444 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 5445 | } |
| 5446 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5447 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5448 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5449 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5450 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5451 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5452 | } |
| 5453 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5457 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5458 | if (cls->NeedsAccessCheck()) { |
| 5459 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5460 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5461 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5462 | return; |
| 5463 | } |
| 5464 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5465 | Location out_loc = locations->Out(); |
| 5466 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5467 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5468 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5469 | bool generate_null_check = false; |
| 5470 | switch (cls->GetLoadKind()) { |
| 5471 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5472 | DCHECK(!cls->CanCallRuntime()); |
| 5473 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5474 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5475 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5476 | GenerateGcRootFieldLoad(cls, |
| 5477 | out_loc, |
| 5478 | current_method, |
| 5479 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5480 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5481 | break; |
| 5482 | } |
| 5483 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5484 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5485 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5486 | cls->GetTypeIndex())); |
| 5487 | break; |
| 5488 | } |
| 5489 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5490 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5491 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5492 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5493 | __ BindTrackedLabel(&labels->movw_label); |
| 5494 | __ movw(out, /* placeholder */ 0u); |
| 5495 | __ BindTrackedLabel(&labels->movt_label); |
| 5496 | __ movt(out, /* placeholder */ 0u); |
| 5497 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5498 | __ add(out, out, ShifterOperand(PC)); |
| 5499 | break; |
| 5500 | } |
| 5501 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5502 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5503 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5504 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5505 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5506 | break; |
| 5507 | } |
| 5508 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5509 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5510 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5511 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5512 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5513 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5514 | // and the remaining offset embedded in the load. |
| 5515 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5516 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5517 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5518 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5519 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5520 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5521 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5522 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5523 | generate_null_check = !cls->IsInDexCache(); |
| 5524 | break; |
| 5525 | } |
| 5526 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5527 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5528 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5529 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5530 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5531 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5532 | generate_null_check = !cls->IsInDexCache(); |
| 5533 | break; |
| 5534 | } |
| 5535 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5536 | // /* GcRoot<mirror::Class>[] */ out = |
| 5537 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5538 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5539 | __ LoadFromOffset(kLoadWord, |
| 5540 | out, |
| 5541 | current_method, |
| 5542 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5543 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5544 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5545 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5546 | generate_null_check = !cls->IsInDexCache(); |
| 5547 | } |
| 5548 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5549 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5550 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5551 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5552 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5553 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5554 | codegen_->AddSlowPath(slow_path); |
| 5555 | if (generate_null_check) { |
| 5556 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5557 | } |
| 5558 | if (cls->MustGenerateClinitCheck()) { |
| 5559 | GenerateClassInitializationCheck(slow_path, out); |
| 5560 | } else { |
| 5561 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5562 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5567 | LocationSummary* locations = |
| 5568 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5570 | if (check->HasUses()) { |
| 5571 | locations->SetOut(Location::SameAsFirstInput()); |
| 5572 | } |
| 5573 | } |
| 5574 | |
| 5575 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5576 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5577 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5578 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5579 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5580 | GenerateClassInitializationCheck(slow_path, |
| 5581 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5582 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5583 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5584 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5585 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5586 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5587 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5588 | __ b(slow_path->GetEntryLabel(), LT); |
| 5589 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5590 | // properly. Therefore, we do a memory fence. |
| 5591 | __ dmb(ISH); |
| 5592 | __ Bind(slow_path->GetExitLabel()); |
| 5593 | } |
| 5594 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5595 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5596 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5597 | switch (desired_string_load_kind) { |
| 5598 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5599 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5600 | break; |
| 5601 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5602 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5603 | break; |
| 5604 | case HLoadString::LoadKind::kBootImageAddress: |
| 5605 | break; |
| 5606 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5607 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5608 | break; |
| 5609 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5610 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5611 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5612 | // is incompatible with it. |
| 5613 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5614 | // with irreducible loops. |
| 5615 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5616 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5617 | } |
| 5618 | break; |
| 5619 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5620 | break; |
| 5621 | } |
| 5622 | return desired_string_load_kind; |
| 5623 | } |
| 5624 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5625 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5626 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
| 5627 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5628 | : LocationSummary::kNoCall; |
| 5629 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5630 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5631 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5632 | DCHECK(load_kind != HLoadString::LoadKind::kDexCachePcRelative) << "Not supported"; |
| 5633 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5634 | locations->SetInAt(0, Location::RequiresRegister()); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5635 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5636 | } else { |
| 5637 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5638 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5642 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5643 | Location out_loc = locations->Out(); |
| 5644 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5645 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5646 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5647 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5648 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5649 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5650 | load->GetStringIndex())); |
| 5651 | return; // No dex cache slow path. |
| 5652 | } |
| 5653 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5654 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5655 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5656 | __ BindTrackedLabel(&labels->movw_label); |
| 5657 | __ movw(out, /* placeholder */ 0u); |
| 5658 | __ BindTrackedLabel(&labels->movt_label); |
| 5659 | __ movt(out, /* placeholder */ 0u); |
| 5660 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5661 | __ add(out, out, ShifterOperand(PC)); |
| 5662 | return; // No dex cache slow path. |
| 5663 | } |
| 5664 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5665 | DCHECK_NE(load->GetAddress(), 0u); |
| 5666 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5667 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5668 | return; // No dex cache slow path. |
| 5669 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5670 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5671 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5672 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5673 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5674 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 5675 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 5676 | InvokeRuntimeCallingConvention calling_convention; |
| 5677 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex()); |
| 5678 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5679 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5682 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5683 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5686 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5687 | LocationSummary* locations = |
| 5688 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5689 | locations->SetOut(Location::RequiresRegister()); |
| 5690 | } |
| 5691 | |
| 5692 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5693 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5694 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5695 | } |
| 5696 | |
| 5697 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5698 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5699 | } |
| 5700 | |
| 5701 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5702 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5703 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5707 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5708 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5709 | InvokeRuntimeCallingConvention calling_convention; |
| 5710 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5711 | } |
| 5712 | |
| 5713 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5714 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5715 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5716 | } |
| 5717 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5718 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5719 | return kEmitCompilerReadBarrier && |
| 5720 | (kUseBakerReadBarrier || |
| 5721 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5722 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5723 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5724 | } |
| 5725 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5726 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5727 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5728 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5729 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5730 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5731 | case TypeCheckKind::kExactCheck: |
| 5732 | case TypeCheckKind::kAbstractClassCheck: |
| 5733 | case TypeCheckKind::kClassHierarchyCheck: |
| 5734 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5735 | call_kind = |
| 5736 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5737 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5738 | break; |
| 5739 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5740 | case TypeCheckKind::kUnresolvedCheck: |
| 5741 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5742 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5743 | break; |
| 5744 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5745 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5746 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5747 | if (baker_read_barrier_slow_path) { |
| 5748 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 5749 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5750 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5751 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5752 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5753 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5754 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5755 | // When read barriers are enabled, we need a temporary register for |
| 5756 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5757 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5758 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5759 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5762 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5763 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5764 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5765 | Location obj_loc = locations->InAt(0); |
| 5766 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5767 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5768 | Location out_loc = locations->Out(); |
| 5769 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5770 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5771 | locations->GetTemp(0) : |
| 5772 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5773 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5774 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5775 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5776 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5777 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5778 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5779 | |
| 5780 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5781 | // avoid null check if we know obj is not null. |
| 5782 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5783 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5784 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5785 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5786 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5787 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5788 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5789 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5790 | case TypeCheckKind::kExactCheck: { |
| 5791 | __ cmp(out, ShifterOperand(cls)); |
| 5792 | // Classes must be equal for the instanceof to succeed. |
| 5793 | __ b(&zero, NE); |
| 5794 | __ LoadImmediate(out, 1); |
| 5795 | __ b(&done); |
| 5796 | break; |
| 5797 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5798 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5799 | case TypeCheckKind::kAbstractClassCheck: { |
| 5800 | // If the class is abstract, we eagerly fetch the super class of the |
| 5801 | // object to avoid doing a comparison we know will fail. |
| 5802 | Label loop; |
| 5803 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5804 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5805 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5806 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5807 | __ CompareAndBranchIfZero(out, &done); |
| 5808 | __ cmp(out, ShifterOperand(cls)); |
| 5809 | __ b(&loop, NE); |
| 5810 | __ LoadImmediate(out, 1); |
| 5811 | if (zero.IsLinked()) { |
| 5812 | __ b(&done); |
| 5813 | } |
| 5814 | break; |
| 5815 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5816 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5817 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5818 | // Walk over the class hierarchy to find a match. |
| 5819 | Label loop, success; |
| 5820 | __ Bind(&loop); |
| 5821 | __ cmp(out, ShifterOperand(cls)); |
| 5822 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5823 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5824 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5825 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5826 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5827 | __ b(&done); |
| 5828 | __ Bind(&success); |
| 5829 | __ LoadImmediate(out, 1); |
| 5830 | if (zero.IsLinked()) { |
| 5831 | __ b(&done); |
| 5832 | } |
| 5833 | break; |
| 5834 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5835 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5836 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5837 | // Do an exact check. |
| 5838 | Label exact_check; |
| 5839 | __ cmp(out, ShifterOperand(cls)); |
| 5840 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5841 | // 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] | 5842 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5843 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5844 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5845 | __ CompareAndBranchIfZero(out, &done); |
| 5846 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5847 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5848 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5849 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5850 | __ LoadImmediate(out, 1); |
| 5851 | __ b(&done); |
| 5852 | break; |
| 5853 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5854 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5855 | case TypeCheckKind::kArrayCheck: { |
| 5856 | __ cmp(out, ShifterOperand(cls)); |
| 5857 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5858 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5859 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5860 | codegen_->AddSlowPath(slow_path); |
| 5861 | __ b(slow_path->GetEntryLabel(), NE); |
| 5862 | __ LoadImmediate(out, 1); |
| 5863 | if (zero.IsLinked()) { |
| 5864 | __ b(&done); |
| 5865 | } |
| 5866 | break; |
| 5867 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5868 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5869 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5870 | case TypeCheckKind::kInterfaceCheck: { |
| 5871 | // 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] | 5872 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5873 | // cases. |
| 5874 | // |
| 5875 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5876 | // entry point without resorting to a type checking slow path |
| 5877 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5878 | // require to assign fixed registers for the inputs of this |
| 5879 | // HInstanceOf instruction (following the runtime calling |
| 5880 | // convention), which might be cluttered by the potential first |
| 5881 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5882 | // |
| 5883 | // TODO: Introduce a new runtime entry point taking the object |
| 5884 | // to test (instead of its class) as argument, and let it deal |
| 5885 | // with the read barrier issues. This will let us refactor this |
| 5886 | // case of the `switch` code as it was previously (with a direct |
| 5887 | // call to the runtime not using a type checking slow path). |
| 5888 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5889 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5890 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5891 | /* is_fatal */ false); |
| 5892 | codegen_->AddSlowPath(slow_path); |
| 5893 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5894 | if (zero.IsLinked()) { |
| 5895 | __ b(&done); |
| 5896 | } |
| 5897 | break; |
| 5898 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5899 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5900 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5901 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5902 | __ Bind(&zero); |
| 5903 | __ LoadImmediate(out, 0); |
| 5904 | } |
| 5905 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5906 | if (done.IsLinked()) { |
| 5907 | __ Bind(&done); |
| 5908 | } |
| 5909 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5910 | if (slow_path != nullptr) { |
| 5911 | __ Bind(slow_path->GetExitLabel()); |
| 5912 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5913 | } |
| 5914 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5915 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5916 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5917 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5918 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5919 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5920 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5921 | case TypeCheckKind::kExactCheck: |
| 5922 | case TypeCheckKind::kAbstractClassCheck: |
| 5923 | case TypeCheckKind::kClassHierarchyCheck: |
| 5924 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5925 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5926 | LocationSummary::kCallOnSlowPath : |
| 5927 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5928 | break; |
| 5929 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5930 | case TypeCheckKind::kUnresolvedCheck: |
| 5931 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5932 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5933 | break; |
| 5934 | } |
| 5935 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5936 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5938 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5939 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5940 | locations->AddTemp(Location::RequiresRegister()); |
| 5941 | // When read barriers are enabled, we need an additional temporary |
| 5942 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5943 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5944 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5945 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5949 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5950 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5951 | Location obj_loc = locations->InAt(0); |
| 5952 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5953 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5954 | Location temp_loc = locations->GetTemp(0); |
| 5955 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5956 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5957 | locations->GetTemp(1) : |
| 5958 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5959 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5960 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5961 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5962 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5963 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5964 | bool is_type_check_slow_path_fatal = |
| 5965 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5966 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5967 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5968 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5969 | !instruction->CanThrowIntoCatchBlock(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5970 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5971 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5972 | is_type_check_slow_path_fatal); |
| 5973 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5974 | |
| 5975 | Label done; |
| 5976 | // Avoid null check if we know obj is not null. |
| 5977 | if (instruction->MustDoNullCheck()) { |
| 5978 | __ CompareAndBranchIfZero(obj, &done); |
| 5979 | } |
| 5980 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5981 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5982 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5983 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5984 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5985 | case TypeCheckKind::kExactCheck: |
| 5986 | case TypeCheckKind::kArrayCheck: { |
| 5987 | __ cmp(temp, ShifterOperand(cls)); |
| 5988 | // Jump to slow path for throwing the exception or doing a |
| 5989 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5990 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5991 | break; |
| 5992 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5993 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5994 | case TypeCheckKind::kAbstractClassCheck: { |
| 5995 | // If the class is abstract, we eagerly fetch the super class of the |
| 5996 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5997 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5998 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5999 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6000 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6001 | |
| 6002 | // If the class reference currently in `temp` is not null, jump |
| 6003 | // to the `compare_classes` label to compare it with the checked |
| 6004 | // class. |
| 6005 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 6006 | // Otherwise, jump to the slow path to throw the exception. |
| 6007 | // |
| 6008 | // But before, move back the object's class into `temp` before |
| 6009 | // going into the slow path, as it has been overwritten in the |
| 6010 | // meantime. |
| 6011 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6012 | GenerateReferenceLoadTwoRegisters( |
| 6013 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6014 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6015 | |
| 6016 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6017 | __ cmp(temp, ShifterOperand(cls)); |
| 6018 | __ b(&loop, NE); |
| 6019 | break; |
| 6020 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6021 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6022 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6023 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6024 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6025 | __ Bind(&loop); |
| 6026 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6027 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6028 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6029 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6030 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6031 | |
| 6032 | // If the class reference currently in `temp` is not null, jump |
| 6033 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6034 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6035 | // Otherwise, jump to the slow path to throw the exception. |
| 6036 | // |
| 6037 | // But before, move back the object's class into `temp` before |
| 6038 | // going into the slow path, as it has been overwritten in the |
| 6039 | // meantime. |
| 6040 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6041 | GenerateReferenceLoadTwoRegisters( |
| 6042 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6043 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6044 | break; |
| 6045 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6046 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6047 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6048 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6049 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6050 | __ cmp(temp, ShifterOperand(cls)); |
| 6051 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6052 | |
| 6053 | // 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] | 6054 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6055 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6056 | |
| 6057 | // If the component type is not null (i.e. the object is indeed |
| 6058 | // an array), jump to label `check_non_primitive_component_type` |
| 6059 | // to further check that this component type is not a primitive |
| 6060 | // type. |
| 6061 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 6062 | // Otherwise, jump to the slow path to throw the exception. |
| 6063 | // |
| 6064 | // But before, move back the object's class into `temp` before |
| 6065 | // going into the slow path, as it has been overwritten in the |
| 6066 | // meantime. |
| 6067 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6068 | GenerateReferenceLoadTwoRegisters( |
| 6069 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6070 | __ b(type_check_slow_path->GetEntryLabel()); |
| 6071 | |
| 6072 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6073 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6074 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 6075 | __ CompareAndBranchIfZero(temp, &done); |
| 6076 | // Same comment as above regarding `temp` and the slow path. |
| 6077 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6078 | GenerateReferenceLoadTwoRegisters( |
| 6079 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6080 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6081 | break; |
| 6082 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6083 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6084 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6085 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6086 | // We always go into the type check slow path for the unresolved |
| 6087 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6088 | // |
| 6089 | // We cannot directly call the CheckCast runtime entry point |
| 6090 | // without resorting to a type checking slow path here (i.e. by |
| 6091 | // calling InvokeRuntime directly), as it would require to |
| 6092 | // assign fixed registers for the inputs of this HInstanceOf |
| 6093 | // instruction (following the runtime calling convention), which |
| 6094 | // might be cluttered by the potential first read barrier |
| 6095 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6096 | // |
| 6097 | // TODO: Introduce a new runtime entry point taking the object |
| 6098 | // to test (instead of its class) as argument, and let it deal |
| 6099 | // with the read barrier issues. This will let us refactor this |
| 6100 | // case of the `switch` code as it was previously (with a direct |
| 6101 | // call to the runtime not using a type checking slow path). |
| 6102 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6103 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6104 | break; |
| 6105 | } |
| 6106 | __ Bind(&done); |
| 6107 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6108 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6111 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6112 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6113 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6114 | InvokeRuntimeCallingConvention calling_convention; |
| 6115 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6116 | } |
| 6117 | |
| 6118 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6119 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6120 | instruction, |
| 6121 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6122 | if (instruction->IsEnter()) { |
| 6123 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6124 | } else { |
| 6125 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6126 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6129 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6130 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6131 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6132 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6133 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6134 | LocationSummary* locations = |
| 6135 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6136 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6137 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6138 | // 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] | 6139 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6140 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6141 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6145 | HandleBitwiseOperation(instruction); |
| 6146 | } |
| 6147 | |
| 6148 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6149 | HandleBitwiseOperation(instruction); |
| 6150 | } |
| 6151 | |
| 6152 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6153 | HandleBitwiseOperation(instruction); |
| 6154 | } |
| 6155 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6156 | |
| 6157 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6158 | LocationSummary* locations = |
| 6159 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6160 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6161 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6162 | |
| 6163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6164 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6165 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6166 | } |
| 6167 | |
| 6168 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6169 | LocationSummary* locations = instruction->GetLocations(); |
| 6170 | Location first = locations->InAt(0); |
| 6171 | Location second = locations->InAt(1); |
| 6172 | Location out = locations->Out(); |
| 6173 | |
| 6174 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6175 | Register first_reg = first.AsRegister<Register>(); |
| 6176 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6177 | Register out_reg = out.AsRegister<Register>(); |
| 6178 | |
| 6179 | switch (instruction->GetOpKind()) { |
| 6180 | case HInstruction::kAnd: |
| 6181 | __ bic(out_reg, first_reg, second_reg); |
| 6182 | break; |
| 6183 | case HInstruction::kOr: |
| 6184 | __ orn(out_reg, first_reg, second_reg); |
| 6185 | break; |
| 6186 | // There is no EON on arm. |
| 6187 | case HInstruction::kXor: |
| 6188 | default: |
| 6189 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6190 | UNREACHABLE(); |
| 6191 | } |
| 6192 | return; |
| 6193 | |
| 6194 | } else { |
| 6195 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6196 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6197 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6198 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6199 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6200 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6201 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6202 | |
| 6203 | switch (instruction->GetOpKind()) { |
| 6204 | case HInstruction::kAnd: |
| 6205 | __ bic(out_low, first_low, second_low); |
| 6206 | __ bic(out_high, first_high, second_high); |
| 6207 | break; |
| 6208 | case HInstruction::kOr: |
| 6209 | __ orn(out_low, first_low, second_low); |
| 6210 | __ orn(out_high, first_high, second_high); |
| 6211 | break; |
| 6212 | // There is no EON on arm. |
| 6213 | case HInstruction::kXor: |
| 6214 | default: |
| 6215 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6216 | UNREACHABLE(); |
| 6217 | } |
| 6218 | } |
| 6219 | } |
| 6220 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6221 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6222 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6223 | if (value == 0xffffffffu) { |
| 6224 | if (out != first) { |
| 6225 | __ mov(out, ShifterOperand(first)); |
| 6226 | } |
| 6227 | return; |
| 6228 | } |
| 6229 | if (value == 0u) { |
| 6230 | __ mov(out, ShifterOperand(0)); |
| 6231 | return; |
| 6232 | } |
| 6233 | ShifterOperand so; |
| 6234 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6235 | __ and_(out, first, so); |
| 6236 | } else { |
| 6237 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6238 | __ bic(out, first, ShifterOperand(~value)); |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6243 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6244 | if (value == 0u) { |
| 6245 | if (out != first) { |
| 6246 | __ mov(out, ShifterOperand(first)); |
| 6247 | } |
| 6248 | return; |
| 6249 | } |
| 6250 | if (value == 0xffffffffu) { |
| 6251 | __ mvn(out, ShifterOperand(0)); |
| 6252 | return; |
| 6253 | } |
| 6254 | ShifterOperand so; |
| 6255 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6256 | __ orr(out, first, so); |
| 6257 | } else { |
| 6258 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6259 | __ orn(out, first, ShifterOperand(~value)); |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6264 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6265 | if (value == 0u) { |
| 6266 | if (out != first) { |
| 6267 | __ mov(out, ShifterOperand(first)); |
| 6268 | } |
| 6269 | return; |
| 6270 | } |
| 6271 | __ eor(out, first, ShifterOperand(value)); |
| 6272 | } |
| 6273 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6274 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6275 | Location first, |
| 6276 | uint64_t value) { |
| 6277 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6278 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6279 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6280 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6281 | uint32_t value_low = Low32Bits(value); |
| 6282 | uint32_t value_high = High32Bits(value); |
| 6283 | if (value_low == 0u) { |
| 6284 | if (out_low != first_low) { |
| 6285 | __ mov(out_low, ShifterOperand(first_low)); |
| 6286 | } |
| 6287 | __ AddConstant(out_high, first_high, value_high); |
| 6288 | return; |
| 6289 | } |
| 6290 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6291 | ShifterOperand so; |
| 6292 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6293 | __ adc(out_high, first_high, so); |
| 6294 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6295 | __ sbc(out_high, first_high, so); |
| 6296 | } else { |
| 6297 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6298 | UNREACHABLE(); |
| 6299 | } |
| 6300 | } |
| 6301 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6302 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6303 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6304 | Location first = locations->InAt(0); |
| 6305 | Location second = locations->InAt(1); |
| 6306 | Location out = locations->Out(); |
| 6307 | |
| 6308 | if (second.IsConstant()) { |
| 6309 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6310 | uint32_t value_low = Low32Bits(value); |
| 6311 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6312 | Register first_reg = first.AsRegister<Register>(); |
| 6313 | Register out_reg = out.AsRegister<Register>(); |
| 6314 | if (instruction->IsAnd()) { |
| 6315 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6316 | } else if (instruction->IsOr()) { |
| 6317 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6318 | } else { |
| 6319 | DCHECK(instruction->IsXor()); |
| 6320 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6321 | } |
| 6322 | } else { |
| 6323 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6324 | uint32_t value_high = High32Bits(value); |
| 6325 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6326 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6327 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6328 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6329 | if (instruction->IsAnd()) { |
| 6330 | GenerateAndConst(out_low, first_low, value_low); |
| 6331 | GenerateAndConst(out_high, first_high, value_high); |
| 6332 | } else if (instruction->IsOr()) { |
| 6333 | GenerateOrrConst(out_low, first_low, value_low); |
| 6334 | GenerateOrrConst(out_high, first_high, value_high); |
| 6335 | } else { |
| 6336 | DCHECK(instruction->IsXor()); |
| 6337 | GenerateEorConst(out_low, first_low, value_low); |
| 6338 | GenerateEorConst(out_high, first_high, value_high); |
| 6339 | } |
| 6340 | } |
| 6341 | return; |
| 6342 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6343 | |
| 6344 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6345 | Register first_reg = first.AsRegister<Register>(); |
| 6346 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6347 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6348 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6349 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6350 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6351 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6352 | } else { |
| 6353 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6354 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6355 | } |
| 6356 | } else { |
| 6357 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6358 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6359 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6360 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6361 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6362 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6363 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6364 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6365 | __ and_(out_low, first_low, second_low); |
| 6366 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6367 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6368 | __ orr(out_low, first_low, second_low); |
| 6369 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6370 | } else { |
| 6371 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6372 | __ eor(out_low, first_low, second_low); |
| 6373 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6374 | } |
| 6375 | } |
| 6376 | } |
| 6377 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6378 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6379 | Location out, |
| 6380 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6381 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6382 | Register out_reg = out.AsRegister<Register>(); |
| 6383 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6384 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6385 | if (kUseBakerReadBarrier) { |
| 6386 | // Load with fast path based Baker's read barrier. |
| 6387 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6388 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6389 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6390 | } else { |
| 6391 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6392 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6393 | // in the following move operation, as we will need it for the |
| 6394 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6395 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6396 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6397 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6398 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6399 | } |
| 6400 | } else { |
| 6401 | // Plain load with no read barrier. |
| 6402 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6403 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6404 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6409 | Location out, |
| 6410 | Location obj, |
| 6411 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6412 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6413 | Register out_reg = out.AsRegister<Register>(); |
| 6414 | Register obj_reg = obj.AsRegister<Register>(); |
| 6415 | if (kEmitCompilerReadBarrier) { |
| 6416 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6417 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6418 | // Load with fast path based Baker's read barrier. |
| 6419 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6420 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6421 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6422 | } else { |
| 6423 | // Load with slow path based read barrier. |
| 6424 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6425 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6426 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6427 | } |
| 6428 | } else { |
| 6429 | // Plain load with no read barrier. |
| 6430 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6431 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6432 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6437 | Location root, |
| 6438 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6439 | uint32_t offset, |
| 6440 | bool requires_read_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6441 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6442 | if (requires_read_barrier) { |
| 6443 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6444 | if (kUseBakerReadBarrier) { |
| 6445 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6446 | // Baker's read barrier are used: |
| 6447 | // |
| 6448 | // root = obj.field; |
| 6449 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6450 | // root = ReadBarrier::Mark(root) |
| 6451 | // } |
| 6452 | |
| 6453 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6454 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6455 | static_assert( |
| 6456 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6457 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6458 | "have different sizes."); |
| 6459 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6460 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6461 | "have different sizes."); |
| 6462 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6463 | // Slow path marking the GC root `root`. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6464 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6465 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6466 | codegen_->AddSlowPath(slow_path); |
| 6467 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6468 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6469 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6470 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6471 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6472 | __ Bind(slow_path->GetExitLabel()); |
| 6473 | } else { |
| 6474 | // GC root loaded through a slow path for read barriers other |
| 6475 | // than Baker's. |
| 6476 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6477 | __ AddConstant(root_reg, obj, offset); |
| 6478 | // /* mirror::Object* */ root = root->Read() |
| 6479 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6480 | } |
| 6481 | } else { |
| 6482 | // Plain GC root load with no read barrier. |
| 6483 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6484 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6485 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6486 | // do not have to unpoison `root_reg` here. |
| 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6491 | Location ref, |
| 6492 | Register obj, |
| 6493 | uint32_t offset, |
| 6494 | Location temp, |
| 6495 | bool needs_null_check) { |
| 6496 | DCHECK(kEmitCompilerReadBarrier); |
| 6497 | DCHECK(kUseBakerReadBarrier); |
| 6498 | |
| 6499 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6500 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6501 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6502 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6503 | 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] | 6504 | } |
| 6505 | |
| 6506 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6507 | Location ref, |
| 6508 | Register obj, |
| 6509 | uint32_t data_offset, |
| 6510 | Location index, |
| 6511 | Location temp, |
| 6512 | bool needs_null_check) { |
| 6513 | DCHECK(kEmitCompilerReadBarrier); |
| 6514 | DCHECK(kUseBakerReadBarrier); |
| 6515 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6516 | static_assert( |
| 6517 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6518 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6519 | // /* HeapReference<Object> */ ref = |
| 6520 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6521 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6522 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6523 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6527 | Location ref, |
| 6528 | Register obj, |
| 6529 | uint32_t offset, |
| 6530 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6531 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6532 | Location temp, |
| 6533 | bool needs_null_check) { |
| 6534 | DCHECK(kEmitCompilerReadBarrier); |
| 6535 | DCHECK(kUseBakerReadBarrier); |
| 6536 | |
| 6537 | // In slow path based read barriers, the read barrier call is |
| 6538 | // inserted after the original load. However, in fast path based |
| 6539 | // Baker's read barriers, we need to perform the load of |
| 6540 | // mirror::Object::monitor_ *before* the original reference load. |
| 6541 | // This load-load ordering is required by the read barrier. |
| 6542 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6543 | // |
| 6544 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6545 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6546 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6547 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6548 | // if (is_gray) { |
| 6549 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6550 | // } |
| 6551 | // |
| 6552 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6553 | // slightly more complex as it performs additional checks that we do |
| 6554 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6555 | |
| 6556 | Register ref_reg = ref.AsRegister<Register>(); |
| 6557 | Register temp_reg = temp.AsRegister<Register>(); |
| 6558 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6559 | |
| 6560 | // /* int32_t */ monitor = obj->monitor_ |
| 6561 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6562 | if (needs_null_check) { |
| 6563 | MaybeRecordImplicitNullCheck(instruction); |
| 6564 | } |
| 6565 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6566 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6567 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6568 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6569 | // Introduce a dependency on the lock_word including the rb_state, |
| 6570 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6571 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 6572 | // `obj` is unchanged by this operation, but its value now depends |
| 6573 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6574 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6575 | |
| 6576 | // The actual reference load. |
| 6577 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6578 | // Load types involving an "index": ArrayGet and |
| 6579 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6580 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6581 | if (index.IsConstant()) { |
| 6582 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6583 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6584 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6585 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6586 | // Handle the special case of the |
| 6587 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6588 | // a register pair as index ("long offset"), of which only the low |
| 6589 | // part contains data. |
| 6590 | Register index_reg = index.IsRegisterPair() |
| 6591 | ? index.AsRegisterPairLow<Register>() |
| 6592 | : index.AsRegister<Register>(); |
| 6593 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6594 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6595 | } |
| 6596 | } else { |
| 6597 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6598 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6599 | } |
| 6600 | |
| 6601 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6602 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6603 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6604 | // Slow path marking the object `ref` when it is gray. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6605 | SlowPathCodeARM* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6606 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6607 | AddSlowPath(slow_path); |
| 6608 | |
| 6609 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6610 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6611 | // Given the numeric representation, it's enough to check the low bit of the |
| 6612 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6613 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6614 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6615 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6616 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6617 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6618 | __ 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] | 6619 | __ Bind(slow_path->GetExitLabel()); |
| 6620 | } |
| 6621 | |
| 6622 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6623 | Location out, |
| 6624 | Location ref, |
| 6625 | Location obj, |
| 6626 | uint32_t offset, |
| 6627 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6628 | DCHECK(kEmitCompilerReadBarrier); |
| 6629 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6630 | // Insert a slow path based read barrier *after* the reference load. |
| 6631 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6632 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6633 | // reference will be carried out by the runtime within the slow |
| 6634 | // path. |
| 6635 | // |
| 6636 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6637 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6638 | // not used by the artReadBarrierSlow entry point. |
| 6639 | // |
| 6640 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6641 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6642 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6643 | AddSlowPath(slow_path); |
| 6644 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6645 | __ b(slow_path->GetEntryLabel()); |
| 6646 | __ Bind(slow_path->GetExitLabel()); |
| 6647 | } |
| 6648 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6649 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6650 | Location out, |
| 6651 | Location ref, |
| 6652 | Location obj, |
| 6653 | uint32_t offset, |
| 6654 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6655 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6656 | // Baker's read barriers shall be handled by the fast path |
| 6657 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6658 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6659 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6660 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6661 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6662 | } else if (kPoisonHeapReferences) { |
| 6663 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6664 | } |
| 6665 | } |
| 6666 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6667 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6668 | Location out, |
| 6669 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6670 | DCHECK(kEmitCompilerReadBarrier); |
| 6671 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6672 | // Insert a slow path based read barrier *after* the GC root load. |
| 6673 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6674 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6675 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6676 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6677 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6678 | AddSlowPath(slow_path); |
| 6679 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6680 | __ b(slow_path->GetEntryLabel()); |
| 6681 | __ Bind(slow_path->GetExitLabel()); |
| 6682 | } |
| 6683 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6684 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6685 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6686 | MethodReference target_method) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6687 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6688 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6689 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6690 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6691 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6692 | if (GetGraph()->HasIrreducibleLoops() && |
| 6693 | (dispatch_info.method_load_kind == |
| 6694 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6695 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6696 | } |
| 6697 | |
| 6698 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6699 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6700 | if (&outer_dex_file != target_method.dex_file) { |
| 6701 | // Calls across dex files are more likely to exceed the available BL range, |
| 6702 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6703 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6704 | (desired_dispatch_info.method_load_kind == |
| 6705 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6706 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6707 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6708 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6709 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6710 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6711 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6712 | 0u |
| 6713 | }; |
| 6714 | } |
| 6715 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6716 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6717 | } |
| 6718 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6719 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6720 | Register temp) { |
| 6721 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6722 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6723 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6724 | return location.AsRegister<Register>(); |
| 6725 | } |
| 6726 | // For intrinsics we allow any location, so it may be on the stack. |
| 6727 | if (!location.IsRegister()) { |
| 6728 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6729 | return temp; |
| 6730 | } |
| 6731 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6732 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6733 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6734 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6735 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6736 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6737 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6738 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6739 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6740 | return temp; |
| 6741 | } |
| 6742 | return location.AsRegister<Register>(); |
| 6743 | } |
| 6744 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6745 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6746 | // 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] | 6747 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6748 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6749 | // LR = code address from literal pool with link-time patch. |
| 6750 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6751 | break; |
| 6752 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6753 | // LR = invoke->GetDirectCodePtr(); |
| 6754 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6755 | break; |
| 6756 | default: |
| 6757 | break; |
| 6758 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6759 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6760 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6761 | switch (invoke->GetMethodLoadKind()) { |
| 6762 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6763 | // temp = thread->string_init_entrypoint |
| 6764 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6765 | break; |
| 6766 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6767 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6768 | break; |
| 6769 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6770 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6771 | break; |
| 6772 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6773 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6774 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6775 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6776 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6777 | HArmDexCacheArraysBase* base = |
| 6778 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6779 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6780 | temp.AsRegister<Register>()); |
| 6781 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6782 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6783 | break; |
| 6784 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6785 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6786 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6787 | Register method_reg; |
| 6788 | Register reg = temp.AsRegister<Register>(); |
| 6789 | if (current_method.IsRegister()) { |
| 6790 | method_reg = current_method.AsRegister<Register>(); |
| 6791 | } else { |
| 6792 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6793 | DCHECK(!current_method.IsValid()); |
| 6794 | method_reg = reg; |
| 6795 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6796 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6797 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6798 | __ LoadFromOffset(kLoadWord, |
| 6799 | reg, |
| 6800 | method_reg, |
| 6801 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6802 | // temp = temp[index_in_cache]; |
| 6803 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6804 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6805 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6806 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6807 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | switch (invoke->GetCodePtrLocation()) { |
| 6811 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6812 | __ bl(GetFrameEntryLabel()); |
| 6813 | break; |
| 6814 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6815 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6816 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6817 | // Arbitrarily branch to the BL itself, override at link time. |
| 6818 | __ bl(&relative_call_patches_.back().label); |
| 6819 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6820 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6821 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6822 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6823 | // LR() |
| 6824 | __ blx(LR); |
| 6825 | break; |
| 6826 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6827 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6828 | __ LoadFromOffset( |
| 6829 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6830 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6831 | // LR() |
| 6832 | __ blx(LR); |
| 6833 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6834 | } |
| 6835 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6836 | DCHECK(!IsLeafMethod()); |
| 6837 | } |
| 6838 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6839 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6840 | Register temp = temp_location.AsRegister<Register>(); |
| 6841 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6842 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6843 | |
| 6844 | // Use the calling convention instead of the location of the receiver, as |
| 6845 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6846 | // slow path, the arguments have been moved to the right place, so here we are |
| 6847 | // guaranteed that the receiver is the first register of the calling convention. |
| 6848 | InvokeDexCallingConvention calling_convention; |
| 6849 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6850 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6851 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6852 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6853 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6854 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6855 | // emit a read barrier for the previous class reference load. |
| 6856 | // However this is not required in practice, as this is an |
| 6857 | // intermediate/temporary reference and because the current |
| 6858 | // concurrent copying collector keeps the from-space memory |
| 6859 | // intact/accessible until the end of the marking phase (the |
| 6860 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6861 | __ MaybeUnpoisonHeapReference(temp); |
| 6862 | // temp = temp->GetMethodAt(method_offset); |
| 6863 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6864 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6865 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6866 | // LR = temp->GetEntryPoint(); |
| 6867 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6868 | // LR(); |
| 6869 | __ blx(LR); |
| 6870 | } |
| 6871 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6872 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 6873 | const DexFile& dex_file, uint32_t string_index) { |
| 6874 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 6875 | } |
| 6876 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6877 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 6878 | const DexFile& dex_file, uint32_t type_index) { |
| 6879 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 6880 | } |
| 6881 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6882 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 6883 | const DexFile& dex_file, uint32_t element_offset) { |
| 6884 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 6885 | } |
| 6886 | |
| 6887 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 6888 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 6889 | patches->emplace_back(dex_file, offset_or_index); |
| 6890 | return &patches->back(); |
| 6891 | } |
| 6892 | |
| 6893 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 6894 | uint32_t string_index) { |
| 6895 | return boot_image_string_patches_.GetOrCreate( |
| 6896 | StringReference(&dex_file, string_index), |
| 6897 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6898 | } |
| 6899 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6900 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 6901 | uint32_t type_index) { |
| 6902 | return boot_image_type_patches_.GetOrCreate( |
| 6903 | TypeReference(&dex_file, type_index), |
| 6904 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6905 | } |
| 6906 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6907 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 6908 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 6909 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 6910 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 6911 | } |
| 6912 | |
| 6913 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 6914 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 6915 | } |
| 6916 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6917 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6918 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6919 | size_t size = |
| 6920 | method_patches_.size() + |
| 6921 | call_patches_.size() + |
| 6922 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6923 | /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() + |
| 6924 | boot_image_string_patches_.size() + |
| 6925 | /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6926 | boot_image_type_patches_.size() + |
| 6927 | /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6928 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6929 | linker_patches->reserve(size); |
| 6930 | for (const auto& entry : method_patches_) { |
| 6931 | const MethodReference& target_method = entry.first; |
| 6932 | Literal* literal = entry.second; |
| 6933 | DCHECK(literal->GetLabel()->IsBound()); |
| 6934 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6935 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6936 | target_method.dex_file, |
| 6937 | target_method.dex_method_index)); |
| 6938 | } |
| 6939 | for (const auto& entry : call_patches_) { |
| 6940 | const MethodReference& target_method = entry.first; |
| 6941 | Literal* literal = entry.second; |
| 6942 | DCHECK(literal->GetLabel()->IsBound()); |
| 6943 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6944 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6945 | target_method.dex_file, |
| 6946 | target_method.dex_method_index)); |
| 6947 | } |
| 6948 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6949 | uint32_t literal_offset = info.label.Position(); |
| 6950 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6951 | info.target_method.dex_file, |
| 6952 | info.target_method.dex_method_index)); |
| 6953 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6954 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
| 6955 | const DexFile& dex_file = info.target_dex_file; |
| 6956 | size_t base_element_offset = info.offset_or_index; |
| 6957 | DCHECK(info.add_pc_label.IsBound()); |
| 6958 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6959 | // Add MOVW patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6960 | DCHECK(info.movw_label.IsBound()); |
| 6961 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6962 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6963 | &dex_file, |
| 6964 | add_pc_offset, |
| 6965 | base_element_offset)); |
| 6966 | // Add MOVT patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6967 | DCHECK(info.movt_label.IsBound()); |
| 6968 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6969 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6970 | &dex_file, |
| 6971 | add_pc_offset, |
| 6972 | base_element_offset)); |
| 6973 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6974 | for (const auto& entry : boot_image_string_patches_) { |
| 6975 | const StringReference& target_string = entry.first; |
| 6976 | Literal* literal = entry.second; |
| 6977 | DCHECK(literal->GetLabel()->IsBound()); |
| 6978 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6979 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 6980 | target_string.dex_file, |
| 6981 | target_string.string_index)); |
| 6982 | } |
| 6983 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 6984 | const DexFile& dex_file = info.target_dex_file; |
| 6985 | uint32_t string_index = info.offset_or_index; |
| 6986 | DCHECK(info.add_pc_label.IsBound()); |
| 6987 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6988 | // Add MOVW patch. |
| 6989 | DCHECK(info.movw_label.IsBound()); |
| 6990 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6991 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset, |
| 6992 | &dex_file, |
| 6993 | add_pc_offset, |
| 6994 | string_index)); |
| 6995 | // Add MOVT patch. |
| 6996 | DCHECK(info.movt_label.IsBound()); |
| 6997 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6998 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset, |
| 6999 | &dex_file, |
| 7000 | add_pc_offset, |
| 7001 | string_index)); |
| 7002 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7003 | for (const auto& entry : boot_image_type_patches_) { |
| 7004 | const TypeReference& target_type = entry.first; |
| 7005 | Literal* literal = entry.second; |
| 7006 | DCHECK(literal->GetLabel()->IsBound()); |
| 7007 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7008 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7009 | target_type.dex_file, |
| 7010 | target_type.type_index)); |
| 7011 | } |
| 7012 | for (const PcRelativePatchInfo& info : pc_relative_type_patches_) { |
| 7013 | const DexFile& dex_file = info.target_dex_file; |
| 7014 | uint32_t type_index = info.offset_or_index; |
| 7015 | DCHECK(info.add_pc_label.IsBound()); |
| 7016 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7017 | // Add MOVW patch. |
| 7018 | DCHECK(info.movw_label.IsBound()); |
| 7019 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7020 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset, |
| 7021 | &dex_file, |
| 7022 | add_pc_offset, |
| 7023 | type_index)); |
| 7024 | // Add MOVT patch. |
| 7025 | DCHECK(info.movt_label.IsBound()); |
| 7026 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7027 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset, |
| 7028 | &dex_file, |
| 7029 | add_pc_offset, |
| 7030 | type_index)); |
| 7031 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7032 | for (const auto& entry : boot_image_address_patches_) { |
| 7033 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7034 | Literal* literal = entry.second; |
| 7035 | DCHECK(literal->GetLabel()->IsBound()); |
| 7036 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7037 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7038 | } |
| 7039 | } |
| 7040 | |
| 7041 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7042 | return map->GetOrCreate( |
| 7043 | value, |
| 7044 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7048 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7049 | return map->GetOrCreate( |
| 7050 | target_method, |
| 7051 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 7055 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 7056 | } |
| 7057 | |
| 7058 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 7059 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 7060 | } |
| 7061 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7062 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7063 | LocationSummary* locations = |
| 7064 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7065 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7066 | Location::RequiresRegister()); |
| 7067 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7068 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7069 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7070 | } |
| 7071 | |
| 7072 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7073 | LocationSummary* locations = instr->GetLocations(); |
| 7074 | Register res = locations->Out().AsRegister<Register>(); |
| 7075 | Register accumulator = |
| 7076 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7077 | Register mul_left = |
| 7078 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7079 | Register mul_right = |
| 7080 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7081 | |
| 7082 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7083 | __ mla(res, mul_left, mul_right, accumulator); |
| 7084 | } else { |
| 7085 | __ mls(res, mul_left, mul_right, accumulator); |
| 7086 | } |
| 7087 | } |
| 7088 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7089 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7090 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7091 | LOG(FATAL) << "Unreachable"; |
| 7092 | } |
| 7093 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7094 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7095 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7096 | LOG(FATAL) << "Unreachable"; |
| 7097 | } |
| 7098 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7099 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7100 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7101 | LocationSummary* locations = |
| 7102 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7103 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7104 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7105 | codegen_->GetAssembler()->IsThumb()) { |
| 7106 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7107 | if (switch_instr->GetStartValue() != 0) { |
| 7108 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7109 | } |
| 7110 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7114 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7115 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7116 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7117 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7118 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7119 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7120 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7121 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7122 | Register temp_reg = IP; |
| 7123 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7124 | // the immediate, because IP is used as the destination register. For the other |
| 7125 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7126 | // and they can be encoded in the instruction without making use of IP register. |
| 7127 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7128 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7129 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7130 | // Jump to successors[0] if value == lower_bound. |
| 7131 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7132 | int32_t last_index = 0; |
| 7133 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7134 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7135 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7136 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7137 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7138 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7139 | } |
| 7140 | if (num_entries - last_index == 2) { |
| 7141 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7142 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7143 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7144 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7145 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7146 | // And the default for any other value. |
| 7147 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7148 | __ b(codegen_->GetLabelOf(default_block)); |
| 7149 | } |
| 7150 | } else { |
| 7151 | // Create a table lookup. |
| 7152 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7153 | |
| 7154 | // Materialize a pointer to the switch table |
| 7155 | std::vector<Label*> labels(num_entries); |
| 7156 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7157 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7158 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7159 | } |
| 7160 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7161 | |
| 7162 | // Remove the bias. |
| 7163 | Register key_reg; |
| 7164 | if (lower_bound != 0) { |
| 7165 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7166 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7167 | } else { |
| 7168 | key_reg = value_reg; |
| 7169 | } |
| 7170 | |
| 7171 | // Check whether the value is in the table, jump to default block if not. |
| 7172 | __ CmpConstant(key_reg, num_entries - 1); |
| 7173 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7174 | |
| 7175 | // Load the displacement from the table. |
| 7176 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7177 | |
| 7178 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7179 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7180 | } |
| 7181 | } |
| 7182 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7183 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7184 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7185 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7189 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7190 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7191 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7192 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7193 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7194 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7195 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7196 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7197 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7198 | } |
| 7199 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7200 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7201 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7202 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7203 | return; |
| 7204 | } |
| 7205 | |
| 7206 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7207 | |
| 7208 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7209 | if (return_loc.Equals(trg)) { |
| 7210 | return; |
| 7211 | } |
| 7212 | |
| 7213 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7214 | // with the last branch. |
| 7215 | if (type == Primitive::kPrimLong) { |
| 7216 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7217 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7218 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7219 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7220 | } else if (type == Primitive::kPrimDouble) { |
| 7221 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7222 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7223 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7224 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7225 | } else { |
| 7226 | // Let the parallel move resolver take care of all of this. |
| 7227 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7228 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7229 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7230 | } |
| 7231 | } |
| 7232 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7233 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7234 | LocationSummary* locations = |
| 7235 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7236 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7237 | locations->SetOut(Location::RequiresRegister()); |
| 7238 | } |
| 7239 | |
| 7240 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7241 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7242 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7243 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7244 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7245 | __ LoadFromOffset(kLoadWord, |
| 7246 | locations->Out().AsRegister<Register>(), |
| 7247 | locations->InAt(0).AsRegister<Register>(), |
| 7248 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7249 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7250 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7251 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7252 | __ LoadFromOffset(kLoadWord, |
| 7253 | locations->Out().AsRegister<Register>(), |
| 7254 | locations->InAt(0).AsRegister<Register>(), |
| 7255 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7256 | __ LoadFromOffset(kLoadWord, |
| 7257 | locations->Out().AsRegister<Register>(), |
| 7258 | locations->Out().AsRegister<Register>(), |
| 7259 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7260 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7263 | #undef __ |
| 7264 | #undef QUICK_ENTRY_POINT |
| 7265 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7266 | } // namespace arm |
| 7267 | } // namespace art |