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 | |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 66 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 68 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 70 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 71 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 73 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 74 | // Live registers will be restored in the catch block if caught. |
| 75 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 76 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 77 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 78 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 79 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | bool IsFatal() const OVERRIDE { return true; } |
| 83 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 84 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 85 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 88 | }; |
| 89 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 90 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 92 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 94 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 96 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 97 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 98 | // Live registers will be restored in the catch block if caught. |
| 99 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 100 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 102 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 103 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 106 | bool IsFatal() const OVERRIDE { return true; } |
| 107 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 108 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 109 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 112 | }; |
| 113 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 114 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 115 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 116 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 117 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 118 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 119 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 120 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 121 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 122 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 123 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 124 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 125 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 126 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 127 | if (successor_ == nullptr) { |
| 128 | __ b(GetReturnLabel()); |
| 129 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 130 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 131 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | Label* GetReturnLabel() { |
| 135 | DCHECK(successor_ == nullptr); |
| 136 | return &return_label_; |
| 137 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 139 | HBasicBlock* GetSuccessor() const { |
| 140 | return successor_; |
| 141 | } |
| 142 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 143 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 144 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 146 | // If not null, the block to branch to after the suspend check. |
| 147 | HBasicBlock* const successor_; |
| 148 | |
| 149 | // 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] | 150 | Label return_label_; |
| 151 | |
| 152 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 153 | }; |
| 154 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 155 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 156 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 157 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 158 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 159 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 160 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 161 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 162 | LocationSummary* locations = instruction_->GetLocations(); |
| 163 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 164 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 165 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 166 | // Live registers will be restored in the catch block if caught. |
| 167 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 168 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 169 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 170 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 172 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 173 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 174 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 175 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 176 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 177 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 178 | Primitive::kPrimInt); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 179 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 180 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 181 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 182 | arm_codegen->InvokeRuntime(entry_point_offset, instruction_, instruction_->GetDexPc(), this); |
| 183 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 184 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 187 | bool IsFatal() const OVERRIDE { return true; } |
| 188 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 189 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 190 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 191 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 193 | }; |
| 194 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 195 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 196 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 197 | LoadClassSlowPathARM(HLoadClass* cls, |
| 198 | HInstruction* at, |
| 199 | uint32_t dex_pc, |
| 200 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 201 | : SlowPathCode(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] | 202 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 203 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 204 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 205 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 206 | LocationSummary* locations = at_->GetLocations(); |
| 207 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 208 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 209 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 210 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 211 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 212 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 213 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 214 | int32_t entry_point_offset = do_clinit_ |
| 215 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 216 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 217 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 218 | if (do_clinit_) { |
| 219 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 220 | } else { |
| 221 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 222 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 223 | |
| 224 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 225 | Location out = locations->Out(); |
| 226 | if (out.IsValid()) { |
| 227 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 229 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 230 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 231 | __ b(GetExitLabel()); |
| 232 | } |
| 233 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 234 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 235 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 236 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | // The class this slow path will load. |
| 238 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 240 | // The instruction where this slow path is happening. |
| 241 | // (Might be the load class or an initialization check). |
| 242 | HInstruction* const at_; |
| 243 | |
| 244 | // The dex PC of `at_`. |
| 245 | const uint32_t dex_pc_; |
| 246 | |
| 247 | // Whether to initialize the class. |
| 248 | const bool do_clinit_; |
| 249 | |
| 250 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 251 | }; |
| 252 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 253 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 254 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 255 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 256 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 257 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 258 | LocationSummary* locations = instruction_->GetLocations(); |
| 259 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 260 | |
| 261 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 262 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 263 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 264 | |
| 265 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 266 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 267 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 268 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 269 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 270 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 271 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 272 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 273 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 274 | __ b(GetExitLabel()); |
| 275 | } |
| 276 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 277 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 278 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 279 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 280 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 281 | }; |
| 282 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 283 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 284 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 285 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 286 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 288 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 289 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 290 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 291 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 292 | DCHECK(instruction_->IsCheckCast() |
| 293 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 294 | |
| 295 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 296 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 297 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 298 | if (!is_fatal_) { |
| 299 | SaveLiveRegisters(codegen, locations); |
| 300 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
| 302 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 303 | // move resolver. |
| 304 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 305 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 306 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 307 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 308 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 309 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 310 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 311 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 313 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 314 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 315 | instruction_, |
| 316 | instruction_->GetDexPc(), |
| 317 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 318 | CheckEntrypointTypes< |
| 319 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 320 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 321 | } else { |
| 322 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 324 | instruction_, |
| 325 | instruction_->GetDexPc(), |
| 326 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 327 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 328 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 330 | if (!is_fatal_) { |
| 331 | RestoreLiveRegisters(codegen, locations); |
| 332 | __ b(GetExitLabel()); |
| 333 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 336 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 337 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 338 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 339 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 341 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | |
| 343 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 344 | }; |
| 345 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 346 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 347 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 348 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 349 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 350 | |
| 351 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 352 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 353 | __ Bind(GetEntryLabel()); |
| 354 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 355 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 356 | instruction_, |
| 357 | instruction_->GetDexPc(), |
| 358 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 359 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 363 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 364 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 366 | }; |
| 367 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 368 | class ArraySetSlowPathARM : public SlowPathCode { |
| 369 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 370 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 371 | |
| 372 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 373 | LocationSummary* locations = instruction_->GetLocations(); |
| 374 | __ Bind(GetEntryLabel()); |
| 375 | SaveLiveRegisters(codegen, locations); |
| 376 | |
| 377 | InvokeRuntimeCallingConvention calling_convention; |
| 378 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 379 | parallel_move.AddMove( |
| 380 | locations->InAt(0), |
| 381 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 382 | Primitive::kPrimNot, |
| 383 | nullptr); |
| 384 | parallel_move.AddMove( |
| 385 | locations->InAt(1), |
| 386 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 387 | Primitive::kPrimInt, |
| 388 | nullptr); |
| 389 | parallel_move.AddMove( |
| 390 | locations->InAt(2), |
| 391 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 392 | Primitive::kPrimNot, |
| 393 | nullptr); |
| 394 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 395 | |
| 396 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 397 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 398 | instruction_, |
| 399 | instruction_->GetDexPc(), |
| 400 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 401 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 402 | RestoreLiveRegisters(codegen, locations); |
| 403 | __ b(GetExitLabel()); |
| 404 | } |
| 405 | |
| 406 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 407 | |
| 408 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 409 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 410 | }; |
| 411 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 412 | // Slow path marking an object during a read barrier. |
| 413 | class ReadBarrierMarkSlowPathARM : public SlowPathCode { |
| 414 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 415 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj) |
| 416 | : SlowPathCode(instruction), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 417 | DCHECK(kEmitCompilerReadBarrier); |
| 418 | } |
| 419 | |
| 420 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 421 | |
| 422 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 423 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 424 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 425 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 426 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 427 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 428 | instruction_->IsStaticFieldGet() || |
| 429 | instruction_->IsArrayGet() || |
| 430 | instruction_->IsLoadClass() || |
| 431 | instruction_->IsLoadString() || |
| 432 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 433 | instruction_->IsCheckCast() || |
| 434 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
| 435 | instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 436 | << "Unexpected instruction in read barrier marking slow path: " |
| 437 | << instruction_->DebugName(); |
| 438 | |
| 439 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame^] | 440 | // No need to save live registers; it's taken care of by the |
| 441 | // entrypoint. Also, there is no need to update the stack mask, |
| 442 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 443 | InvokeRuntimeCallingConvention calling_convention; |
| 444 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 445 | DCHECK_NE(reg, SP); |
| 446 | DCHECK_NE(reg, LR); |
| 447 | DCHECK_NE(reg, PC); |
| 448 | DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg; |
| 449 | // "Compact" slow path, saving two moves. |
| 450 | // |
| 451 | // Instead of using the standard runtime calling convention (input |
| 452 | // and output in R0): |
| 453 | // |
| 454 | // R0 <- obj |
| 455 | // R0 <- ReadBarrierMark(R0) |
| 456 | // obj <- R0 |
| 457 | // |
| 458 | // we just use rX (the register holding `obj`) as input and output |
| 459 | // of a dedicated entrypoint: |
| 460 | // |
| 461 | // rX <- ReadBarrierMarkRegX(rX) |
| 462 | // |
| 463 | int32_t entry_point_offset = |
| 464 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmWordSize>(reg); |
| 465 | // TODO: Do not emit a stack map for this runtime call. |
| 466 | arm_codegen->InvokeRuntime(entry_point_offset, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 467 | instruction_, |
| 468 | instruction_->GetDexPc(), |
| 469 | this); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 470 | __ b(GetExitLabel()); |
| 471 | } |
| 472 | |
| 473 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 474 | const Location obj_; |
| 475 | |
| 476 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 477 | }; |
| 478 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 479 | // Slow path generating a read barrier for a heap reference. |
| 480 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 481 | public: |
| 482 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 483 | Location out, |
| 484 | Location ref, |
| 485 | Location obj, |
| 486 | uint32_t offset, |
| 487 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 488 | : SlowPathCode(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 489 | out_(out), |
| 490 | ref_(ref), |
| 491 | obj_(obj), |
| 492 | offset_(offset), |
| 493 | index_(index) { |
| 494 | DCHECK(kEmitCompilerReadBarrier); |
| 495 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 496 | // has been overwritten by (or after) the heap object reference load |
| 497 | // to be instrumented, e.g.: |
| 498 | // |
| 499 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 500 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 501 | // |
| 502 | // In that case, we have lost the information about the original |
| 503 | // object, and the emitted read barrier cannot work properly. |
| 504 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 505 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 506 | } |
| 507 | |
| 508 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 509 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 510 | LocationSummary* locations = instruction_->GetLocations(); |
| 511 | Register reg_out = out_.AsRegister<Register>(); |
| 512 | DCHECK(locations->CanCall()); |
| 513 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 514 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 515 | instruction_->IsStaticFieldGet() || |
| 516 | instruction_->IsArrayGet() || |
| 517 | instruction_->IsInstanceOf() || |
| 518 | instruction_->IsCheckCast() || |
| 519 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 520 | instruction_->GetLocations()->Intrinsified())) |
| 521 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 522 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 523 | |
| 524 | __ Bind(GetEntryLabel()); |
| 525 | SaveLiveRegisters(codegen, locations); |
| 526 | |
| 527 | // We may have to change the index's value, but as `index_` is a |
| 528 | // constant member (like other "inputs" of this slow path), |
| 529 | // introduce a copy of it, `index`. |
| 530 | Location index = index_; |
| 531 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 532 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 533 | if (instruction_->IsArrayGet()) { |
| 534 | // Compute the actual memory offset and store it in `index`. |
| 535 | Register index_reg = index_.AsRegister<Register>(); |
| 536 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 537 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 538 | // We are about to change the value of `index_reg` (see the |
| 539 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 540 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 541 | // not been saved by the previous call to |
| 542 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 543 | // callee-save register -- |
| 544 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 545 | // callee-save registers, as it has been designed with the |
| 546 | // assumption that callee-save registers are supposed to be |
| 547 | // handled by the called function. So, as a callee-save |
| 548 | // register, `index_reg` _would_ eventually be saved onto |
| 549 | // the stack, but it would be too late: we would have |
| 550 | // changed its value earlier. Therefore, we manually save |
| 551 | // it here into another freely available register, |
| 552 | // `free_reg`, chosen of course among the caller-save |
| 553 | // registers (as a callee-save `free_reg` register would |
| 554 | // exhibit the same problem). |
| 555 | // |
| 556 | // Note we could have requested a temporary register from |
| 557 | // the register allocator instead; but we prefer not to, as |
| 558 | // this is a slow path, and we know we can find a |
| 559 | // caller-save register that is available. |
| 560 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 561 | __ Mov(free_reg, index_reg); |
| 562 | index_reg = free_reg; |
| 563 | index = Location::RegisterLocation(index_reg); |
| 564 | } else { |
| 565 | // The initial register stored in `index_` has already been |
| 566 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 567 | // (as it is not a callee-save register), so we can freely |
| 568 | // use it. |
| 569 | } |
| 570 | // Shifting the index value contained in `index_reg` by the scale |
| 571 | // factor (2) cannot overflow in practice, as the runtime is |
| 572 | // unable to allocate object arrays with a size larger than |
| 573 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 574 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 575 | static_assert( |
| 576 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 577 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 578 | __ AddConstant(index_reg, index_reg, offset_); |
| 579 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 580 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 581 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 582 | // (as in the case of ArrayGet), as it is actually an offset |
| 583 | // to an object field within an object. |
| 584 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 585 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 586 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 587 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 588 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 589 | DCHECK_EQ(offset_, 0U); |
| 590 | DCHECK(index_.IsRegisterPair()); |
| 591 | // UnsafeGet's offset location is a register pair, the low |
| 592 | // part contains the correct offset. |
| 593 | index = index_.ToLow(); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | // We're moving two or three locations to locations that could |
| 598 | // overlap, so we need a parallel move resolver. |
| 599 | InvokeRuntimeCallingConvention calling_convention; |
| 600 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 601 | parallel_move.AddMove(ref_, |
| 602 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 603 | Primitive::kPrimNot, |
| 604 | nullptr); |
| 605 | parallel_move.AddMove(obj_, |
| 606 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 607 | Primitive::kPrimNot, |
| 608 | nullptr); |
| 609 | if (index.IsValid()) { |
| 610 | parallel_move.AddMove(index, |
| 611 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 612 | Primitive::kPrimInt, |
| 613 | nullptr); |
| 614 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 615 | } else { |
| 616 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 617 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 618 | } |
| 619 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 620 | instruction_, |
| 621 | instruction_->GetDexPc(), |
| 622 | this); |
| 623 | CheckEntrypointTypes< |
| 624 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 625 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 626 | |
| 627 | RestoreLiveRegisters(codegen, locations); |
| 628 | __ b(GetExitLabel()); |
| 629 | } |
| 630 | |
| 631 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 632 | |
| 633 | private: |
| 634 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 635 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 636 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 637 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 638 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 639 | return static_cast<Register>(i); |
| 640 | } |
| 641 | } |
| 642 | // We shall never fail to find a free caller-save register, as |
| 643 | // there are more than two core caller-save registers on ARM |
| 644 | // (meaning it is possible to find one which is different from |
| 645 | // `ref` and `obj`). |
| 646 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 647 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 648 | UNREACHABLE(); |
| 649 | } |
| 650 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 651 | const Location out_; |
| 652 | const Location ref_; |
| 653 | const Location obj_; |
| 654 | const uint32_t offset_; |
| 655 | // An additional location containing an index to an array. |
| 656 | // Only used for HArrayGet and the UnsafeGetObject & |
| 657 | // UnsafeGetObjectVolatile intrinsics. |
| 658 | const Location index_; |
| 659 | |
| 660 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 661 | }; |
| 662 | |
| 663 | // Slow path generating a read barrier for a GC root. |
| 664 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 665 | public: |
| 666 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 667 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 668 | DCHECK(kEmitCompilerReadBarrier); |
| 669 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 670 | |
| 671 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 672 | LocationSummary* locations = instruction_->GetLocations(); |
| 673 | Register reg_out = out_.AsRegister<Register>(); |
| 674 | DCHECK(locations->CanCall()); |
| 675 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 676 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 677 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 678 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 679 | |
| 680 | __ Bind(GetEntryLabel()); |
| 681 | SaveLiveRegisters(codegen, locations); |
| 682 | |
| 683 | InvokeRuntimeCallingConvention calling_convention; |
| 684 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 685 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 686 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 687 | instruction_, |
| 688 | instruction_->GetDexPc(), |
| 689 | this); |
| 690 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 691 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 692 | |
| 693 | RestoreLiveRegisters(codegen, locations); |
| 694 | __ b(GetExitLabel()); |
| 695 | } |
| 696 | |
| 697 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 698 | |
| 699 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 700 | const Location out_; |
| 701 | const Location root_; |
| 702 | |
| 703 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 704 | }; |
| 705 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 706 | #undef __ |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 707 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 708 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 709 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 710 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 711 | switch (cond) { |
| 712 | case kCondEQ: return EQ; |
| 713 | case kCondNE: return NE; |
| 714 | case kCondLT: return LT; |
| 715 | case kCondLE: return LE; |
| 716 | case kCondGT: return GT; |
| 717 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 718 | case kCondB: return LO; |
| 719 | case kCondBE: return LS; |
| 720 | case kCondA: return HI; |
| 721 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 722 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 723 | LOG(FATAL) << "Unreachable"; |
| 724 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 727 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 728 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 729 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 730 | case kCondEQ: return EQ; |
| 731 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 732 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 733 | case kCondLT: return LO; |
| 734 | case kCondLE: return LS; |
| 735 | case kCondGT: return HI; |
| 736 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 737 | // Unsigned remain unchanged. |
| 738 | case kCondB: return LO; |
| 739 | case kCondBE: return LS; |
| 740 | case kCondA: return HI; |
| 741 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 742 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 743 | LOG(FATAL) << "Unreachable"; |
| 744 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 747 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 748 | // The ARM condition codes can express all the necessary branches, see the |
| 749 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 750 | // There is no dex instruction or HIR that would need the missing conditions |
| 751 | // "equal or unordered" or "not equal". |
| 752 | switch (cond) { |
| 753 | case kCondEQ: return EQ; |
| 754 | case kCondNE: return NE /* unordered */; |
| 755 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 756 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 757 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 758 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 759 | default: |
| 760 | LOG(FATAL) << "UNREACHABLE"; |
| 761 | UNREACHABLE(); |
| 762 | } |
| 763 | } |
| 764 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 765 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 766 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 770 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 773 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 774 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 775 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 778 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 779 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 780 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 783 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 784 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 785 | return kArmWordSize; |
| 786 | } |
| 787 | |
| 788 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 789 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 790 | return kArmWordSize; |
| 791 | } |
| 792 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 793 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 794 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 795 | const CompilerOptions& compiler_options, |
| 796 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 797 | : CodeGenerator(graph, |
| 798 | kNumberOfCoreRegisters, |
| 799 | kNumberOfSRegisters, |
| 800 | kNumberOfRegisterPairs, |
| 801 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 802 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 803 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 804 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 805 | compiler_options, |
| 806 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 807 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 808 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 809 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 810 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 811 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 812 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 813 | uint32_literals_(std::less<uint32_t>(), |
| 814 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 815 | method_patches_(MethodReferenceComparator(), |
| 816 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 817 | call_patches_(MethodReferenceComparator(), |
| 818 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 819 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 820 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 821 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 822 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 823 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 824 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 825 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 826 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 827 | boot_image_address_patches_(std::less<uint32_t>(), |
| 828 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 829 | // Always save the LR register to mimic Quick. |
| 830 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 833 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 834 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 835 | __ FinalizeCode(); |
| 836 | |
| 837 | // Adjust native pc offsets in stack maps. |
| 838 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 839 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 840 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 841 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 842 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 843 | // Adjust pc offsets for the disassembly information. |
| 844 | if (disasm_info_ != nullptr) { |
| 845 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 846 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 847 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 848 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 849 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 850 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 851 | } |
| 852 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 853 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 854 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 855 | } |
| 856 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 857 | |
| 858 | CodeGenerator::Finalize(allocator); |
| 859 | } |
| 860 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 861 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 862 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 863 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 864 | |
| 865 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 866 | blocked_core_registers_[SP] = true; |
| 867 | blocked_core_registers_[LR] = true; |
| 868 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 869 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 870 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 871 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 872 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 873 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 874 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 875 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 876 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 877 | // Stubs do not save callee-save floating point registers. If the graph |
| 878 | // is debuggable, we need to deal with these registers differently. For |
| 879 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 880 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 881 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 882 | } |
| 883 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 884 | |
| 885 | UpdateBlockedPairRegisters(); |
| 886 | } |
| 887 | |
| 888 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 889 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 890 | ArmManagedRegister current = |
| 891 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 892 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 893 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 894 | blocked_register_pairs_[i] = true; |
| 895 | } |
| 896 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 897 | } |
| 898 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 899 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 900 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 901 | assembler_(codegen->GetAssembler()), |
| 902 | codegen_(codegen) {} |
| 903 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 904 | void CodeGeneratorARM::ComputeSpillMask() { |
| 905 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 906 | 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] | 907 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 908 | // restore another arbitrary register. |
| 909 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 910 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 911 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 912 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 913 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 914 | // but in the range. |
| 915 | if (fpu_spill_mask_ != 0) { |
| 916 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 917 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 918 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 919 | fpu_spill_mask_ |= (1 << i); |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 924 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 925 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 929 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 930 | } |
| 931 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 932 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 933 | bool skip_overflow_check = |
| 934 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 935 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 936 | __ Bind(&frame_entry_label_); |
| 937 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 938 | if (HasEmptyFrame()) { |
| 939 | return; |
| 940 | } |
| 941 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 942 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 943 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 944 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 945 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 948 | __ PushList(core_spill_mask_); |
| 949 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 950 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 951 | if (fpu_spill_mask_ != 0) { |
| 952 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 953 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 954 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 955 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 956 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 957 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 958 | __ AddConstant(SP, -adjust); |
| 959 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 960 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 964 | if (HasEmptyFrame()) { |
| 965 | __ bx(LR); |
| 966 | return; |
| 967 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 968 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 969 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 970 | __ AddConstant(SP, adjust); |
| 971 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 972 | if (fpu_spill_mask_ != 0) { |
| 973 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 974 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 975 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 976 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 977 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 978 | // Pop LR into PC to return. |
| 979 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 980 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 981 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 982 | __ cfi().RestoreState(); |
| 983 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 986 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 987 | Label* label = GetLabelOf(block); |
| 988 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 991 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 992 | switch (type) { |
| 993 | case Primitive::kPrimBoolean: |
| 994 | case Primitive::kPrimByte: |
| 995 | case Primitive::kPrimChar: |
| 996 | case Primitive::kPrimShort: |
| 997 | case Primitive::kPrimInt: |
| 998 | case Primitive::kPrimNot: { |
| 999 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1000 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1001 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1002 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1003 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1004 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1005 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1006 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1007 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1008 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1009 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1010 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1011 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1012 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1013 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1014 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1015 | // Skip R1, and use R2_R3 instead. |
| 1016 | gp_index_++; |
| 1017 | index++; |
| 1018 | } |
| 1019 | } |
| 1020 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1021 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1022 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1023 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1024 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1025 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1026 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1027 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | case Primitive::kPrimFloat: { |
| 1032 | uint32_t stack_index = stack_index_++; |
| 1033 | if (float_index_ % 2 == 0) { |
| 1034 | float_index_ = std::max(double_index_, float_index_); |
| 1035 | } |
| 1036 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1037 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1038 | } else { |
| 1039 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | case Primitive::kPrimDouble: { |
| 1044 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1045 | uint32_t stack_index = stack_index_; |
| 1046 | stack_index_ += 2; |
| 1047 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1048 | uint32_t index = double_index_; |
| 1049 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1050 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1051 | calling_convention.GetFpuRegisterAt(index), |
| 1052 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1053 | DCHECK(ExpectedPairLayout(result)); |
| 1054 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1055 | } else { |
| 1056 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1060 | case Primitive::kPrimVoid: |
| 1061 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1062 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1063 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1064 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1065 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1066 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1067 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1068 | switch (type) { |
| 1069 | case Primitive::kPrimBoolean: |
| 1070 | case Primitive::kPrimByte: |
| 1071 | case Primitive::kPrimChar: |
| 1072 | case Primitive::kPrimShort: |
| 1073 | case Primitive::kPrimInt: |
| 1074 | case Primitive::kPrimNot: { |
| 1075 | return Location::RegisterLocation(R0); |
| 1076 | } |
| 1077 | |
| 1078 | case Primitive::kPrimFloat: { |
| 1079 | return Location::FpuRegisterLocation(S0); |
| 1080 | } |
| 1081 | |
| 1082 | case Primitive::kPrimLong: { |
| 1083 | return Location::RegisterPairLocation(R0, R1); |
| 1084 | } |
| 1085 | |
| 1086 | case Primitive::kPrimDouble: { |
| 1087 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1088 | } |
| 1089 | |
| 1090 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1091 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1092 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1093 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1094 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1097 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1098 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1099 | } |
| 1100 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1101 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1102 | if (source.Equals(destination)) { |
| 1103 | return; |
| 1104 | } |
| 1105 | if (destination.IsRegister()) { |
| 1106 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1107 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1108 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1109 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1110 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1111 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1112 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1113 | } else if (destination.IsFpuRegister()) { |
| 1114 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1115 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1116 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1117 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1118 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1119 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1120 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1121 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1122 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1123 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1124 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1125 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1126 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1127 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1128 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1129 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1130 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1136 | if (source.Equals(destination)) { |
| 1137 | return; |
| 1138 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1139 | if (destination.IsRegisterPair()) { |
| 1140 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1141 | EmitParallelMoves( |
| 1142 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1143 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1144 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1145 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1146 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1147 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1148 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1149 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1150 | } else if (source.IsFpuRegisterPair()) { |
| 1151 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1152 | destination.AsRegisterPairHigh<Register>(), |
| 1153 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1154 | } else { |
| 1155 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1156 | DCHECK(ExpectedPairLayout(destination)); |
| 1157 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1158 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1159 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1160 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1162 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1163 | SP, |
| 1164 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1165 | } else if (source.IsRegisterPair()) { |
| 1166 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1167 | source.AsRegisterPairLow<Register>(), |
| 1168 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1169 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1170 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1171 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1172 | } else { |
| 1173 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1174 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1175 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1176 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1177 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1178 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1179 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1180 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1181 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1182 | SP, destination.GetStackIndex()); |
| 1183 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1184 | } else if (source.IsFpuRegisterPair()) { |
| 1185 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1186 | SP, |
| 1187 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1188 | } else { |
| 1189 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1190 | EmitParallelMoves( |
| 1191 | Location::StackSlot(source.GetStackIndex()), |
| 1192 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1193 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1194 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1195 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1196 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1201 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1202 | DCHECK(location.IsRegister()); |
| 1203 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1204 | } |
| 1205 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1206 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1207 | HParallelMove move(GetGraph()->GetArena()); |
| 1208 | move.AddMove(src, dst, dst_type, nullptr); |
| 1209 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1213 | if (location.IsRegister()) { |
| 1214 | locations->AddTemp(location); |
| 1215 | } else if (location.IsRegisterPair()) { |
| 1216 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1217 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1218 | } else { |
| 1219 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1220 | } |
| 1221 | } |
| 1222 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1223 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1224 | HInstruction* instruction, |
| 1225 | uint32_t dex_pc, |
| 1226 | SlowPathCode* slow_path) { |
| 1227 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1228 | instruction, |
| 1229 | dex_pc, |
| 1230 | slow_path); |
| 1231 | } |
| 1232 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1233 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1234 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1235 | uint32_t dex_pc, |
| 1236 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1237 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1238 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1239 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1240 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1241 | } |
| 1242 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1243 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1244 | DCHECK(!successor->IsExitBlock()); |
| 1245 | |
| 1246 | HBasicBlock* block = got->GetBlock(); |
| 1247 | HInstruction* previous = got->GetPrevious(); |
| 1248 | |
| 1249 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1250 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1251 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1252 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
| 1256 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1257 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1258 | } |
| 1259 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1260 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1264 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1265 | got->SetLocations(nullptr); |
| 1266 | } |
| 1267 | |
| 1268 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1269 | HandleGoto(got, got->GetSuccessor()); |
| 1270 | } |
| 1271 | |
| 1272 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1273 | try_boundary->SetLocations(nullptr); |
| 1274 | } |
| 1275 | |
| 1276 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1277 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1278 | if (!successor->IsExitBlock()) { |
| 1279 | HandleGoto(try_boundary, successor); |
| 1280 | } |
| 1281 | } |
| 1282 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1283 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1284 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1287 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1290 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1291 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1292 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1293 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1294 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1298 | Label* true_label, |
| 1299 | Label* false_label) { |
| 1300 | LocationSummary* locations = cond->GetLocations(); |
| 1301 | Location left = locations->InAt(0); |
| 1302 | Location right = locations->InAt(1); |
| 1303 | IfCondition if_cond = cond->GetCondition(); |
| 1304 | |
| 1305 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1306 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1307 | IfCondition true_high_cond = if_cond; |
| 1308 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1309 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1310 | |
| 1311 | // Set the conditions for the test, remembering that == needs to be |
| 1312 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1313 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1314 | switch (if_cond) { |
| 1315 | case kCondEQ: |
| 1316 | case kCondNE: |
| 1317 | // Nothing to do. |
| 1318 | break; |
| 1319 | case kCondLT: |
| 1320 | false_high_cond = kCondGT; |
| 1321 | break; |
| 1322 | case kCondLE: |
| 1323 | true_high_cond = kCondLT; |
| 1324 | break; |
| 1325 | case kCondGT: |
| 1326 | false_high_cond = kCondLT; |
| 1327 | break; |
| 1328 | case kCondGE: |
| 1329 | true_high_cond = kCondGT; |
| 1330 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1331 | case kCondB: |
| 1332 | false_high_cond = kCondA; |
| 1333 | break; |
| 1334 | case kCondBE: |
| 1335 | true_high_cond = kCondB; |
| 1336 | break; |
| 1337 | case kCondA: |
| 1338 | false_high_cond = kCondB; |
| 1339 | break; |
| 1340 | case kCondAE: |
| 1341 | true_high_cond = kCondA; |
| 1342 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1343 | } |
| 1344 | if (right.IsConstant()) { |
| 1345 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1346 | int32_t val_low = Low32Bits(value); |
| 1347 | int32_t val_high = High32Bits(value); |
| 1348 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1349 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1350 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1351 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1352 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1353 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1354 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1355 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1356 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1357 | } |
| 1358 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1359 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1360 | } else { |
| 1361 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1362 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1363 | |
| 1364 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1365 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1366 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1367 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1368 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1369 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1370 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1371 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1372 | } |
| 1373 | // Must be equal high, so compare the lows. |
| 1374 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1375 | } |
| 1376 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1377 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1378 | __ b(true_label, final_condition); |
| 1379 | } |
| 1380 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1381 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1382 | Label* true_target_in, |
| 1383 | Label* false_target_in) { |
| 1384 | // Generated branching requires both targets to be explicit. If either of the |
| 1385 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1386 | Label fallthrough_target; |
| 1387 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1388 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1389 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1390 | LocationSummary* locations = condition->GetLocations(); |
| 1391 | Location left = locations->InAt(0); |
| 1392 | Location right = locations->InAt(1); |
| 1393 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1394 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1395 | switch (type) { |
| 1396 | case Primitive::kPrimLong: |
| 1397 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1398 | break; |
| 1399 | case Primitive::kPrimFloat: |
| 1400 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1401 | GenerateFPJumps(condition, true_target, false_target); |
| 1402 | break; |
| 1403 | case Primitive::kPrimDouble: |
| 1404 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1405 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1406 | GenerateFPJumps(condition, true_target, false_target); |
| 1407 | break; |
| 1408 | default: |
| 1409 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1410 | } |
| 1411 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1412 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1413 | __ b(false_target); |
| 1414 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1415 | |
| 1416 | if (fallthrough_target.IsLinked()) { |
| 1417 | __ Bind(&fallthrough_target); |
| 1418 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1419 | } |
| 1420 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1421 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1422 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1423 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1424 | Label* false_target) { |
| 1425 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1426 | |
| 1427 | if (true_target == nullptr && false_target == nullptr) { |
| 1428 | // Nothing to do. The code always falls through. |
| 1429 | return; |
| 1430 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1431 | // Constant condition, statically compared against "true" (integer value 1). |
| 1432 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1433 | if (true_target != nullptr) { |
| 1434 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1435 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1436 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1437 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1438 | if (false_target != nullptr) { |
| 1439 | __ b(false_target); |
| 1440 | } |
| 1441 | } |
| 1442 | return; |
| 1443 | } |
| 1444 | |
| 1445 | // The following code generates these patterns: |
| 1446 | // (1) true_target == nullptr && false_target != nullptr |
| 1447 | // - opposite condition true => branch to false_target |
| 1448 | // (2) true_target != nullptr && false_target == nullptr |
| 1449 | // - condition true => branch to true_target |
| 1450 | // (3) true_target != nullptr && false_target != nullptr |
| 1451 | // - condition true => branch to true_target |
| 1452 | // - branch to false_target |
| 1453 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1454 | // Condition has been materialized, compare the output to 0. |
| 1455 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1456 | DCHECK(cond_val.IsRegister()); |
| 1457 | if (true_target == nullptr) { |
| 1458 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1459 | } else { |
| 1460 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1461 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1462 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1463 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1464 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1465 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1466 | |
| 1467 | // If this is a long or FP comparison that has been folded into |
| 1468 | // the HCondition, generate the comparison directly. |
| 1469 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1470 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1471 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1472 | return; |
| 1473 | } |
| 1474 | |
| 1475 | LocationSummary* locations = cond->GetLocations(); |
| 1476 | DCHECK(locations->InAt(0).IsRegister()); |
| 1477 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1478 | Location right = locations->InAt(1); |
| 1479 | if (right.IsRegister()) { |
| 1480 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1481 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1482 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1483 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1484 | } |
| 1485 | if (true_target == nullptr) { |
| 1486 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1487 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1488 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1489 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1490 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1491 | |
| 1492 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1493 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1494 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1495 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1499 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1500 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1501 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1507 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1508 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1509 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1510 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1511 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1512 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1513 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1517 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1518 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1519 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1520 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1525 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1526 | GenerateTestAndBranch(deoptimize, |
| 1527 | /* condition_input_index */ 0, |
| 1528 | slow_path->GetEntryLabel(), |
| 1529 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1530 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1531 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1532 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1533 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1534 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1535 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1536 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1537 | } else { |
| 1538 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1539 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1540 | } |
| 1541 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1542 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1543 | } |
| 1544 | locations->SetOut(Location::SameAsFirstInput()); |
| 1545 | } |
| 1546 | |
| 1547 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1548 | LocationSummary* locations = select->GetLocations(); |
| 1549 | Label false_target; |
| 1550 | GenerateTestAndBranch(select, |
| 1551 | /* condition_input_index */ 2, |
| 1552 | /* true_target */ nullptr, |
| 1553 | &false_target); |
| 1554 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1555 | __ Bind(&false_target); |
| 1556 | } |
| 1557 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1558 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1559 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1560 | } |
| 1561 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1562 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1563 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | void CodeGeneratorARM::GenerateNop() { |
| 1567 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1570 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1571 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1572 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1573 | // Handle the long/FP comparisons made in instruction simplification. |
| 1574 | switch (cond->InputAt(0)->GetType()) { |
| 1575 | case Primitive::kPrimLong: |
| 1576 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1577 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1578 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1579 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1580 | } |
| 1581 | break; |
| 1582 | |
| 1583 | case Primitive::kPrimFloat: |
| 1584 | case Primitive::kPrimDouble: |
| 1585 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1586 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1587 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1588 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1589 | } |
| 1590 | break; |
| 1591 | |
| 1592 | default: |
| 1593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1594 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1595 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1596 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1597 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1598 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1601 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1602 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1603 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1604 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1605 | |
| 1606 | LocationSummary* locations = cond->GetLocations(); |
| 1607 | Location left = locations->InAt(0); |
| 1608 | Location right = locations->InAt(1); |
| 1609 | Register out = locations->Out().AsRegister<Register>(); |
| 1610 | Label true_label, false_label; |
| 1611 | |
| 1612 | switch (cond->InputAt(0)->GetType()) { |
| 1613 | default: { |
| 1614 | // Integer case. |
| 1615 | if (right.IsRegister()) { |
| 1616 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1617 | } else { |
| 1618 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1619 | __ CmpConstant(left.AsRegister<Register>(), |
| 1620 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1621 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1622 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1623 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1624 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1625 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1626 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1627 | return; |
| 1628 | } |
| 1629 | case Primitive::kPrimLong: |
| 1630 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1631 | break; |
| 1632 | case Primitive::kPrimFloat: |
| 1633 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1634 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1635 | break; |
| 1636 | case Primitive::kPrimDouble: |
| 1637 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1638 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1639 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | // Convert the jumps into the result. |
| 1644 | Label done_label; |
| 1645 | |
| 1646 | // False case: result = 0. |
| 1647 | __ Bind(&false_label); |
| 1648 | __ LoadImmediate(out, 0); |
| 1649 | __ b(&done_label); |
| 1650 | |
| 1651 | // True case: result = 1. |
| 1652 | __ Bind(&true_label); |
| 1653 | __ LoadImmediate(out, 1); |
| 1654 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1658 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1662 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1666 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1670 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1674 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1678 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1682 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1686 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1690 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1694 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1698 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1702 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1705 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1706 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1710 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1714 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1718 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1722 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1726 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1730 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1734 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1737 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1738 | LocationSummary* locations = |
| 1739 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1740 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1743 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1744 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1747 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1748 | LocationSummary* locations = |
| 1749 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1750 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1751 | } |
| 1752 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1753 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1754 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1757 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1758 | LocationSummary* locations = |
| 1759 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1760 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1761 | } |
| 1762 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1763 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1764 | // Will be generated at use site. |
| 1765 | } |
| 1766 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1767 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1768 | LocationSummary* locations = |
| 1769 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1770 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1771 | } |
| 1772 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1773 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1774 | // Will be generated at use site. |
| 1775 | } |
| 1776 | |
| 1777 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1778 | LocationSummary* locations = |
| 1779 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1780 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1781 | } |
| 1782 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1783 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1784 | // Will be generated at use site. |
| 1785 | } |
| 1786 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1787 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1788 | memory_barrier->SetLocations(nullptr); |
| 1789 | } |
| 1790 | |
| 1791 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1792 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1793 | } |
| 1794 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1795 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1796 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1799 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1800 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1803 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1804 | LocationSummary* locations = |
| 1805 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1806 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1809 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1810 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1813 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1814 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1815 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1816 | // the method_idx. |
| 1817 | HandleInvoke(invoke); |
| 1818 | } |
| 1819 | |
| 1820 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1821 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1822 | } |
| 1823 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1824 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1825 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1826 | // art::PrepareForRegisterAllocation. |
| 1827 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1828 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1829 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1830 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1831 | codegen_->GetInstructionSetFeatures()); |
| 1832 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1833 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1834 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1835 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1836 | return; |
| 1837 | } |
| 1838 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1839 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1840 | |
| 1841 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1842 | if (invoke->HasPcRelativeDexCache()) { |
| 1843 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 1844 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1847 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1848 | if (invoke->GetLocations()->Intrinsified()) { |
| 1849 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1850 | intrinsic.Dispatch(invoke); |
| 1851 | return true; |
| 1852 | } |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1856 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1857 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1858 | // art::PrepareForRegisterAllocation. |
| 1859 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1860 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1861 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1862 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1863 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1864 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1865 | LocationSummary* locations = invoke->GetLocations(); |
| 1866 | codegen_->GenerateStaticOrDirectCall( |
| 1867 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1868 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1871 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1872 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1873 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1876 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1877 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1878 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1879 | codegen_->GetInstructionSetFeatures()); |
| 1880 | if (intrinsic.TryDispatch(invoke)) { |
| 1881 | return; |
| 1882 | } |
| 1883 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1884 | HandleInvoke(invoke); |
| 1885 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1886 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1887 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1888 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1889 | return; |
| 1890 | } |
| 1891 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1892 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1893 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1894 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1897 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1898 | HandleInvoke(invoke); |
| 1899 | // Add the hidden argument. |
| 1900 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1901 | } |
| 1902 | |
| 1903 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1904 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1905 | LocationSummary* locations = invoke->GetLocations(); |
| 1906 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1907 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1908 | Location receiver = locations->InAt(0); |
| 1909 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1910 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1911 | // Set the hidden argument. This is safe to do this here, as R12 |
| 1912 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 1913 | DCHECK_EQ(R12, hidden_reg); |
| 1914 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1915 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1916 | if (receiver.IsStackSlot()) { |
| 1917 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1918 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1919 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1920 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1921 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1922 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1923 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1924 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1925 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1926 | // emit a read barrier for the previous class reference load. |
| 1927 | // However this is not required in practice, as this is an |
| 1928 | // intermediate/temporary reference and because the current |
| 1929 | // concurrent copying collector keeps the from-space memory |
| 1930 | // intact/accessible until the end of the marking phase (the |
| 1931 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1932 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1933 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 1934 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 1935 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 1936 | invoke->GetImtIndex() % ImTable::kSize, kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1937 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1938 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1939 | uint32_t entry_point = |
| 1940 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1941 | // LR = temp->GetEntryPoint(); |
| 1942 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1943 | // LR(); |
| 1944 | __ blx(LR); |
| 1945 | DCHECK(!codegen_->IsLeafMethod()); |
| 1946 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1947 | } |
| 1948 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1949 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1950 | LocationSummary* locations = |
| 1951 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1952 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1953 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1954 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1955 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1956 | break; |
| 1957 | } |
| 1958 | case Primitive::kPrimLong: { |
| 1959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1960 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1961 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1962 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1963 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1964 | case Primitive::kPrimFloat: |
| 1965 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1966 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1967 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1968 | break; |
| 1969 | |
| 1970 | default: |
| 1971 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1976 | LocationSummary* locations = neg->GetLocations(); |
| 1977 | Location out = locations->Out(); |
| 1978 | Location in = locations->InAt(0); |
| 1979 | switch (neg->GetResultType()) { |
| 1980 | case Primitive::kPrimInt: |
| 1981 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1982 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1983 | break; |
| 1984 | |
| 1985 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1986 | DCHECK(in.IsRegisterPair()); |
| 1987 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1988 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1989 | in.AsRegisterPairLow<Register>(), |
| 1990 | ShifterOperand(0)); |
| 1991 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1992 | // instruction here, as it does not exist in the Thumb-2 |
| 1993 | // instruction set. We use the following approach |
| 1994 | // using SBC and SUB instead. |
| 1995 | // |
| 1996 | // out.hi = -C |
| 1997 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1998 | out.AsRegisterPairHigh<Register>(), |
| 1999 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2000 | // out.hi = out.hi - in.hi |
| 2001 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2002 | out.AsRegisterPairHigh<Register>(), |
| 2003 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2004 | break; |
| 2005 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2006 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2007 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2008 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2009 | break; |
| 2010 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2011 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2012 | DCHECK(in.IsFpuRegisterPair()); |
| 2013 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2014 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2015 | break; |
| 2016 | |
| 2017 | default: |
| 2018 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2019 | } |
| 2020 | } |
| 2021 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2022 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2023 | Primitive::Type result_type = conversion->GetResultType(); |
| 2024 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2025 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2026 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2027 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2028 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2029 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2030 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2031 | && result_type == Primitive::kPrimLong) |
| 2032 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2033 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2034 | : LocationSummary::kNoCall; |
| 2035 | LocationSummary* locations = |
| 2036 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2037 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2038 | // The Java language does not allow treating boolean as an integral type but |
| 2039 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2040 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2041 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2042 | case Primitive::kPrimByte: |
| 2043 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2044 | case Primitive::kPrimLong: |
| 2045 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2046 | case Primitive::kPrimBoolean: |
| 2047 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimShort: |
| 2049 | case Primitive::kPrimInt: |
| 2050 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2051 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2053 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2054 | break; |
| 2055 | |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2058 | << " to " << result_type; |
| 2059 | } |
| 2060 | break; |
| 2061 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2062 | case Primitive::kPrimShort: |
| 2063 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2064 | case Primitive::kPrimLong: |
| 2065 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2066 | case Primitive::kPrimBoolean: |
| 2067 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2068 | case Primitive::kPrimByte: |
| 2069 | case Primitive::kPrimInt: |
| 2070 | case Primitive::kPrimChar: |
| 2071 | // Processing a Dex `int-to-short' instruction. |
| 2072 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2074 | break; |
| 2075 | |
| 2076 | default: |
| 2077 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2078 | << " to " << result_type; |
| 2079 | } |
| 2080 | break; |
| 2081 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2082 | case Primitive::kPrimInt: |
| 2083 | switch (input_type) { |
| 2084 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2085 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2086 | locations->SetInAt(0, Location::Any()); |
| 2087 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2088 | break; |
| 2089 | |
| 2090 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2091 | // Processing a Dex `float-to-int' instruction. |
| 2092 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2093 | locations->SetOut(Location::RequiresRegister()); |
| 2094 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2095 | break; |
| 2096 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2097 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2098 | // Processing a Dex `double-to-int' instruction. |
| 2099 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2100 | locations->SetOut(Location::RequiresRegister()); |
| 2101 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | |
| 2104 | default: |
| 2105 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2106 | << " to " << result_type; |
| 2107 | } |
| 2108 | break; |
| 2109 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2110 | case Primitive::kPrimLong: |
| 2111 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimBoolean: |
| 2113 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimByte: |
| 2115 | case Primitive::kPrimShort: |
| 2116 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2117 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2118 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2119 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2120 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2121 | break; |
| 2122 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2123 | case Primitive::kPrimFloat: { |
| 2124 | // Processing a Dex `float-to-long' instruction. |
| 2125 | InvokeRuntimeCallingConvention calling_convention; |
| 2126 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2127 | calling_convention.GetFpuRegisterAt(0))); |
| 2128 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2129 | break; |
| 2130 | } |
| 2131 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2132 | case Primitive::kPrimDouble: { |
| 2133 | // Processing a Dex `double-to-long' instruction. |
| 2134 | InvokeRuntimeCallingConvention calling_convention; |
| 2135 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2136 | calling_convention.GetFpuRegisterAt(0), |
| 2137 | calling_convention.GetFpuRegisterAt(1))); |
| 2138 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2139 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2140 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2141 | |
| 2142 | default: |
| 2143 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2144 | << " to " << result_type; |
| 2145 | } |
| 2146 | break; |
| 2147 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2148 | case Primitive::kPrimChar: |
| 2149 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2150 | case Primitive::kPrimLong: |
| 2151 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimBoolean: |
| 2153 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimByte: |
| 2155 | case Primitive::kPrimShort: |
| 2156 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2157 | // Processing a Dex `int-to-char' instruction. |
| 2158 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2159 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2160 | break; |
| 2161 | |
| 2162 | default: |
| 2163 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2164 | << " to " << result_type; |
| 2165 | } |
| 2166 | break; |
| 2167 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2168 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2169 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2170 | case Primitive::kPrimBoolean: |
| 2171 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2172 | case Primitive::kPrimByte: |
| 2173 | case Primitive::kPrimShort: |
| 2174 | case Primitive::kPrimInt: |
| 2175 | case Primitive::kPrimChar: |
| 2176 | // Processing a Dex `int-to-float' instruction. |
| 2177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2178 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2179 | break; |
| 2180 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2181 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2182 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2183 | InvokeRuntimeCallingConvention calling_convention; |
| 2184 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2185 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2186 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2187 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2188 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2189 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2190 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2191 | // Processing a Dex `double-to-float' instruction. |
| 2192 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2193 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | |
| 2196 | default: |
| 2197 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2198 | << " to " << result_type; |
| 2199 | }; |
| 2200 | break; |
| 2201 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2202 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2203 | switch (input_type) { |
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 | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2206 | case Primitive::kPrimByte: |
| 2207 | case Primitive::kPrimShort: |
| 2208 | case Primitive::kPrimInt: |
| 2209 | case Primitive::kPrimChar: |
| 2210 | // Processing a Dex `int-to-double' instruction. |
| 2211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2212 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2213 | break; |
| 2214 | |
| 2215 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2216 | // Processing a Dex `long-to-double' instruction. |
| 2217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2218 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2219 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2220 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2221 | break; |
| 2222 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2224 | // Processing a Dex `float-to-double' instruction. |
| 2225 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2226 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2227 | break; |
| 2228 | |
| 2229 | default: |
| 2230 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2231 | << " to " << result_type; |
| 2232 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2233 | break; |
| 2234 | |
| 2235 | default: |
| 2236 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2237 | << " to " << result_type; |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2242 | LocationSummary* locations = conversion->GetLocations(); |
| 2243 | Location out = locations->Out(); |
| 2244 | Location in = locations->InAt(0); |
| 2245 | Primitive::Type result_type = conversion->GetResultType(); |
| 2246 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2247 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2248 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2249 | case Primitive::kPrimByte: |
| 2250 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimLong: |
| 2252 | // Type conversion from long to byte is a result of code transformations. |
| 2253 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2254 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2255 | case Primitive::kPrimBoolean: |
| 2256 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2257 | case Primitive::kPrimShort: |
| 2258 | case Primitive::kPrimInt: |
| 2259 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2260 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2261 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | |
| 2264 | default: |
| 2265 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2266 | << " to " << result_type; |
| 2267 | } |
| 2268 | break; |
| 2269 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimShort: |
| 2271 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimLong: |
| 2273 | // Type conversion from long to short is a result of code transformations. |
| 2274 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2275 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimBoolean: |
| 2277 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimByte: |
| 2279 | case Primitive::kPrimInt: |
| 2280 | case Primitive::kPrimChar: |
| 2281 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2282 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2283 | break; |
| 2284 | |
| 2285 | default: |
| 2286 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2287 | << " to " << result_type; |
| 2288 | } |
| 2289 | break; |
| 2290 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2291 | case Primitive::kPrimInt: |
| 2292 | switch (input_type) { |
| 2293 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2294 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2295 | DCHECK(out.IsRegister()); |
| 2296 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2297 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2298 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2299 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2300 | } else { |
| 2301 | DCHECK(in.IsConstant()); |
| 2302 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2303 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2304 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2305 | } |
| 2306 | break; |
| 2307 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2308 | case Primitive::kPrimFloat: { |
| 2309 | // Processing a Dex `float-to-int' instruction. |
| 2310 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2311 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2312 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2313 | break; |
| 2314 | } |
| 2315 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimDouble: { |
| 2317 | // Processing a Dex `double-to-int' instruction. |
| 2318 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2319 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2320 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2321 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2322 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2323 | |
| 2324 | default: |
| 2325 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2326 | << " to " << result_type; |
| 2327 | } |
| 2328 | break; |
| 2329 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimLong: |
| 2331 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimBoolean: |
| 2333 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2334 | case Primitive::kPrimByte: |
| 2335 | case Primitive::kPrimShort: |
| 2336 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2337 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2338 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2339 | DCHECK(out.IsRegisterPair()); |
| 2340 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2341 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2342 | // Sign extension. |
| 2343 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2344 | out.AsRegisterPairLow<Register>(), |
| 2345 | 31); |
| 2346 | break; |
| 2347 | |
| 2348 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2349 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2350 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2351 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2352 | conversion->GetDexPc(), |
| 2353 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2354 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2357 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2358 | // Processing a Dex `double-to-long' instruction. |
| 2359 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2360 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2361 | conversion->GetDexPc(), |
| 2362 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2363 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2364 | break; |
| 2365 | |
| 2366 | default: |
| 2367 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2368 | << " to " << result_type; |
| 2369 | } |
| 2370 | break; |
| 2371 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2372 | case Primitive::kPrimChar: |
| 2373 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimLong: |
| 2375 | // Type conversion from long to char is a result of code transformations. |
| 2376 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2377 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimBoolean: |
| 2379 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimByte: |
| 2381 | case Primitive::kPrimShort: |
| 2382 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2383 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2384 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2389 | << " to " << result_type; |
| 2390 | } |
| 2391 | break; |
| 2392 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2393 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2394 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimBoolean: |
| 2396 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimByte: |
| 2398 | case Primitive::kPrimShort: |
| 2399 | case Primitive::kPrimInt: |
| 2400 | case Primitive::kPrimChar: { |
| 2401 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2402 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2403 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2404 | break; |
| 2405 | } |
| 2406 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2407 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2408 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2409 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2410 | conversion, |
| 2411 | conversion->GetDexPc(), |
| 2412 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2413 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2414 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2415 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2416 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2417 | // Processing a Dex `double-to-float' instruction. |
| 2418 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2419 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +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 | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2429 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimBoolean: |
| 2431 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimByte: |
| 2433 | case Primitive::kPrimShort: |
| 2434 | case Primitive::kPrimInt: |
| 2435 | case Primitive::kPrimChar: { |
| 2436 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2437 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2438 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2439 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2440 | break; |
| 2441 | } |
| 2442 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2443 | case Primitive::kPrimLong: { |
| 2444 | // Processing a Dex `long-to-double' instruction. |
| 2445 | Register low = in.AsRegisterPairLow<Register>(); |
| 2446 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2447 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2448 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2449 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2450 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2451 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2452 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2453 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2454 | // temp_d = int-to-double(high) |
| 2455 | __ vmovsr(temp_s, high); |
| 2456 | __ vcvtdi(temp_d, temp_s); |
| 2457 | // constant_d = k2Pow32EncodingForDouble |
| 2458 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2459 | // out_d = unsigned-to-double(low) |
| 2460 | __ vmovsr(out_s, low); |
| 2461 | __ vcvtdu(out_d, out_s); |
| 2462 | // out_d += temp_d * constant_d |
| 2463 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2464 | break; |
| 2465 | } |
| 2466 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2467 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2468 | // Processing a Dex `float-to-double' instruction. |
| 2469 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2470 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | |
| 2473 | default: |
| 2474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2475 | << " to " << result_type; |
| 2476 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2477 | break; |
| 2478 | |
| 2479 | default: |
| 2480 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2481 | << " to " << result_type; |
| 2482 | } |
| 2483 | } |
| 2484 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2485 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2486 | LocationSummary* locations = |
| 2487 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2488 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2489 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2490 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2491 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2492 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2493 | break; |
| 2494 | } |
| 2495 | |
| 2496 | case Primitive::kPrimLong: { |
| 2497 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2498 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2499 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2500 | break; |
| 2501 | } |
| 2502 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2503 | case Primitive::kPrimFloat: |
| 2504 | case Primitive::kPrimDouble: { |
| 2505 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2506 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2507 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2508 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2509 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2510 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2511 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2512 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2513 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2517 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2518 | Location out = locations->Out(); |
| 2519 | Location first = locations->InAt(0); |
| 2520 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2521 | switch (add->GetResultType()) { |
| 2522 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2523 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2524 | __ add(out.AsRegister<Register>(), |
| 2525 | first.AsRegister<Register>(), |
| 2526 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2527 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2528 | __ AddConstant(out.AsRegister<Register>(), |
| 2529 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2530 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2531 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2532 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2533 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimLong: { |
| 2535 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2536 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2537 | first.AsRegisterPairLow<Register>(), |
| 2538 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2539 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2540 | first.AsRegisterPairHigh<Register>(), |
| 2541 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2542 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2543 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2544 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2545 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2546 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2547 | first.AsFpuRegister<SRegister>(), |
| 2548 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2549 | break; |
| 2550 | |
| 2551 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2552 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2553 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2554 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2555 | break; |
| 2556 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2557 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2558 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2559 | } |
| 2560 | } |
| 2561 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2562 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2563 | LocationSummary* locations = |
| 2564 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2565 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2566 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2568 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2569 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2570 | break; |
| 2571 | } |
| 2572 | |
| 2573 | case Primitive::kPrimLong: { |
| 2574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2575 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2577 | break; |
| 2578 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2579 | case Primitive::kPrimFloat: |
| 2580 | case Primitive::kPrimDouble: { |
| 2581 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2582 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2583 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2584 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2585 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2586 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2587 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2588 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2592 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2593 | Location out = locations->Out(); |
| 2594 | Location first = locations->InAt(0); |
| 2595 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2596 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2597 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2598 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2599 | __ sub(out.AsRegister<Register>(), |
| 2600 | first.AsRegister<Register>(), |
| 2601 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2602 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2603 | __ AddConstant(out.AsRegister<Register>(), |
| 2604 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2605 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2606 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2607 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2608 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2609 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2610 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2611 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2612 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2613 | first.AsRegisterPairLow<Register>(), |
| 2614 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2615 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2616 | first.AsRegisterPairHigh<Register>(), |
| 2617 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2618 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2619 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2620 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2621 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2622 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2623 | first.AsFpuRegister<SRegister>(), |
| 2624 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2625 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2629 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2630 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2631 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2632 | break; |
| 2633 | } |
| 2634 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2635 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2636 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2637 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2641 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2642 | LocationSummary* locations = |
| 2643 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2644 | switch (mul->GetResultType()) { |
| 2645 | case Primitive::kPrimInt: |
| 2646 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2648 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2649 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2650 | break; |
| 2651 | } |
| 2652 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2653 | case Primitive::kPrimFloat: |
| 2654 | case Primitive::kPrimDouble: { |
| 2655 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2656 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2657 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2658 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2659 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2660 | |
| 2661 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2662 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2663 | } |
| 2664 | } |
| 2665 | |
| 2666 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2667 | LocationSummary* locations = mul->GetLocations(); |
| 2668 | Location out = locations->Out(); |
| 2669 | Location first = locations->InAt(0); |
| 2670 | Location second = locations->InAt(1); |
| 2671 | switch (mul->GetResultType()) { |
| 2672 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2673 | __ mul(out.AsRegister<Register>(), |
| 2674 | first.AsRegister<Register>(), |
| 2675 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2676 | break; |
| 2677 | } |
| 2678 | case Primitive::kPrimLong: { |
| 2679 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2680 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2681 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2682 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2683 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2684 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2685 | |
| 2686 | // Extra checks to protect caused by the existence of R1_R2. |
| 2687 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2688 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2689 | DCHECK_NE(out_hi, in1_lo); |
| 2690 | DCHECK_NE(out_hi, in2_lo); |
| 2691 | |
| 2692 | // input: in1 - 64 bits, in2 - 64 bits |
| 2693 | // output: out |
| 2694 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2695 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2696 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2697 | |
| 2698 | // IP <- in1.lo * in2.hi |
| 2699 | __ mul(IP, in1_lo, in2_hi); |
| 2700 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2701 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2702 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2703 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2704 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2705 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2706 | break; |
| 2707 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2708 | |
| 2709 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2710 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2711 | first.AsFpuRegister<SRegister>(), |
| 2712 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2713 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2717 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2718 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2719 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2720 | break; |
| 2721 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2722 | |
| 2723 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2724 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2725 | } |
| 2726 | } |
| 2727 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2728 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2729 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2730 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2731 | |
| 2732 | LocationSummary* locations = instruction->GetLocations(); |
| 2733 | Location second = locations->InAt(1); |
| 2734 | DCHECK(second.IsConstant()); |
| 2735 | |
| 2736 | Register out = locations->Out().AsRegister<Register>(); |
| 2737 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2738 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2739 | DCHECK(imm == 1 || imm == -1); |
| 2740 | |
| 2741 | if (instruction->IsRem()) { |
| 2742 | __ LoadImmediate(out, 0); |
| 2743 | } else { |
| 2744 | if (imm == 1) { |
| 2745 | __ Mov(out, dividend); |
| 2746 | } else { |
| 2747 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2753 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2754 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2755 | |
| 2756 | LocationSummary* locations = instruction->GetLocations(); |
| 2757 | Location second = locations->InAt(1); |
| 2758 | DCHECK(second.IsConstant()); |
| 2759 | |
| 2760 | Register out = locations->Out().AsRegister<Register>(); |
| 2761 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2762 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2763 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2764 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2765 | int ctz_imm = CTZ(abs_imm); |
| 2766 | |
| 2767 | if (ctz_imm == 1) { |
| 2768 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2769 | } else { |
| 2770 | __ Asr(temp, dividend, 31); |
| 2771 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2772 | } |
| 2773 | __ add(out, temp, ShifterOperand(dividend)); |
| 2774 | |
| 2775 | if (instruction->IsDiv()) { |
| 2776 | __ Asr(out, out, ctz_imm); |
| 2777 | if (imm < 0) { |
| 2778 | __ rsb(out, out, ShifterOperand(0)); |
| 2779 | } |
| 2780 | } else { |
| 2781 | __ ubfx(out, out, 0, ctz_imm); |
| 2782 | __ sub(out, out, ShifterOperand(temp)); |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2787 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2788 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2789 | |
| 2790 | LocationSummary* locations = instruction->GetLocations(); |
| 2791 | Location second = locations->InAt(1); |
| 2792 | DCHECK(second.IsConstant()); |
| 2793 | |
| 2794 | Register out = locations->Out().AsRegister<Register>(); |
| 2795 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2796 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2797 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2798 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2799 | |
| 2800 | int64_t magic; |
| 2801 | int shift; |
| 2802 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2803 | |
| 2804 | __ LoadImmediate(temp1, magic); |
| 2805 | __ smull(temp2, temp1, dividend, temp1); |
| 2806 | |
| 2807 | if (imm > 0 && magic < 0) { |
| 2808 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2809 | } else if (imm < 0 && magic > 0) { |
| 2810 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2811 | } |
| 2812 | |
| 2813 | if (shift != 0) { |
| 2814 | __ Asr(temp1, temp1, shift); |
| 2815 | } |
| 2816 | |
| 2817 | if (instruction->IsDiv()) { |
| 2818 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2819 | } else { |
| 2820 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2821 | // TODO: Strength reduction for mls. |
| 2822 | __ LoadImmediate(temp2, imm); |
| 2823 | __ mls(out, temp1, temp2, dividend); |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2828 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2829 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2830 | |
| 2831 | LocationSummary* locations = instruction->GetLocations(); |
| 2832 | Location second = locations->InAt(1); |
| 2833 | DCHECK(second.IsConstant()); |
| 2834 | |
| 2835 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2836 | if (imm == 0) { |
| 2837 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2838 | } else if (imm == 1 || imm == -1) { |
| 2839 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2840 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2841 | DivRemByPowerOfTwo(instruction); |
| 2842 | } else { |
| 2843 | DCHECK(imm <= -2 || imm >= 2); |
| 2844 | GenerateDivRemWithAnyConstant(instruction); |
| 2845 | } |
| 2846 | } |
| 2847 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2848 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2849 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2850 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2851 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2852 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2853 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2854 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2855 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2856 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2857 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2858 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2861 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2862 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2863 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2864 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2865 | if (div->InputAt(1)->IsConstant()) { |
| 2866 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2867 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2868 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2869 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 2870 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2871 | // No temp register required. |
| 2872 | } else { |
| 2873 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2874 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2875 | locations->AddTemp(Location::RequiresRegister()); |
| 2876 | } |
| 2877 | } |
| 2878 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2879 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2880 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2881 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2882 | } else { |
| 2883 | InvokeRuntimeCallingConvention calling_convention; |
| 2884 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2885 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2886 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2887 | // we only need the former. |
| 2888 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2889 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2892 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2893 | InvokeRuntimeCallingConvention calling_convention; |
| 2894 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2895 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2896 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2897 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2898 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | } |
| 2901 | case Primitive::kPrimFloat: |
| 2902 | case Primitive::kPrimDouble: { |
| 2903 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2904 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2905 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2906 | break; |
| 2907 | } |
| 2908 | |
| 2909 | default: |
| 2910 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2915 | LocationSummary* locations = div->GetLocations(); |
| 2916 | Location out = locations->Out(); |
| 2917 | Location first = locations->InAt(0); |
| 2918 | Location second = locations->InAt(1); |
| 2919 | |
| 2920 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2921 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2922 | if (second.IsConstant()) { |
| 2923 | GenerateDivRemConstantIntegral(div); |
| 2924 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2925 | __ sdiv(out.AsRegister<Register>(), |
| 2926 | first.AsRegister<Register>(), |
| 2927 | second.AsRegister<Register>()); |
| 2928 | } else { |
| 2929 | InvokeRuntimeCallingConvention calling_convention; |
| 2930 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2931 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2932 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2933 | |
| 2934 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2935 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2936 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2937 | break; |
| 2938 | } |
| 2939 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2940 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2941 | InvokeRuntimeCallingConvention calling_convention; |
| 2942 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2943 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2944 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2945 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2946 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2947 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2948 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2949 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2950 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2951 | break; |
| 2952 | } |
| 2953 | |
| 2954 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2955 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2956 | first.AsFpuRegister<SRegister>(), |
| 2957 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2958 | break; |
| 2959 | } |
| 2960 | |
| 2961 | case Primitive::kPrimDouble: { |
| 2962 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2963 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2964 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2965 | break; |
| 2966 | } |
| 2967 | |
| 2968 | default: |
| 2969 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2970 | } |
| 2971 | } |
| 2972 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2973 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2974 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2975 | |
| 2976 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2977 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2978 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 2979 | // sdiv will be replaced by other instruction sequence. |
| 2980 | call_kind = LocationSummary::kNoCall; |
| 2981 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 2982 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2983 | // Have hardware divide instruction for int, do it with three instructions. |
| 2984 | call_kind = LocationSummary::kNoCall; |
| 2985 | } |
| 2986 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2987 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2988 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2989 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2990 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2991 | if (rem->InputAt(1)->IsConstant()) { |
| 2992 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2993 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2994 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2995 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 2996 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2997 | // No temp register required. |
| 2998 | } else { |
| 2999 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3000 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3001 | locations->AddTemp(Location::RequiresRegister()); |
| 3002 | } |
| 3003 | } |
| 3004 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3005 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3006 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3007 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3008 | locations->AddTemp(Location::RequiresRegister()); |
| 3009 | } else { |
| 3010 | InvokeRuntimeCallingConvention calling_convention; |
| 3011 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3012 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3013 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3014 | // we only need the latter. |
| 3015 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3016 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3017 | break; |
| 3018 | } |
| 3019 | case Primitive::kPrimLong: { |
| 3020 | InvokeRuntimeCallingConvention calling_convention; |
| 3021 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3022 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3023 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3024 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3025 | // The runtime helper puts the output in R2,R3. |
| 3026 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3027 | break; |
| 3028 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3029 | case Primitive::kPrimFloat: { |
| 3030 | InvokeRuntimeCallingConvention calling_convention; |
| 3031 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3032 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3033 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3034 | break; |
| 3035 | } |
| 3036 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3037 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3038 | InvokeRuntimeCallingConvention calling_convention; |
| 3039 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3040 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3041 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3042 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3043 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3044 | break; |
| 3045 | } |
| 3046 | |
| 3047 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3048 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3053 | LocationSummary* locations = rem->GetLocations(); |
| 3054 | Location out = locations->Out(); |
| 3055 | Location first = locations->InAt(0); |
| 3056 | Location second = locations->InAt(1); |
| 3057 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3058 | Primitive::Type type = rem->GetResultType(); |
| 3059 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3060 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3061 | if (second.IsConstant()) { |
| 3062 | GenerateDivRemConstantIntegral(rem); |
| 3063 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3064 | Register reg1 = first.AsRegister<Register>(); |
| 3065 | Register reg2 = second.AsRegister<Register>(); |
| 3066 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3067 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3068 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3069 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3070 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3071 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3072 | } else { |
| 3073 | InvokeRuntimeCallingConvention calling_convention; |
| 3074 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3075 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3076 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3077 | |
| 3078 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3079 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3080 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3081 | break; |
| 3082 | } |
| 3083 | |
| 3084 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3085 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3086 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3087 | break; |
| 3088 | } |
| 3089 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3090 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3091 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3092 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3093 | break; |
| 3094 | } |
| 3095 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3096 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3097 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3098 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3099 | break; |
| 3100 | } |
| 3101 | |
| 3102 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3103 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3107 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3108 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3109 | ? LocationSummary::kCallOnSlowPath |
| 3110 | : LocationSummary::kNoCall; |
| 3111 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3112 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3113 | if (instruction->HasUses()) { |
| 3114 | locations->SetOut(Location::SameAsFirstInput()); |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3119 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3120 | codegen_->AddSlowPath(slow_path); |
| 3121 | |
| 3122 | LocationSummary* locations = instruction->GetLocations(); |
| 3123 | Location value = locations->InAt(0); |
| 3124 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3125 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3126 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3127 | case Primitive::kPrimByte: |
| 3128 | case Primitive::kPrimChar: |
| 3129 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3130 | case Primitive::kPrimInt: { |
| 3131 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3132 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3133 | } else { |
| 3134 | DCHECK(value.IsConstant()) << value; |
| 3135 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3136 | __ b(slow_path->GetEntryLabel()); |
| 3137 | } |
| 3138 | } |
| 3139 | break; |
| 3140 | } |
| 3141 | case Primitive::kPrimLong: { |
| 3142 | if (value.IsRegisterPair()) { |
| 3143 | __ orrs(IP, |
| 3144 | value.AsRegisterPairLow<Register>(), |
| 3145 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3146 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3147 | } else { |
| 3148 | DCHECK(value.IsConstant()) << value; |
| 3149 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3150 | __ b(slow_path->GetEntryLabel()); |
| 3151 | } |
| 3152 | } |
| 3153 | break; |
| 3154 | default: |
| 3155 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3156 | } |
| 3157 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3160 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3161 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3162 | Location rhs = locations->InAt(1); |
| 3163 | Register out = locations->Out().AsRegister<Register>(); |
| 3164 | |
| 3165 | if (rhs.IsConstant()) { |
| 3166 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3167 | // so map all rotations to a +ve. equivalent in that range. |
| 3168 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3169 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3170 | if (rot) { |
| 3171 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3172 | // (e.g. left by 2 bits == right by 30.) |
| 3173 | __ Ror(out, in, rot); |
| 3174 | } else if (out != in) { |
| 3175 | __ Mov(out, in); |
| 3176 | } |
| 3177 | } else { |
| 3178 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3183 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3184 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3185 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3186 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3187 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3188 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3189 | Location rhs = locations->InAt(1); |
| 3190 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3191 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3192 | |
| 3193 | if (rhs.IsConstant()) { |
| 3194 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3195 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3196 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3197 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3198 | // logic below to a simple pair of binary orr. |
| 3199 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3200 | if (rot >= kArmBitsPerWord) { |
| 3201 | rot -= kArmBitsPerWord; |
| 3202 | std::swap(in_reg_hi, in_reg_lo); |
| 3203 | } |
| 3204 | // Rotate, or mov to out for zero or word size rotations. |
| 3205 | if (rot != 0u) { |
| 3206 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3207 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3208 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3209 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3210 | } else { |
| 3211 | __ Mov(out_reg_lo, in_reg_lo); |
| 3212 | __ Mov(out_reg_hi, in_reg_hi); |
| 3213 | } |
| 3214 | } else { |
| 3215 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3216 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3217 | Label end; |
| 3218 | Label shift_by_32_plus_shift_right; |
| 3219 | |
| 3220 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3221 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3222 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3223 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3224 | |
| 3225 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3226 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3227 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3228 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3229 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3230 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3231 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3232 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3233 | __ b(&end); |
| 3234 | |
| 3235 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3236 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3237 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3238 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3239 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3240 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3241 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3242 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3243 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3244 | |
| 3245 | __ Bind(&end); |
| 3246 | } |
| 3247 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3248 | |
| 3249 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3250 | LocationSummary* locations = |
| 3251 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3252 | switch (ror->GetResultType()) { |
| 3253 | case Primitive::kPrimInt: { |
| 3254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3255 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3256 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3257 | break; |
| 3258 | } |
| 3259 | case Primitive::kPrimLong: { |
| 3260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3261 | if (ror->InputAt(1)->IsConstant()) { |
| 3262 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3263 | } else { |
| 3264 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3265 | locations->AddTemp(Location::RequiresRegister()); |
| 3266 | locations->AddTemp(Location::RequiresRegister()); |
| 3267 | } |
| 3268 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3269 | break; |
| 3270 | } |
| 3271 | default: |
| 3272 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3273 | } |
| 3274 | } |
| 3275 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3276 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3277 | LocationSummary* locations = ror->GetLocations(); |
| 3278 | Primitive::Type type = ror->GetResultType(); |
| 3279 | switch (type) { |
| 3280 | case Primitive::kPrimInt: { |
| 3281 | HandleIntegerRotate(locations); |
| 3282 | break; |
| 3283 | } |
| 3284 | case Primitive::kPrimLong: { |
| 3285 | HandleLongRotate(locations); |
| 3286 | break; |
| 3287 | } |
| 3288 | default: |
| 3289 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3290 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3291 | } |
| 3292 | } |
| 3293 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3294 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3295 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3296 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3297 | LocationSummary* locations = |
| 3298 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3299 | |
| 3300 | switch (op->GetResultType()) { |
| 3301 | case Primitive::kPrimInt: { |
| 3302 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3303 | if (op->InputAt(1)->IsConstant()) { |
| 3304 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3305 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3306 | } else { |
| 3307 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3308 | // Make the output overlap, as it will be used to hold the masked |
| 3309 | // second input. |
| 3310 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3311 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3312 | break; |
| 3313 | } |
| 3314 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3315 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3316 | if (op->InputAt(1)->IsConstant()) { |
| 3317 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3318 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3319 | // don't clash with high registers which the register allocator currently guarantees. |
| 3320 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3321 | } else { |
| 3322 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3323 | locations->AddTemp(Location::RequiresRegister()); |
| 3324 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3325 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3326 | break; |
| 3327 | } |
| 3328 | default: |
| 3329 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3334 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3335 | |
| 3336 | LocationSummary* locations = op->GetLocations(); |
| 3337 | Location out = locations->Out(); |
| 3338 | Location first = locations->InAt(0); |
| 3339 | Location second = locations->InAt(1); |
| 3340 | |
| 3341 | Primitive::Type type = op->GetResultType(); |
| 3342 | switch (type) { |
| 3343 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3344 | Register out_reg = out.AsRegister<Register>(); |
| 3345 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3346 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3347 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3348 | // 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] | 3349 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3350 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3351 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3352 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3353 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3354 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3355 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3356 | } |
| 3357 | } else { |
| 3358 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3359 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3360 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3361 | __ Mov(out_reg, first_reg); |
| 3362 | } else if (op->IsShl()) { |
| 3363 | __ Lsl(out_reg, first_reg, shift_value); |
| 3364 | } else if (op->IsShr()) { |
| 3365 | __ Asr(out_reg, first_reg, shift_value); |
| 3366 | } else { |
| 3367 | __ Lsr(out_reg, first_reg, shift_value); |
| 3368 | } |
| 3369 | } |
| 3370 | break; |
| 3371 | } |
| 3372 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3373 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3374 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3375 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3376 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3377 | Register low = first.AsRegisterPairLow<Register>(); |
| 3378 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3379 | if (second.IsRegister()) { |
| 3380 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3381 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3382 | Register second_reg = second.AsRegister<Register>(); |
| 3383 | |
| 3384 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3385 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3386 | // Shift the high part |
| 3387 | __ Lsl(o_h, high, o_l); |
| 3388 | // Shift the low part and `or` what overflew on the high part |
| 3389 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3390 | __ Lsr(temp, low, temp); |
| 3391 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3392 | // If the shift is > 32 bits, override the high part |
| 3393 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3394 | __ it(PL); |
| 3395 | __ Lsl(o_h, low, temp, PL); |
| 3396 | // Shift the low part |
| 3397 | __ Lsl(o_l, low, o_l); |
| 3398 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3399 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3400 | // Shift the low part |
| 3401 | __ Lsr(o_l, low, o_h); |
| 3402 | // Shift the high part and `or` what underflew on the low part |
| 3403 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3404 | __ Lsl(temp, high, temp); |
| 3405 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3406 | // If the shift is > 32 bits, override the low part |
| 3407 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3408 | __ it(PL); |
| 3409 | __ Asr(o_l, high, temp, PL); |
| 3410 | // Shift the high part |
| 3411 | __ Asr(o_h, high, o_h); |
| 3412 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3413 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3414 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3415 | __ Lsr(o_l, low, o_h); |
| 3416 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3417 | __ Lsl(temp, high, temp); |
| 3418 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3419 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3420 | __ it(PL); |
| 3421 | __ Lsr(o_l, high, temp, PL); |
| 3422 | __ Lsr(o_h, high, o_h); |
| 3423 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3424 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3425 | // Register allocator doesn't create partial overlap. |
| 3426 | DCHECK_NE(o_l, high); |
| 3427 | DCHECK_NE(o_h, low); |
| 3428 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3429 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3430 | if (shift_value > 32) { |
| 3431 | if (op->IsShl()) { |
| 3432 | __ Lsl(o_h, low, shift_value - 32); |
| 3433 | __ LoadImmediate(o_l, 0); |
| 3434 | } else if (op->IsShr()) { |
| 3435 | __ Asr(o_l, high, shift_value - 32); |
| 3436 | __ Asr(o_h, high, 31); |
| 3437 | } else { |
| 3438 | __ Lsr(o_l, high, shift_value - 32); |
| 3439 | __ LoadImmediate(o_h, 0); |
| 3440 | } |
| 3441 | } else if (shift_value == 32) { |
| 3442 | if (op->IsShl()) { |
| 3443 | __ mov(o_h, ShifterOperand(low)); |
| 3444 | __ LoadImmediate(o_l, 0); |
| 3445 | } else if (op->IsShr()) { |
| 3446 | __ mov(o_l, ShifterOperand(high)); |
| 3447 | __ Asr(o_h, high, 31); |
| 3448 | } else { |
| 3449 | __ mov(o_l, ShifterOperand(high)); |
| 3450 | __ LoadImmediate(o_h, 0); |
| 3451 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3452 | } else if (shift_value == 1) { |
| 3453 | if (op->IsShl()) { |
| 3454 | __ Lsls(o_l, low, 1); |
| 3455 | __ adc(o_h, high, ShifterOperand(high)); |
| 3456 | } else if (op->IsShr()) { |
| 3457 | __ Asrs(o_h, high, 1); |
| 3458 | __ Rrx(o_l, low); |
| 3459 | } else { |
| 3460 | __ Lsrs(o_h, high, 1); |
| 3461 | __ Rrx(o_l, low); |
| 3462 | } |
| 3463 | } else { |
| 3464 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3465 | if (op->IsShl()) { |
| 3466 | __ Lsl(o_h, high, shift_value); |
| 3467 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3468 | __ Lsl(o_l, low, shift_value); |
| 3469 | } else if (op->IsShr()) { |
| 3470 | __ Lsr(o_l, low, shift_value); |
| 3471 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3472 | __ Asr(o_h, high, shift_value); |
| 3473 | } else { |
| 3474 | __ Lsr(o_l, low, shift_value); |
| 3475 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3476 | __ Lsr(o_h, high, shift_value); |
| 3477 | } |
| 3478 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3479 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3480 | break; |
| 3481 | } |
| 3482 | default: |
| 3483 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3484 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3489 | HandleShift(shl); |
| 3490 | } |
| 3491 | |
| 3492 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3493 | HandleShift(shl); |
| 3494 | } |
| 3495 | |
| 3496 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3497 | HandleShift(shr); |
| 3498 | } |
| 3499 | |
| 3500 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3501 | HandleShift(shr); |
| 3502 | } |
| 3503 | |
| 3504 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3505 | HandleShift(ushr); |
| 3506 | } |
| 3507 | |
| 3508 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3509 | HandleShift(ushr); |
| 3510 | } |
| 3511 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3512 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3513 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3514 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3515 | if (instruction->IsStringAlloc()) { |
| 3516 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3517 | } else { |
| 3518 | InvokeRuntimeCallingConvention calling_convention; |
| 3519 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3520 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3521 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3522 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3526 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3527 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3528 | if (instruction->IsStringAlloc()) { |
| 3529 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3530 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3531 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize); |
| 3532 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3533 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3534 | __ blx(LR); |
| 3535 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3536 | } else { |
| 3537 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3538 | instruction, |
| 3539 | instruction->GetDexPc(), |
| 3540 | nullptr); |
| 3541 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3542 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3543 | } |
| 3544 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3545 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3546 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3547 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3548 | InvokeRuntimeCallingConvention calling_convention; |
| 3549 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3550 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3551 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3552 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3556 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3557 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3558 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3559 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3560 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3561 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3562 | instruction->GetDexPc(), |
| 3563 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3564 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3567 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3568 | LocationSummary* locations = |
| 3569 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3570 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3571 | if (location.IsStackSlot()) { |
| 3572 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3573 | } else if (location.IsDoubleStackSlot()) { |
| 3574 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3575 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3576 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3577 | } |
| 3578 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3579 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3580 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3581 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3585 | LocationSummary* locations = |
| 3586 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3587 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3588 | } |
| 3589 | |
| 3590 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3591 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3592 | } |
| 3593 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3594 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3595 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3596 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3597 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3598 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3599 | } |
| 3600 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3601 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3602 | LocationSummary* locations = not_->GetLocations(); |
| 3603 | Location out = locations->Out(); |
| 3604 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3605 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3606 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3607 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3608 | break; |
| 3609 | |
| 3610 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3611 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3612 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3613 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3614 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3615 | break; |
| 3616 | |
| 3617 | default: |
| 3618 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3619 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3622 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3623 | LocationSummary* locations = |
| 3624 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3625 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3626 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3627 | } |
| 3628 | |
| 3629 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3630 | LocationSummary* locations = bool_not->GetLocations(); |
| 3631 | Location out = locations->Out(); |
| 3632 | Location in = locations->InAt(0); |
| 3633 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3634 | } |
| 3635 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3636 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3637 | LocationSummary* locations = |
| 3638 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3639 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3640 | case Primitive::kPrimBoolean: |
| 3641 | case Primitive::kPrimByte: |
| 3642 | case Primitive::kPrimShort: |
| 3643 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3644 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3645 | case Primitive::kPrimLong: { |
| 3646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3647 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3648 | // Output overlaps because it is written before doing the low comparison. |
| 3649 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3650 | break; |
| 3651 | } |
| 3652 | case Primitive::kPrimFloat: |
| 3653 | case Primitive::kPrimDouble: { |
| 3654 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3655 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3656 | locations->SetOut(Location::RequiresRegister()); |
| 3657 | break; |
| 3658 | } |
| 3659 | default: |
| 3660 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3661 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3665 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3666 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3667 | Location left = locations->InAt(0); |
| 3668 | Location right = locations->InAt(1); |
| 3669 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3670 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3671 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3672 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3673 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3674 | case Primitive::kPrimBoolean: |
| 3675 | case Primitive::kPrimByte: |
| 3676 | case Primitive::kPrimShort: |
| 3677 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3678 | case Primitive::kPrimInt: { |
| 3679 | __ LoadImmediate(out, 0); |
| 3680 | __ cmp(left.AsRegister<Register>(), |
| 3681 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3682 | less_cond = LT; |
| 3683 | break; |
| 3684 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3685 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3686 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3687 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3688 | __ b(&less, LT); |
| 3689 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3690 | // 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] | 3691 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3692 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3693 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3694 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3695 | break; |
| 3696 | } |
| 3697 | case Primitive::kPrimFloat: |
| 3698 | case Primitive::kPrimDouble: { |
| 3699 | __ LoadImmediate(out, 0); |
| 3700 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3701 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3702 | } else { |
| 3703 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3704 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3705 | } |
| 3706 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3707 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3708 | break; |
| 3709 | } |
| 3710 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3711 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3712 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3713 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3714 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3715 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3716 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3717 | |
| 3718 | __ Bind(&greater); |
| 3719 | __ LoadImmediate(out, 1); |
| 3720 | __ b(&done); |
| 3721 | |
| 3722 | __ Bind(&less); |
| 3723 | __ LoadImmediate(out, -1); |
| 3724 | |
| 3725 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3726 | } |
| 3727 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3728 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3729 | LocationSummary* locations = |
| 3730 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3731 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3732 | locations->SetInAt(i, Location::Any()); |
| 3733 | } |
| 3734 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3735 | } |
| 3736 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3737 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3738 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3741 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3742 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3743 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3744 | switch (kind) { |
| 3745 | case MemBarrierKind::kAnyStore: |
| 3746 | case MemBarrierKind::kLoadAny: |
| 3747 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3748 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3749 | break; |
| 3750 | } |
| 3751 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3752 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | default: |
| 3756 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3757 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3758 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3762 | uint32_t offset, |
| 3763 | Register out_lo, |
| 3764 | Register out_hi) { |
| 3765 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3766 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3767 | // `offset` into `out_lo` does not clutter `addr`. |
| 3768 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3769 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3770 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3771 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3772 | } |
| 3773 | __ ldrexd(out_lo, out_hi, addr); |
| 3774 | } |
| 3775 | |
| 3776 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3777 | uint32_t offset, |
| 3778 | Register value_lo, |
| 3779 | Register value_hi, |
| 3780 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3781 | Register temp2, |
| 3782 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3783 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3784 | if (offset != 0) { |
| 3785 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3786 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3787 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3788 | } |
| 3789 | __ Bind(&fail); |
| 3790 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3791 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3792 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3794 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3795 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3799 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3800 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3801 | LocationSummary* locations = |
| 3802 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3803 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3804 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3805 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3806 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3807 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3808 | } else { |
| 3809 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3810 | } |
| 3811 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3812 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3813 | bool generate_volatile = field_info.IsVolatile() |
| 3814 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3815 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3816 | bool needs_write_barrier = |
| 3817 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3818 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3819 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3820 | if (needs_write_barrier) { |
| 3821 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3822 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3823 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3824 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3825 | // - registers need to be consecutive |
| 3826 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3827 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3828 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3829 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3830 | |
| 3831 | locations->AddTemp(Location::RequiresRegister()); |
| 3832 | locations->AddTemp(Location::RequiresRegister()); |
| 3833 | if (field_type == Primitive::kPrimDouble) { |
| 3834 | // For doubles we need two more registers to copy the value. |
| 3835 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3836 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3837 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3838 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3839 | } |
| 3840 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3841 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3842 | const FieldInfo& field_info, |
| 3843 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3844 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3845 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3846 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3847 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3848 | Location value = locations->InAt(1); |
| 3849 | |
| 3850 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3851 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3852 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3853 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3854 | bool needs_write_barrier = |
| 3855 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3856 | |
| 3857 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3858 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3859 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3860 | |
| 3861 | switch (field_type) { |
| 3862 | case Primitive::kPrimBoolean: |
| 3863 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3864 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3865 | break; |
| 3866 | } |
| 3867 | |
| 3868 | case Primitive::kPrimShort: |
| 3869 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3870 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3871 | break; |
| 3872 | } |
| 3873 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3874 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3875 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3876 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3877 | // Note that in the case where `value` is a null reference, |
| 3878 | // we do not enter this block, as a null reference does not |
| 3879 | // need poisoning. |
| 3880 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3881 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3882 | __ Mov(temp, value.AsRegister<Register>()); |
| 3883 | __ PoisonHeapReference(temp); |
| 3884 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3885 | } else { |
| 3886 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3887 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3888 | break; |
| 3889 | } |
| 3890 | |
| 3891 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3892 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3893 | GenerateWideAtomicStore(base, offset, |
| 3894 | value.AsRegisterPairLow<Register>(), |
| 3895 | value.AsRegisterPairHigh<Register>(), |
| 3896 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3897 | locations->GetTemp(1).AsRegister<Register>(), |
| 3898 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3899 | } else { |
| 3900 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3901 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3902 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3903 | break; |
| 3904 | } |
| 3905 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3906 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3907 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3908 | break; |
| 3909 | } |
| 3910 | |
| 3911 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3912 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3913 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3914 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3915 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3916 | |
| 3917 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3918 | |
| 3919 | GenerateWideAtomicStore(base, offset, |
| 3920 | value_reg_lo, |
| 3921 | value_reg_hi, |
| 3922 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3923 | locations->GetTemp(3).AsRegister<Register>(), |
| 3924 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3925 | } else { |
| 3926 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3927 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3928 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3929 | break; |
| 3930 | } |
| 3931 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3932 | case Primitive::kPrimVoid: |
| 3933 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3934 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3935 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3936 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3937 | // Longs and doubles are handled in the switch. |
| 3938 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3939 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3940 | } |
| 3941 | |
| 3942 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3943 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3944 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3945 | codegen_->MarkGCCard( |
| 3946 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3949 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3950 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3951 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3952 | } |
| 3953 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3954 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3955 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3956 | |
| 3957 | bool object_field_get_with_read_barrier = |
| 3958 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3959 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3960 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 3961 | object_field_get_with_read_barrier ? |
| 3962 | LocationSummary::kCallOnSlowPath : |
| 3963 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3964 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3965 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3966 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3967 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3968 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3969 | // The output overlaps in case of volatile long: we don't want the |
| 3970 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 3971 | // object's location. Likewise, in the case of an object field get |
| 3972 | // with read barriers enabled, we do not want the load to overwrite |
| 3973 | // the object's location, as we need it to emit the read barrier. |
| 3974 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 3975 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3976 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3977 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3978 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3979 | } else { |
| 3980 | locations->SetOut(Location::RequiresRegister(), |
| 3981 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3982 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3983 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3984 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3985 | // - registers need to be consecutive |
| 3986 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3987 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3988 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3989 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3990 | locations->AddTemp(Location::RequiresRegister()); |
| 3991 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3992 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 3993 | // We need a temporary register for the read barrier marking slow |
| 3994 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 3995 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3996 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 3999 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4000 | Opcode opcode) { |
| 4001 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4002 | if (constant->IsConstant() && |
| 4003 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4004 | return Location::ConstantLocation(constant->AsConstant()); |
| 4005 | } |
| 4006 | return Location::RequiresRegister(); |
| 4007 | } |
| 4008 | |
| 4009 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4010 | Opcode opcode) { |
| 4011 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4012 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 4013 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode) && |
| 4014 | CanEncodeConstantAsImmediate(High32Bits(value), opcode); |
| 4015 | } else { |
| 4016 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode) { |
| 4021 | ShifterOperand so; |
| 4022 | ArmAssembler* assembler = codegen_->GetAssembler(); |
| 4023 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, &so)) { |
| 4024 | return true; |
| 4025 | } |
| 4026 | Opcode neg_opcode = kNoOperand; |
| 4027 | switch (opcode) { |
| 4028 | case AND: |
| 4029 | neg_opcode = BIC; |
| 4030 | break; |
| 4031 | case ORR: |
| 4032 | neg_opcode = ORN; |
| 4033 | break; |
| 4034 | default: |
| 4035 | return false; |
| 4036 | } |
| 4037 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, ~value, &so); |
| 4038 | } |
| 4039 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4040 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4041 | const FieldInfo& field_info) { |
| 4042 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4043 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4044 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4045 | Location base_loc = locations->InAt(0); |
| 4046 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4047 | Location out = locations->Out(); |
| 4048 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4049 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4050 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4051 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4052 | |
| 4053 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4054 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4055 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4056 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4057 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4058 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4059 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4060 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4061 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4062 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4063 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4064 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4065 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4066 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4067 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4068 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4069 | |
| 4070 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4071 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4072 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4073 | |
| 4074 | case Primitive::kPrimNot: { |
| 4075 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4076 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4077 | Location temp_loc = locations->GetTemp(0); |
| 4078 | // Note that a potential implicit null check is handled in this |
| 4079 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4080 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4081 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4082 | if (is_volatile) { |
| 4083 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4084 | } |
| 4085 | } else { |
| 4086 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4087 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4088 | if (is_volatile) { |
| 4089 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4090 | } |
| 4091 | // If read barriers are enabled, emit read barriers other than |
| 4092 | // Baker's using a slow path (and also unpoison the loaded |
| 4093 | // reference, if heap poisoning is enabled). |
| 4094 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4095 | } |
| 4096 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4097 | } |
| 4098 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4099 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4100 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4101 | GenerateWideAtomicLoad(base, offset, |
| 4102 | out.AsRegisterPairLow<Register>(), |
| 4103 | out.AsRegisterPairHigh<Register>()); |
| 4104 | } else { |
| 4105 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4106 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4107 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4108 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4109 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4110 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4111 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4112 | |
| 4113 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4114 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4115 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4116 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4117 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4118 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4119 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4120 | __ vmovdrr(out_reg, lo, hi); |
| 4121 | } else { |
| 4122 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4123 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4124 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4125 | break; |
| 4126 | } |
| 4127 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4128 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4129 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4130 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4131 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4132 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4133 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4134 | // Potential implicit null checks, in the case of reference or |
| 4135 | // double fields, are handled in the previous switch statement. |
| 4136 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4137 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4138 | } |
| 4139 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4140 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4141 | if (field_type == Primitive::kPrimNot) { |
| 4142 | // Memory barriers, in the case of references, are also handled |
| 4143 | // in the previous switch statement. |
| 4144 | } else { |
| 4145 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4146 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4147 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4151 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4152 | } |
| 4153 | |
| 4154 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4155 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4159 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4160 | } |
| 4161 | |
| 4162 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4163 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4164 | } |
| 4165 | |
| 4166 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4167 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4168 | } |
| 4169 | |
| 4170 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4171 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4172 | } |
| 4173 | |
| 4174 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4175 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4176 | } |
| 4177 | |
| 4178 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4179 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4182 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4183 | HUnresolvedInstanceFieldGet* instruction) { |
| 4184 | FieldAccessCallingConventionARM calling_convention; |
| 4185 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4186 | instruction, instruction->GetFieldType(), calling_convention); |
| 4187 | } |
| 4188 | |
| 4189 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4190 | HUnresolvedInstanceFieldGet* instruction) { |
| 4191 | FieldAccessCallingConventionARM calling_convention; |
| 4192 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4193 | instruction->GetFieldType(), |
| 4194 | instruction->GetFieldIndex(), |
| 4195 | instruction->GetDexPc(), |
| 4196 | calling_convention); |
| 4197 | } |
| 4198 | |
| 4199 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4200 | HUnresolvedInstanceFieldSet* instruction) { |
| 4201 | FieldAccessCallingConventionARM calling_convention; |
| 4202 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4203 | instruction, instruction->GetFieldType(), calling_convention); |
| 4204 | } |
| 4205 | |
| 4206 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4207 | HUnresolvedInstanceFieldSet* instruction) { |
| 4208 | FieldAccessCallingConventionARM calling_convention; |
| 4209 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4210 | instruction->GetFieldType(), |
| 4211 | instruction->GetFieldIndex(), |
| 4212 | instruction->GetDexPc(), |
| 4213 | calling_convention); |
| 4214 | } |
| 4215 | |
| 4216 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4217 | HUnresolvedStaticFieldGet* instruction) { |
| 4218 | FieldAccessCallingConventionARM calling_convention; |
| 4219 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4220 | instruction, instruction->GetFieldType(), calling_convention); |
| 4221 | } |
| 4222 | |
| 4223 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4224 | HUnresolvedStaticFieldGet* instruction) { |
| 4225 | FieldAccessCallingConventionARM calling_convention; |
| 4226 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4227 | instruction->GetFieldType(), |
| 4228 | instruction->GetFieldIndex(), |
| 4229 | instruction->GetDexPc(), |
| 4230 | calling_convention); |
| 4231 | } |
| 4232 | |
| 4233 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4234 | HUnresolvedStaticFieldSet* instruction) { |
| 4235 | FieldAccessCallingConventionARM calling_convention; |
| 4236 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4237 | instruction, instruction->GetFieldType(), calling_convention); |
| 4238 | } |
| 4239 | |
| 4240 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4241 | HUnresolvedStaticFieldSet* instruction) { |
| 4242 | FieldAccessCallingConventionARM calling_convention; |
| 4243 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4244 | instruction->GetFieldType(), |
| 4245 | instruction->GetFieldIndex(), |
| 4246 | instruction->GetDexPc(), |
| 4247 | calling_convention); |
| 4248 | } |
| 4249 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4250 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4251 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4252 | ? LocationSummary::kCallOnSlowPath |
| 4253 | : LocationSummary::kNoCall; |
| 4254 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4255 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4256 | if (instruction->HasUses()) { |
| 4257 | locations->SetOut(Location::SameAsFirstInput()); |
| 4258 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4259 | } |
| 4260 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4261 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4262 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4263 | return; |
| 4264 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4265 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4266 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4267 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4268 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4271 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4272 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4273 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4274 | |
| 4275 | LocationSummary* locations = instruction->GetLocations(); |
| 4276 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4277 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4278 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4279 | } |
| 4280 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4281 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4282 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4285 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4286 | bool object_array_get_with_read_barrier = |
| 4287 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4288 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4289 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4290 | object_array_get_with_read_barrier ? |
| 4291 | LocationSummary::kCallOnSlowPath : |
| 4292 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4293 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4294 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4295 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4296 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4297 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4298 | // The output overlaps in the case of an object array get with |
| 4299 | // read barriers enabled: we do not want the move to overwrite the |
| 4300 | // array's location, as we need it to emit the read barrier. |
| 4301 | locations->SetOut( |
| 4302 | Location::RequiresRegister(), |
| 4303 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4304 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4305 | // We need a temporary register for the read barrier marking slow |
| 4306 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4307 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4308 | locations->AddTemp(Location::RequiresRegister()); |
| 4309 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4313 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4314 | Location obj_loc = locations->InAt(0); |
| 4315 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4316 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4317 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4318 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4319 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4320 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4321 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4322 | case Primitive::kPrimBoolean: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4323 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4324 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4325 | size_t offset = |
| 4326 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4327 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 4328 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4329 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4330 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 4331 | } |
| 4332 | break; |
| 4333 | } |
| 4334 | |
| 4335 | case Primitive::kPrimByte: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4336 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4337 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4338 | size_t offset = |
| 4339 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4340 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 4341 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4342 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4343 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 4344 | } |
| 4345 | break; |
| 4346 | } |
| 4347 | |
| 4348 | case Primitive::kPrimShort: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4349 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4350 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4351 | size_t offset = |
| 4352 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4353 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 4354 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4355 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4356 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 4357 | } |
| 4358 | break; |
| 4359 | } |
| 4360 | |
| 4361 | case Primitive::kPrimChar: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4362 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4363 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4364 | size_t offset = |
| 4365 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4366 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 4367 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4368 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4369 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 4370 | } |
| 4371 | break; |
| 4372 | } |
| 4373 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4374 | case Primitive::kPrimInt: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4375 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4376 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4377 | size_t offset = |
| 4378 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4379 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4380 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4381 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4382 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4383 | } |
| 4384 | break; |
| 4385 | } |
| 4386 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4387 | case Primitive::kPrimNot: { |
| 4388 | static_assert( |
| 4389 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4390 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4391 | // /* HeapReference<Object> */ out = |
| 4392 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4393 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4394 | Location temp = locations->GetTemp(0); |
| 4395 | // Note that a potential implicit null check is handled in this |
| 4396 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4397 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4398 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4399 | } else { |
| 4400 | Register out = out_loc.AsRegister<Register>(); |
| 4401 | if (index.IsConstant()) { |
| 4402 | size_t offset = |
| 4403 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4404 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4405 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4406 | // If read barriers are enabled, emit read barriers other than |
| 4407 | // Baker's using a slow path (and also unpoison the loaded |
| 4408 | // reference, if heap poisoning is enabled). |
| 4409 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4410 | } else { |
| 4411 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4412 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4413 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4414 | // If read barriers are enabled, emit read barriers other than |
| 4415 | // Baker's using a slow path (and also unpoison the loaded |
| 4416 | // reference, if heap poisoning is enabled). |
| 4417 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4418 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4419 | } |
| 4420 | } |
| 4421 | break; |
| 4422 | } |
| 4423 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4424 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4425 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4426 | size_t offset = |
| 4427 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4428 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4429 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4430 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4431 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4432 | } |
| 4433 | break; |
| 4434 | } |
| 4435 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4436 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4437 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4438 | if (index.IsConstant()) { |
| 4439 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4440 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4441 | } else { |
| 4442 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4443 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4444 | } |
| 4445 | break; |
| 4446 | } |
| 4447 | |
| 4448 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4449 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4450 | if (index.IsConstant()) { |
| 4451 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4452 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4453 | } else { |
| 4454 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4455 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4456 | } |
| 4457 | break; |
| 4458 | } |
| 4459 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4460 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4461 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4462 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4463 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4464 | |
| 4465 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4466 | // Potential implicit null checks, in the case of reference |
| 4467 | // arrays, are handled in the previous switch statement. |
| 4468 | } else { |
| 4469 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4470 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4474 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4475 | |
| 4476 | bool needs_write_barrier = |
| 4477 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4478 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 4479 | bool object_array_set_with_read_barrier = |
| 4480 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4481 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4482 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4483 | instruction, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4484 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 4485 | LocationSummary::kCallOnSlowPath : |
| 4486 | LocationSummary::kNoCall); |
| 4487 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4488 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4489 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4490 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4491 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4492 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4493 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4494 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4495 | if (needs_write_barrier) { |
| 4496 | // Temporary registers for the write barrier. |
| 4497 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4498 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4499 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4503 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4504 | Location array_loc = locations->InAt(0); |
| 4505 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4506 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4507 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4508 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4509 | bool needs_write_barrier = |
| 4510 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4511 | |
| 4512 | switch (value_type) { |
| 4513 | case Primitive::kPrimBoolean: |
| 4514 | case Primitive::kPrimByte: { |
| 4515 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4516 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4517 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4518 | size_t offset = |
| 4519 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4520 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4521 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4522 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4523 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 4524 | } |
| 4525 | break; |
| 4526 | } |
| 4527 | |
| 4528 | case Primitive::kPrimShort: |
| 4529 | case Primitive::kPrimChar: { |
| 4530 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4531 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4532 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4533 | size_t offset = |
| 4534 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4535 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4537 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4538 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 4539 | } |
| 4540 | break; |
| 4541 | } |
| 4542 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4543 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4544 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4545 | Location value_loc = locations->InAt(2); |
| 4546 | Register value = value_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4547 | Register source = value; |
| 4548 | |
| 4549 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4550 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4551 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4552 | size_t offset = |
| 4553 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4554 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4555 | } else { |
| 4556 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4557 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4558 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4559 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4560 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4561 | DCHECK(!needs_write_barrier); |
| 4562 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4563 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4564 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4565 | |
| 4566 | DCHECK(needs_write_barrier); |
| 4567 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4568 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4569 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4570 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4571 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4572 | Label done; |
| 4573 | SlowPathCode* slow_path = nullptr; |
| 4574 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4575 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4576 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4577 | codegen_->AddSlowPath(slow_path); |
| 4578 | if (instruction->GetValueCanBeNull()) { |
| 4579 | Label non_zero; |
| 4580 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4581 | if (index.IsConstant()) { |
| 4582 | size_t offset = |
| 4583 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4584 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4585 | } else { |
| 4586 | DCHECK(index.IsRegister()) << index; |
| 4587 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4588 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4589 | } |
| 4590 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4591 | __ b(&done); |
| 4592 | __ Bind(&non_zero); |
| 4593 | } |
| 4594 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4595 | if (kEmitCompilerReadBarrier) { |
| 4596 | // When read barriers are enabled, the type checking |
| 4597 | // instrumentation requires two read barriers: |
| 4598 | // |
| 4599 | // __ Mov(temp2, temp1); |
| 4600 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4601 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4602 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4603 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4604 | // |
| 4605 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4606 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4607 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4608 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4609 | // |
| 4610 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4611 | // |
| 4612 | // However, the second read barrier may trash `temp`, as it |
| 4613 | // is a temporary register, and as such would not be saved |
| 4614 | // along with live registers before calling the runtime (nor |
| 4615 | // restored afterwards). So in this case, we bail out and |
| 4616 | // delegate the work to the array set slow path. |
| 4617 | // |
| 4618 | // TODO: Extend the register allocator to support a new |
| 4619 | // "(locally) live temp" location so as to avoid always |
| 4620 | // going into the slow path when read barriers are enabled. |
| 4621 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4622 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4623 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4624 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4625 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4626 | __ MaybeUnpoisonHeapReference(temp1); |
| 4627 | |
| 4628 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4629 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4630 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4631 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4632 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4633 | // nor `temp2`, as we are comparing two poisoned references. |
| 4634 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4635 | |
| 4636 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4637 | Label do_put; |
| 4638 | __ b(&do_put, EQ); |
| 4639 | // If heap poisoning is enabled, the `temp1` reference has |
| 4640 | // not been unpoisoned yet; unpoison it now. |
| 4641 | __ MaybeUnpoisonHeapReference(temp1); |
| 4642 | |
| 4643 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4644 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4645 | // If heap poisoning is enabled, no need to unpoison |
| 4646 | // `temp1`, as we are comparing against null below. |
| 4647 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4648 | __ Bind(&do_put); |
| 4649 | } else { |
| 4650 | __ b(slow_path->GetEntryLabel(), NE); |
| 4651 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | |
| 4655 | if (kPoisonHeapReferences) { |
| 4656 | // Note that in the case where `value` is a null reference, |
| 4657 | // we do not enter this block, as a null reference does not |
| 4658 | // need poisoning. |
| 4659 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4660 | __ Mov(temp1, value); |
| 4661 | __ PoisonHeapReference(temp1); |
| 4662 | source = temp1; |
| 4663 | } |
| 4664 | |
| 4665 | if (index.IsConstant()) { |
| 4666 | size_t offset = |
| 4667 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4668 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4669 | } else { |
| 4670 | DCHECK(index.IsRegister()) << index; |
| 4671 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4672 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4673 | } |
| 4674 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4675 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4676 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4677 | } |
| 4678 | |
| 4679 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4680 | |
| 4681 | if (done.IsLinked()) { |
| 4682 | __ Bind(&done); |
| 4683 | } |
| 4684 | |
| 4685 | if (slow_path != nullptr) { |
| 4686 | __ Bind(slow_path->GetExitLabel()); |
| 4687 | } |
| 4688 | |
| 4689 | break; |
| 4690 | } |
| 4691 | |
| 4692 | case Primitive::kPrimInt: { |
| 4693 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4694 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4695 | if (index.IsConstant()) { |
| 4696 | size_t offset = |
| 4697 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4698 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4699 | } else { |
| 4700 | DCHECK(index.IsRegister()) << index; |
| 4701 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4702 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4703 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4704 | break; |
| 4705 | } |
| 4706 | |
| 4707 | case Primitive::kPrimLong: { |
| 4708 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4709 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4710 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4711 | size_t offset = |
| 4712 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4713 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4714 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4715 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4716 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | } |
| 4718 | break; |
| 4719 | } |
| 4720 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4721 | case Primitive::kPrimFloat: { |
| 4722 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4723 | Location value = locations->InAt(2); |
| 4724 | DCHECK(value.IsFpuRegister()); |
| 4725 | if (index.IsConstant()) { |
| 4726 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4727 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4728 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4729 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4730 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4731 | } |
| 4732 | break; |
| 4733 | } |
| 4734 | |
| 4735 | case Primitive::kPrimDouble: { |
| 4736 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4737 | Location value = locations->InAt(2); |
| 4738 | DCHECK(value.IsFpuRegisterPair()); |
| 4739 | if (index.IsConstant()) { |
| 4740 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4741 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4742 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4743 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4744 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4745 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4746 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4747 | break; |
| 4748 | } |
| 4749 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4750 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4751 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4752 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4754 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 4755 | // Objects are handled in the switch. |
| 4756 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4757 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4758 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4762 | LocationSummary* locations = |
| 4763 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4764 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4765 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4769 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4770 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4771 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4772 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4773 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4774 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4778 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4779 | ? LocationSummary::kCallOnSlowPath |
| 4780 | : LocationSummary::kNoCall; |
| 4781 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4782 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4783 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4784 | if (instruction->HasUses()) { |
| 4785 | locations->SetOut(Location::SameAsFirstInput()); |
| 4786 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4790 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4791 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4792 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4793 | codegen_->AddSlowPath(slow_path); |
| 4794 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4795 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4796 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4797 | |
| 4798 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4799 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4800 | } |
| 4801 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4802 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4803 | Register card, |
| 4804 | Register object, |
| 4805 | Register value, |
| 4806 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4807 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4808 | if (can_be_null) { |
| 4809 | __ CompareAndBranchIfZero(value, &is_null); |
| 4810 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4811 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4812 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4813 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4814 | if (can_be_null) { |
| 4815 | __ Bind(&is_null); |
| 4816 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4817 | } |
| 4818 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4819 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4820 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4824 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4825 | } |
| 4826 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4827 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4828 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4829 | } |
| 4830 | |
| 4831 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4832 | HBasicBlock* block = instruction->GetBlock(); |
| 4833 | if (block->GetLoopInformation() != nullptr) { |
| 4834 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4835 | // The back edge will generate the suspend check. |
| 4836 | return; |
| 4837 | } |
| 4838 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4839 | // The goto will generate the suspend check. |
| 4840 | return; |
| 4841 | } |
| 4842 | GenerateSuspendCheck(instruction, nullptr); |
| 4843 | } |
| 4844 | |
| 4845 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4846 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4847 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4848 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4849 | if (slow_path == nullptr) { |
| 4850 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4851 | instruction->SetSlowPath(slow_path); |
| 4852 | codegen_->AddSlowPath(slow_path); |
| 4853 | if (successor != nullptr) { |
| 4854 | DCHECK(successor->IsLoopHeader()); |
| 4855 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4856 | } |
| 4857 | } else { |
| 4858 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4859 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4860 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4861 | __ LoadFromOffset( |
| 4862 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4863 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4864 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4865 | __ Bind(slow_path->GetReturnLabel()); |
| 4866 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4867 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4868 | __ b(slow_path->GetEntryLabel()); |
| 4869 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4872 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4873 | return codegen_->GetAssembler(); |
| 4874 | } |
| 4875 | |
| 4876 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4877 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4878 | Location source = move->GetSource(); |
| 4879 | Location destination = move->GetDestination(); |
| 4880 | |
| 4881 | if (source.IsRegister()) { |
| 4882 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4883 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4884 | } else if (destination.IsFpuRegister()) { |
| 4885 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4886 | } else { |
| 4887 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4888 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4889 | SP, destination.GetStackIndex()); |
| 4890 | } |
| 4891 | } else if (source.IsStackSlot()) { |
| 4892 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4893 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4894 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4895 | } else if (destination.IsFpuRegister()) { |
| 4896 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4897 | } else { |
| 4898 | DCHECK(destination.IsStackSlot()); |
| 4899 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4900 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4901 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4902 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4903 | if (destination.IsRegister()) { |
| 4904 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 4905 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4906 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4907 | } else { |
| 4908 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4909 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4910 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4911 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4912 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4913 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4914 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4915 | } else if (destination.IsRegisterPair()) { |
| 4916 | DCHECK(ExpectedPairLayout(destination)); |
| 4917 | __ LoadFromOffset( |
| 4918 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4919 | } else { |
| 4920 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4921 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4922 | SP, |
| 4923 | source.GetStackIndex()); |
| 4924 | } |
| 4925 | } else if (source.IsRegisterPair()) { |
| 4926 | if (destination.IsRegisterPair()) { |
| 4927 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 4928 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4929 | } else if (destination.IsFpuRegisterPair()) { |
| 4930 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4931 | source.AsRegisterPairLow<Register>(), |
| 4932 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4933 | } else { |
| 4934 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4935 | DCHECK(ExpectedPairLayout(source)); |
| 4936 | __ StoreToOffset( |
| 4937 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 4938 | } |
| 4939 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4940 | if (destination.IsRegisterPair()) { |
| 4941 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 4942 | destination.AsRegisterPairHigh<Register>(), |
| 4943 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4944 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4945 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4946 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4947 | } else { |
| 4948 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4949 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 4950 | SP, |
| 4951 | destination.GetStackIndex()); |
| 4952 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4953 | } else { |
| 4954 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4955 | HConstant* constant = source.GetConstant(); |
| 4956 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4957 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4958 | if (destination.IsRegister()) { |
| 4959 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 4960 | } else { |
| 4961 | DCHECK(destination.IsStackSlot()); |
| 4962 | __ LoadImmediate(IP, value); |
| 4963 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4964 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4965 | } else if (constant->IsLongConstant()) { |
| 4966 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4967 | if (destination.IsRegisterPair()) { |
| 4968 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 4969 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4970 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4971 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4972 | __ LoadImmediate(IP, Low32Bits(value)); |
| 4973 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4974 | __ LoadImmediate(IP, High32Bits(value)); |
| 4975 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4976 | } |
| 4977 | } else if (constant->IsDoubleConstant()) { |
| 4978 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4979 | if (destination.IsFpuRegisterPair()) { |
| 4980 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4981 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4982 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4983 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4984 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 4985 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4986 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 4987 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4988 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4989 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4990 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4991 | float value = constant->AsFloatConstant()->GetValue(); |
| 4992 | if (destination.IsFpuRegister()) { |
| 4993 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 4994 | } else { |
| 4995 | DCHECK(destination.IsStackSlot()); |
| 4996 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 4997 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4998 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4999 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5004 | __ Mov(IP, reg); |
| 5005 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5006 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5007 | } |
| 5008 | |
| 5009 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5010 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5011 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5012 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5013 | SP, mem1 + stack_offset); |
| 5014 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5015 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5016 | SP, mem2 + stack_offset); |
| 5017 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5018 | } |
| 5019 | |
| 5020 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5021 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5022 | Location source = move->GetSource(); |
| 5023 | Location destination = move->GetDestination(); |
| 5024 | |
| 5025 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5026 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5027 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5028 | __ Mov(IP, source.AsRegister<Register>()); |
| 5029 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5030 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5031 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5032 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5033 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5034 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5035 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5036 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5037 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5038 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5039 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5040 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5041 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5042 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5043 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5044 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5045 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5046 | destination.AsRegisterPairHigh<Register>(), |
| 5047 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5048 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5049 | Register low_reg = source.IsRegisterPair() |
| 5050 | ? source.AsRegisterPairLow<Register>() |
| 5051 | : destination.AsRegisterPairLow<Register>(); |
| 5052 | int mem = source.IsRegisterPair() |
| 5053 | ? destination.GetStackIndex() |
| 5054 | : source.GetStackIndex(); |
| 5055 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5056 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5057 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5058 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5059 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5060 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5061 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5062 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5063 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5064 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5065 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5066 | DRegister reg = source.IsFpuRegisterPair() |
| 5067 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5068 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5069 | int mem = source.IsFpuRegisterPair() |
| 5070 | ? destination.GetStackIndex() |
| 5071 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5072 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5073 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5074 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5075 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5076 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5077 | : destination.AsFpuRegister<SRegister>(); |
| 5078 | int mem = source.IsFpuRegister() |
| 5079 | ? destination.GetStackIndex() |
| 5080 | : source.GetStackIndex(); |
| 5081 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5082 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5083 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5084 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5085 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5086 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5087 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5088 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5089 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5094 | __ Push(static_cast<Register>(reg)); |
| 5095 | } |
| 5096 | |
| 5097 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5098 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5099 | } |
| 5100 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5101 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5102 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5103 | if (kEmitCompilerReadBarrier) { |
| 5104 | switch (desired_class_load_kind) { |
| 5105 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5106 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5107 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5108 | // TODO: Implement for read barrier. |
| 5109 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5110 | default: |
| 5111 | break; |
| 5112 | } |
| 5113 | } |
| 5114 | switch (desired_class_load_kind) { |
| 5115 | case HLoadClass::LoadKind::kReferrersClass: |
| 5116 | break; |
| 5117 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5118 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5119 | break; |
| 5120 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5121 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5122 | break; |
| 5123 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5124 | break; |
| 5125 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5126 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5127 | break; |
| 5128 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5129 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5130 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5131 | // is incompatible with it. |
| 5132 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5133 | // with irreducible loops. |
| 5134 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5135 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5136 | } |
| 5137 | break; |
| 5138 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5139 | break; |
| 5140 | } |
| 5141 | return desired_class_load_kind; |
| 5142 | } |
| 5143 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5144 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5145 | if (cls->NeedsAccessCheck()) { |
| 5146 | InvokeRuntimeCallingConvention calling_convention; |
| 5147 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5148 | cls, |
| 5149 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5150 | Location::RegisterLocation(R0), |
| 5151 | /* code_generator_supports_read_barrier */ true); |
| 5152 | return; |
| 5153 | } |
| 5154 | |
| 5155 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5156 | ? LocationSummary::kCallOnSlowPath |
| 5157 | : LocationSummary::kNoCall; |
| 5158 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5159 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5160 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5161 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5162 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5164 | } |
| 5165 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5169 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5170 | if (cls->NeedsAccessCheck()) { |
| 5171 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5172 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5173 | cls, |
| 5174 | cls->GetDexPc(), |
| 5175 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5176 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5177 | return; |
| 5178 | } |
| 5179 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5180 | Location out_loc = locations->Out(); |
| 5181 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5182 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5183 | bool generate_null_check = false; |
| 5184 | switch (cls->GetLoadKind()) { |
| 5185 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5186 | DCHECK(!cls->CanCallRuntime()); |
| 5187 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5188 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5189 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5190 | GenerateGcRootFieldLoad( |
| 5191 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5192 | break; |
| 5193 | } |
| 5194 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 5195 | DCHECK(!kEmitCompilerReadBarrier); |
| 5196 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5197 | cls->GetTypeIndex())); |
| 5198 | break; |
| 5199 | } |
| 5200 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 5201 | DCHECK(!kEmitCompilerReadBarrier); |
| 5202 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5203 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5204 | __ BindTrackedLabel(&labels->movw_label); |
| 5205 | __ movw(out, /* placeholder */ 0u); |
| 5206 | __ BindTrackedLabel(&labels->movt_label); |
| 5207 | __ movt(out, /* placeholder */ 0u); |
| 5208 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5209 | __ add(out, out, ShifterOperand(PC)); |
| 5210 | break; |
| 5211 | } |
| 5212 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5213 | DCHECK(!kEmitCompilerReadBarrier); |
| 5214 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5215 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5216 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5217 | break; |
| 5218 | } |
| 5219 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5220 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5221 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5222 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5223 | // a 128B range. To try and reduce the number of literals if we load multiple types, |
| 5224 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5225 | // and the remaining offset embedded in the load. |
| 5226 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 5227 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 5228 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5229 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5230 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5231 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5232 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 5233 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5234 | generate_null_check = !cls->IsInDexCache(); |
| 5235 | break; |
| 5236 | } |
| 5237 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5238 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5239 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5240 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5241 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
| 5242 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset); |
| 5243 | generate_null_check = !cls->IsInDexCache(); |
| 5244 | break; |
| 5245 | } |
| 5246 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5247 | // /* GcRoot<mirror::Class>[] */ out = |
| 5248 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5249 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5250 | __ LoadFromOffset(kLoadWord, |
| 5251 | out, |
| 5252 | current_method, |
| 5253 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
| 5254 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5255 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5256 | GenerateGcRootFieldLoad(cls, out_loc, out, offset); |
| 5257 | generate_null_check = !cls->IsInDexCache(); |
| 5258 | } |
| 5259 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5260 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5261 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5262 | DCHECK(cls->CanCallRuntime()); |
| 5263 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 5264 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5265 | codegen_->AddSlowPath(slow_path); |
| 5266 | if (generate_null_check) { |
| 5267 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5268 | } |
| 5269 | if (cls->MustGenerateClinitCheck()) { |
| 5270 | GenerateClassInitializationCheck(slow_path, out); |
| 5271 | } else { |
| 5272 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5273 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5278 | LocationSummary* locations = |
| 5279 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5280 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5281 | if (check->HasUses()) { |
| 5282 | locations->SetOut(Location::SameAsFirstInput()); |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5287 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5288 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5289 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5290 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5291 | GenerateClassInitializationCheck(slow_path, |
| 5292 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5293 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5294 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5295 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5296 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5297 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5298 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5299 | __ b(slow_path->GetEntryLabel(), LT); |
| 5300 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5301 | // properly. Therefore, we do a memory fence. |
| 5302 | __ dmb(ISH); |
| 5303 | __ Bind(slow_path->GetExitLabel()); |
| 5304 | } |
| 5305 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5306 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5307 | HLoadString::LoadKind desired_string_load_kind) { |
| 5308 | if (kEmitCompilerReadBarrier) { |
| 5309 | switch (desired_string_load_kind) { |
| 5310 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5311 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5312 | case HLoadString::LoadKind::kBootImageAddress: |
| 5313 | // TODO: Implement for read barrier. |
| 5314 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5315 | default: |
| 5316 | break; |
| 5317 | } |
| 5318 | } |
| 5319 | switch (desired_string_load_kind) { |
| 5320 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5321 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5322 | break; |
| 5323 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5324 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5325 | break; |
| 5326 | case HLoadString::LoadKind::kBootImageAddress: |
| 5327 | break; |
| 5328 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5329 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5330 | break; |
| 5331 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5332 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5333 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5334 | // is incompatible with it. |
| 5335 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5336 | // with irreducible loops. |
| 5337 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5338 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5339 | } |
| 5340 | break; |
| 5341 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5342 | break; |
| 5343 | } |
| 5344 | return desired_string_load_kind; |
| 5345 | } |
| 5346 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5347 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5348 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5349 | ? LocationSummary::kCallOnSlowPath |
| 5350 | : LocationSummary::kNoCall; |
| 5351 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5352 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5353 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 5354 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 5355 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5356 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5357 | locations->SetOut(Location::RequiresRegister()); |
| 5358 | } |
| 5359 | |
| 5360 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5361 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5362 | Location out_loc = locations->Out(); |
| 5363 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5364 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5365 | switch (load->GetLoadKind()) { |
| 5366 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 5367 | DCHECK(!kEmitCompilerReadBarrier); |
| 5368 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5369 | load->GetStringIndex())); |
| 5370 | return; // No dex cache slow path. |
| 5371 | } |
| 5372 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5373 | DCHECK(!kEmitCompilerReadBarrier); |
| 5374 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5375 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5376 | __ BindTrackedLabel(&labels->movw_label); |
| 5377 | __ movw(out, /* placeholder */ 0u); |
| 5378 | __ BindTrackedLabel(&labels->movt_label); |
| 5379 | __ movt(out, /* placeholder */ 0u); |
| 5380 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5381 | __ add(out, out, ShifterOperand(PC)); |
| 5382 | return; // No dex cache slow path. |
| 5383 | } |
| 5384 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5385 | DCHECK(!kEmitCompilerReadBarrier); |
| 5386 | DCHECK_NE(load->GetAddress(), 0u); |
| 5387 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5388 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5389 | return; // No dex cache slow path. |
| 5390 | } |
| 5391 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 5392 | DCHECK_NE(load->GetAddress(), 0u); |
| 5393 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5394 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5395 | // a 128B range. To try and reduce the number of literals if we load multiple strings, |
| 5396 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5397 | // and the remaining offset embedded in the load. |
| 5398 | static_assert(sizeof(GcRoot<mirror::String>) == 4u, "Expected GC root to be 4 bytes."); |
| 5399 | DCHECK_ALIGNED(load->GetAddress(), 4u); |
| 5400 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5401 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5402 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5403 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5404 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5405 | GenerateGcRootFieldLoad(load, out_loc, out, offset); |
| 5406 | break; |
| 5407 | } |
| 5408 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 5409 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5410 | HArmDexCacheArraysBase* base = load->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5411 | int32_t offset = load->GetDexCacheElementOffset() - base->GetElementOffset(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5412 | // /* GcRoot<mirror::String> */ out = *(dex_cache_arrays_base + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5413 | GenerateGcRootFieldLoad(load, out_loc, base_reg, offset); |
| 5414 | break; |
| 5415 | } |
| 5416 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 5417 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5418 | |
| 5419 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5420 | GenerateGcRootFieldLoad( |
| 5421 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5422 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5423 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
| 5424 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5425 | GenerateGcRootFieldLoad( |
| 5426 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 5427 | break; |
| 5428 | } |
| 5429 | default: |
| 5430 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 5431 | UNREACHABLE(); |
| 5432 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5433 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5434 | if (!load->IsInDexCache()) { |
| 5435 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5436 | codegen_->AddSlowPath(slow_path); |
| 5437 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5438 | __ Bind(slow_path->GetExitLabel()); |
| 5439 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5442 | static int32_t GetExceptionTlsOffset() { |
| 5443 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 5444 | } |
| 5445 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5446 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5447 | LocationSummary* locations = |
| 5448 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5449 | locations->SetOut(Location::RequiresRegister()); |
| 5450 | } |
| 5451 | |
| 5452 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5453 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5454 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5455 | } |
| 5456 | |
| 5457 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5458 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5459 | } |
| 5460 | |
| 5461 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5462 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5463 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5467 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5468 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5469 | InvokeRuntimeCallingConvention calling_convention; |
| 5470 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5471 | } |
| 5472 | |
| 5473 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 5474 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5475 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5476 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5477 | } |
| 5478 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5479 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5480 | return kEmitCompilerReadBarrier && |
| 5481 | (kUseBakerReadBarrier || |
| 5482 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5483 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5484 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5485 | } |
| 5486 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5487 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5488 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5489 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5490 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5491 | case TypeCheckKind::kExactCheck: |
| 5492 | case TypeCheckKind::kAbstractClassCheck: |
| 5493 | case TypeCheckKind::kClassHierarchyCheck: |
| 5494 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5495 | call_kind = |
| 5496 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5497 | break; |
| 5498 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5499 | case TypeCheckKind::kUnresolvedCheck: |
| 5500 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5501 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5502 | break; |
| 5503 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5504 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5505 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5507 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5508 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5509 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5510 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5511 | // When read barriers are enabled, we need a temporary register for |
| 5512 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5513 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5514 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5515 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5518 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5519 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5520 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5521 | Location obj_loc = locations->InAt(0); |
| 5522 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5523 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5524 | Location out_loc = locations->Out(); |
| 5525 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5526 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5527 | locations->GetTemp(0) : |
| 5528 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5529 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5530 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5531 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5532 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5533 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5534 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5535 | |
| 5536 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5537 | // avoid null check if we know obj is not null. |
| 5538 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5539 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5540 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5541 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5542 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5543 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5544 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5545 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5546 | case TypeCheckKind::kExactCheck: { |
| 5547 | __ cmp(out, ShifterOperand(cls)); |
| 5548 | // Classes must be equal for the instanceof to succeed. |
| 5549 | __ b(&zero, NE); |
| 5550 | __ LoadImmediate(out, 1); |
| 5551 | __ b(&done); |
| 5552 | break; |
| 5553 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5554 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5555 | case TypeCheckKind::kAbstractClassCheck: { |
| 5556 | // If the class is abstract, we eagerly fetch the super class of the |
| 5557 | // object to avoid doing a comparison we know will fail. |
| 5558 | Label loop; |
| 5559 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5560 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5561 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5562 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5563 | __ CompareAndBranchIfZero(out, &done); |
| 5564 | __ cmp(out, ShifterOperand(cls)); |
| 5565 | __ b(&loop, NE); |
| 5566 | __ LoadImmediate(out, 1); |
| 5567 | if (zero.IsLinked()) { |
| 5568 | __ b(&done); |
| 5569 | } |
| 5570 | break; |
| 5571 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5572 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5573 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5574 | // Walk over the class hierarchy to find a match. |
| 5575 | Label loop, success; |
| 5576 | __ Bind(&loop); |
| 5577 | __ cmp(out, ShifterOperand(cls)); |
| 5578 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5579 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5580 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5581 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5582 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5583 | __ b(&done); |
| 5584 | __ Bind(&success); |
| 5585 | __ LoadImmediate(out, 1); |
| 5586 | if (zero.IsLinked()) { |
| 5587 | __ b(&done); |
| 5588 | } |
| 5589 | break; |
| 5590 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5591 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5592 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5593 | // Do an exact check. |
| 5594 | Label exact_check; |
| 5595 | __ cmp(out, ShifterOperand(cls)); |
| 5596 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5597 | // 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] | 5598 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5599 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5600 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5601 | __ CompareAndBranchIfZero(out, &done); |
| 5602 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5603 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5604 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5605 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5606 | __ LoadImmediate(out, 1); |
| 5607 | __ b(&done); |
| 5608 | break; |
| 5609 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5610 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5611 | case TypeCheckKind::kArrayCheck: { |
| 5612 | __ cmp(out, ShifterOperand(cls)); |
| 5613 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5614 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5615 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5616 | codegen_->AddSlowPath(slow_path); |
| 5617 | __ b(slow_path->GetEntryLabel(), NE); |
| 5618 | __ LoadImmediate(out, 1); |
| 5619 | if (zero.IsLinked()) { |
| 5620 | __ b(&done); |
| 5621 | } |
| 5622 | break; |
| 5623 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5624 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5625 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5626 | case TypeCheckKind::kInterfaceCheck: { |
| 5627 | // 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] | 5628 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5629 | // cases. |
| 5630 | // |
| 5631 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5632 | // entry point without resorting to a type checking slow path |
| 5633 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5634 | // require to assign fixed registers for the inputs of this |
| 5635 | // HInstanceOf instruction (following the runtime calling |
| 5636 | // convention), which might be cluttered by the potential first |
| 5637 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5638 | // |
| 5639 | // TODO: Introduce a new runtime entry point taking the object |
| 5640 | // to test (instead of its class) as argument, and let it deal |
| 5641 | // with the read barrier issues. This will let us refactor this |
| 5642 | // case of the `switch` code as it was previously (with a direct |
| 5643 | // call to the runtime not using a type checking slow path). |
| 5644 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5645 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5646 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5647 | /* is_fatal */ false); |
| 5648 | codegen_->AddSlowPath(slow_path); |
| 5649 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5650 | if (zero.IsLinked()) { |
| 5651 | __ b(&done); |
| 5652 | } |
| 5653 | break; |
| 5654 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5655 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5656 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5657 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5658 | __ Bind(&zero); |
| 5659 | __ LoadImmediate(out, 0); |
| 5660 | } |
| 5661 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5662 | if (done.IsLinked()) { |
| 5663 | __ Bind(&done); |
| 5664 | } |
| 5665 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5666 | if (slow_path != nullptr) { |
| 5667 | __ Bind(slow_path->GetExitLabel()); |
| 5668 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5671 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5672 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5673 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5674 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5675 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5676 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5677 | case TypeCheckKind::kExactCheck: |
| 5678 | case TypeCheckKind::kAbstractClassCheck: |
| 5679 | case TypeCheckKind::kClassHierarchyCheck: |
| 5680 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5681 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5682 | LocationSummary::kCallOnSlowPath : |
| 5683 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5684 | break; |
| 5685 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5686 | case TypeCheckKind::kUnresolvedCheck: |
| 5687 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5688 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5689 | break; |
| 5690 | } |
| 5691 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5692 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5694 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5695 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5696 | locations->AddTemp(Location::RequiresRegister()); |
| 5697 | // When read barriers are enabled, we need an additional temporary |
| 5698 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5699 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5700 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5701 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5705 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5706 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5707 | Location obj_loc = locations->InAt(0); |
| 5708 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5709 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5710 | Location temp_loc = locations->GetTemp(0); |
| 5711 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5712 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5713 | locations->GetTemp(1) : |
| 5714 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5715 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5716 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5717 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5718 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5719 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5720 | bool is_type_check_slow_path_fatal = |
| 5721 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5722 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5723 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5724 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5725 | !instruction->CanThrowIntoCatchBlock(); |
| 5726 | SlowPathCode* type_check_slow_path = |
| 5727 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5728 | is_type_check_slow_path_fatal); |
| 5729 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5730 | |
| 5731 | Label done; |
| 5732 | // Avoid null check if we know obj is not null. |
| 5733 | if (instruction->MustDoNullCheck()) { |
| 5734 | __ CompareAndBranchIfZero(obj, &done); |
| 5735 | } |
| 5736 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5737 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5738 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5739 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5740 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5741 | case TypeCheckKind::kExactCheck: |
| 5742 | case TypeCheckKind::kArrayCheck: { |
| 5743 | __ cmp(temp, ShifterOperand(cls)); |
| 5744 | // Jump to slow path for throwing the exception or doing a |
| 5745 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5746 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5747 | break; |
| 5748 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5749 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5750 | case TypeCheckKind::kAbstractClassCheck: { |
| 5751 | // If the class is abstract, we eagerly fetch the super class of the |
| 5752 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5753 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5754 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5755 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5756 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5757 | |
| 5758 | // If the class reference currently in `temp` is not null, jump |
| 5759 | // to the `compare_classes` label to compare it with the checked |
| 5760 | // class. |
| 5761 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5762 | // Otherwise, jump to the slow path to throw the exception. |
| 5763 | // |
| 5764 | // But before, move back the object's class into `temp` before |
| 5765 | // going into the slow path, as it has been overwritten in the |
| 5766 | // meantime. |
| 5767 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5768 | GenerateReferenceLoadTwoRegisters( |
| 5769 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5770 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5771 | |
| 5772 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5773 | __ cmp(temp, ShifterOperand(cls)); |
| 5774 | __ b(&loop, NE); |
| 5775 | break; |
| 5776 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5777 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5778 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5779 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5780 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5781 | __ Bind(&loop); |
| 5782 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5783 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5784 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5785 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5786 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5787 | |
| 5788 | // If the class reference currently in `temp` is not null, jump |
| 5789 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5790 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5791 | // Otherwise, jump to the slow path to throw the exception. |
| 5792 | // |
| 5793 | // But before, move back the object's class into `temp` before |
| 5794 | // going into the slow path, as it has been overwritten in the |
| 5795 | // meantime. |
| 5796 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5797 | GenerateReferenceLoadTwoRegisters( |
| 5798 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5799 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5800 | break; |
| 5801 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5802 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5803 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5804 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5805 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5806 | __ cmp(temp, ShifterOperand(cls)); |
| 5807 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5808 | |
| 5809 | // 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] | 5810 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5811 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5812 | |
| 5813 | // If the component type is not null (i.e. the object is indeed |
| 5814 | // an array), jump to label `check_non_primitive_component_type` |
| 5815 | // to further check that this component type is not a primitive |
| 5816 | // type. |
| 5817 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 5818 | // Otherwise, jump to the slow path to throw the exception. |
| 5819 | // |
| 5820 | // But before, move back the object's class into `temp` before |
| 5821 | // going into the slow path, as it has been overwritten in the |
| 5822 | // meantime. |
| 5823 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5824 | GenerateReferenceLoadTwoRegisters( |
| 5825 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5826 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5827 | |
| 5828 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5829 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5830 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 5831 | __ CompareAndBranchIfZero(temp, &done); |
| 5832 | // Same comment as above regarding `temp` and the slow path. |
| 5833 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5834 | GenerateReferenceLoadTwoRegisters( |
| 5835 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5836 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | break; |
| 5838 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5839 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5840 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5841 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5842 | // We always go into the type check slow path for the unresolved |
| 5843 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5844 | // |
| 5845 | // We cannot directly call the CheckCast runtime entry point |
| 5846 | // without resorting to a type checking slow path here (i.e. by |
| 5847 | // calling InvokeRuntime directly), as it would require to |
| 5848 | // assign fixed registers for the inputs of this HInstanceOf |
| 5849 | // instruction (following the runtime calling convention), which |
| 5850 | // might be cluttered by the potential first read barrier |
| 5851 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5852 | // |
| 5853 | // TODO: Introduce a new runtime entry point taking the object |
| 5854 | // to test (instead of its class) as argument, and let it deal |
| 5855 | // with the read barrier issues. This will let us refactor this |
| 5856 | // case of the `switch` code as it was previously (with a direct |
| 5857 | // call to the runtime not using a type checking slow path). |
| 5858 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5859 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5860 | break; |
| 5861 | } |
| 5862 | __ Bind(&done); |
| 5863 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5864 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5865 | } |
| 5866 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5867 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5868 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5869 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5870 | InvokeRuntimeCallingConvention calling_convention; |
| 5871 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5872 | } |
| 5873 | |
| 5874 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5875 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 5876 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 5877 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5878 | instruction->GetDexPc(), |
| 5879 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5880 | if (instruction->IsEnter()) { |
| 5881 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5882 | } else { |
| 5883 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5884 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5887 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 5888 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 5889 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5890 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5891 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5892 | LocationSummary* locations = |
| 5893 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5894 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5895 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5896 | // 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] | 5897 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5898 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5899 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 5903 | HandleBitwiseOperation(instruction); |
| 5904 | } |
| 5905 | |
| 5906 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 5907 | HandleBitwiseOperation(instruction); |
| 5908 | } |
| 5909 | |
| 5910 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 5911 | HandleBitwiseOperation(instruction); |
| 5912 | } |
| 5913 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 5914 | |
| 5915 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 5916 | LocationSummary* locations = |
| 5917 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5918 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5919 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5920 | |
| 5921 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5922 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5923 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5924 | } |
| 5925 | |
| 5926 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 5927 | LocationSummary* locations = instruction->GetLocations(); |
| 5928 | Location first = locations->InAt(0); |
| 5929 | Location second = locations->InAt(1); |
| 5930 | Location out = locations->Out(); |
| 5931 | |
| 5932 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5933 | Register first_reg = first.AsRegister<Register>(); |
| 5934 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 5935 | Register out_reg = out.AsRegister<Register>(); |
| 5936 | |
| 5937 | switch (instruction->GetOpKind()) { |
| 5938 | case HInstruction::kAnd: |
| 5939 | __ bic(out_reg, first_reg, second_reg); |
| 5940 | break; |
| 5941 | case HInstruction::kOr: |
| 5942 | __ orn(out_reg, first_reg, second_reg); |
| 5943 | break; |
| 5944 | // There is no EON on arm. |
| 5945 | case HInstruction::kXor: |
| 5946 | default: |
| 5947 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 5948 | UNREACHABLE(); |
| 5949 | } |
| 5950 | return; |
| 5951 | |
| 5952 | } else { |
| 5953 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5954 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5955 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5956 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 5957 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 5958 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5959 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5960 | |
| 5961 | switch (instruction->GetOpKind()) { |
| 5962 | case HInstruction::kAnd: |
| 5963 | __ bic(out_low, first_low, second_low); |
| 5964 | __ bic(out_high, first_high, second_high); |
| 5965 | break; |
| 5966 | case HInstruction::kOr: |
| 5967 | __ orn(out_low, first_low, second_low); |
| 5968 | __ orn(out_high, first_high, second_high); |
| 5969 | break; |
| 5970 | // There is no EON on arm. |
| 5971 | case HInstruction::kXor: |
| 5972 | default: |
| 5973 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 5974 | UNREACHABLE(); |
| 5975 | } |
| 5976 | } |
| 5977 | } |
| 5978 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5979 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 5980 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 5981 | if (value == 0xffffffffu) { |
| 5982 | if (out != first) { |
| 5983 | __ mov(out, ShifterOperand(first)); |
| 5984 | } |
| 5985 | return; |
| 5986 | } |
| 5987 | if (value == 0u) { |
| 5988 | __ mov(out, ShifterOperand(0)); |
| 5989 | return; |
| 5990 | } |
| 5991 | ShifterOperand so; |
| 5992 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 5993 | __ and_(out, first, so); |
| 5994 | } else { |
| 5995 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 5996 | __ bic(out, first, ShifterOperand(~value)); |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6001 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6002 | if (value == 0u) { |
| 6003 | if (out != first) { |
| 6004 | __ mov(out, ShifterOperand(first)); |
| 6005 | } |
| 6006 | return; |
| 6007 | } |
| 6008 | if (value == 0xffffffffu) { |
| 6009 | __ mvn(out, ShifterOperand(0)); |
| 6010 | return; |
| 6011 | } |
| 6012 | ShifterOperand so; |
| 6013 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6014 | __ orr(out, first, so); |
| 6015 | } else { |
| 6016 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6017 | __ orn(out, first, ShifterOperand(~value)); |
| 6018 | } |
| 6019 | } |
| 6020 | |
| 6021 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6022 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6023 | if (value == 0u) { |
| 6024 | if (out != first) { |
| 6025 | __ mov(out, ShifterOperand(first)); |
| 6026 | } |
| 6027 | return; |
| 6028 | } |
| 6029 | __ eor(out, first, ShifterOperand(value)); |
| 6030 | } |
| 6031 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6032 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6033 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6034 | Location first = locations->InAt(0); |
| 6035 | Location second = locations->InAt(1); |
| 6036 | Location out = locations->Out(); |
| 6037 | |
| 6038 | if (second.IsConstant()) { |
| 6039 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6040 | uint32_t value_low = Low32Bits(value); |
| 6041 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6042 | Register first_reg = first.AsRegister<Register>(); |
| 6043 | Register out_reg = out.AsRegister<Register>(); |
| 6044 | if (instruction->IsAnd()) { |
| 6045 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6046 | } else if (instruction->IsOr()) { |
| 6047 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6048 | } else { |
| 6049 | DCHECK(instruction->IsXor()); |
| 6050 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6051 | } |
| 6052 | } else { |
| 6053 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6054 | uint32_t value_high = High32Bits(value); |
| 6055 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6056 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6057 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6058 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6059 | if (instruction->IsAnd()) { |
| 6060 | GenerateAndConst(out_low, first_low, value_low); |
| 6061 | GenerateAndConst(out_high, first_high, value_high); |
| 6062 | } else if (instruction->IsOr()) { |
| 6063 | GenerateOrrConst(out_low, first_low, value_low); |
| 6064 | GenerateOrrConst(out_high, first_high, value_high); |
| 6065 | } else { |
| 6066 | DCHECK(instruction->IsXor()); |
| 6067 | GenerateEorConst(out_low, first_low, value_low); |
| 6068 | GenerateEorConst(out_high, first_high, value_high); |
| 6069 | } |
| 6070 | } |
| 6071 | return; |
| 6072 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6073 | |
| 6074 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6075 | Register first_reg = first.AsRegister<Register>(); |
| 6076 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6077 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6078 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6079 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6080 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6081 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6082 | } else { |
| 6083 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6084 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6085 | } |
| 6086 | } else { |
| 6087 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6088 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6089 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6090 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6091 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6092 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6093 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6094 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6095 | __ and_(out_low, first_low, second_low); |
| 6096 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6097 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6098 | __ orr(out_low, first_low, second_low); |
| 6099 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6100 | } else { |
| 6101 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6102 | __ eor(out_low, first_low, second_low); |
| 6103 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6104 | } |
| 6105 | } |
| 6106 | } |
| 6107 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6108 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6109 | Location out, |
| 6110 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6111 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6112 | Register out_reg = out.AsRegister<Register>(); |
| 6113 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6114 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6115 | if (kUseBakerReadBarrier) { |
| 6116 | // Load with fast path based Baker's read barrier. |
| 6117 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6118 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6119 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6120 | } else { |
| 6121 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6122 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6123 | // in the following move operation, as we will need it for the |
| 6124 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6125 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6126 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6127 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6128 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6129 | } |
| 6130 | } else { |
| 6131 | // Plain load with no read barrier. |
| 6132 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6133 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6134 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6139 | Location out, |
| 6140 | Location obj, |
| 6141 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6142 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6143 | Register out_reg = out.AsRegister<Register>(); |
| 6144 | Register obj_reg = obj.AsRegister<Register>(); |
| 6145 | if (kEmitCompilerReadBarrier) { |
| 6146 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6147 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6148 | // Load with fast path based Baker's read barrier. |
| 6149 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6150 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6151 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6152 | } else { |
| 6153 | // Load with slow path based read barrier. |
| 6154 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6155 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6156 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6157 | } |
| 6158 | } else { |
| 6159 | // Plain load with no read barrier. |
| 6160 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6161 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6162 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6167 | Location root, |
| 6168 | Register obj, |
| 6169 | uint32_t offset) { |
| 6170 | Register root_reg = root.AsRegister<Register>(); |
| 6171 | if (kEmitCompilerReadBarrier) { |
| 6172 | if (kUseBakerReadBarrier) { |
| 6173 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6174 | // Baker's read barrier are used: |
| 6175 | // |
| 6176 | // root = obj.field; |
| 6177 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6178 | // root = ReadBarrier::Mark(root) |
| 6179 | // } |
| 6180 | |
| 6181 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6182 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6183 | static_assert( |
| 6184 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6185 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6186 | "have different sizes."); |
| 6187 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6188 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6189 | "have different sizes."); |
| 6190 | |
| 6191 | // Slow path used to mark the GC root `root`. |
| 6192 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6193 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6194 | codegen_->AddSlowPath(slow_path); |
| 6195 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6196 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6197 | __ LoadFromOffset( |
| 6198 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmWordSize>().Int32Value()); |
| 6199 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6200 | __ Bind(slow_path->GetExitLabel()); |
| 6201 | } else { |
| 6202 | // GC root loaded through a slow path for read barriers other |
| 6203 | // than Baker's. |
| 6204 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6205 | __ AddConstant(root_reg, obj, offset); |
| 6206 | // /* mirror::Object* */ root = root->Read() |
| 6207 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6208 | } |
| 6209 | } else { |
| 6210 | // Plain GC root load with no read barrier. |
| 6211 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6212 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6213 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6214 | // do not have to unpoison `root_reg` here. |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6219 | Location ref, |
| 6220 | Register obj, |
| 6221 | uint32_t offset, |
| 6222 | Location temp, |
| 6223 | bool needs_null_check) { |
| 6224 | DCHECK(kEmitCompilerReadBarrier); |
| 6225 | DCHECK(kUseBakerReadBarrier); |
| 6226 | |
| 6227 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6228 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6229 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6230 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6231 | 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] | 6232 | } |
| 6233 | |
| 6234 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6235 | Location ref, |
| 6236 | Register obj, |
| 6237 | uint32_t data_offset, |
| 6238 | Location index, |
| 6239 | Location temp, |
| 6240 | bool needs_null_check) { |
| 6241 | DCHECK(kEmitCompilerReadBarrier); |
| 6242 | DCHECK(kUseBakerReadBarrier); |
| 6243 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6244 | static_assert( |
| 6245 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6246 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6247 | // /* HeapReference<Object> */ ref = |
| 6248 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6249 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6250 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6251 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6255 | Location ref, |
| 6256 | Register obj, |
| 6257 | uint32_t offset, |
| 6258 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6259 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6260 | Location temp, |
| 6261 | bool needs_null_check) { |
| 6262 | DCHECK(kEmitCompilerReadBarrier); |
| 6263 | DCHECK(kUseBakerReadBarrier); |
| 6264 | |
| 6265 | // In slow path based read barriers, the read barrier call is |
| 6266 | // inserted after the original load. However, in fast path based |
| 6267 | // Baker's read barriers, we need to perform the load of |
| 6268 | // mirror::Object::monitor_ *before* the original reference load. |
| 6269 | // This load-load ordering is required by the read barrier. |
| 6270 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6271 | // |
| 6272 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6273 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6274 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6275 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6276 | // if (is_gray) { |
| 6277 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6278 | // } |
| 6279 | // |
| 6280 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6281 | // slightly more complex as it performs additional checks that we do |
| 6282 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6283 | |
| 6284 | Register ref_reg = ref.AsRegister<Register>(); |
| 6285 | Register temp_reg = temp.AsRegister<Register>(); |
| 6286 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6287 | |
| 6288 | // /* int32_t */ monitor = obj->monitor_ |
| 6289 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6290 | if (needs_null_check) { |
| 6291 | MaybeRecordImplicitNullCheck(instruction); |
| 6292 | } |
| 6293 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6294 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6295 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6296 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6297 | // Introduce a dependency on the lock_word including the rb_state, |
| 6298 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6299 | // a memory barrier (which would be more expensive). |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6300 | // obj is unchanged by this operation, but its value now depends on temp_reg. |
| 6301 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6302 | |
| 6303 | // The actual reference load. |
| 6304 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6305 | // Load types involving an "index": ArrayGet and |
| 6306 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6307 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6308 | if (index.IsConstant()) { |
| 6309 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6310 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6311 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6312 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6313 | // Handle the special case of the |
| 6314 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6315 | // a register pair as index ("long offset"), of which only the low |
| 6316 | // part contains data. |
| 6317 | Register index_reg = index.IsRegisterPair() |
| 6318 | ? index.AsRegisterPairLow<Register>() |
| 6319 | : index.AsRegister<Register>(); |
| 6320 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6321 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6322 | } |
| 6323 | } else { |
| 6324 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6325 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6326 | } |
| 6327 | |
| 6328 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6329 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6330 | |
| 6331 | // Slow path used to mark the object `ref` when it is gray. |
| 6332 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6333 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6334 | AddSlowPath(slow_path); |
| 6335 | |
| 6336 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6337 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6338 | // Given the numeric representation, it's enough to check the low bit of the |
| 6339 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6340 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6341 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6342 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6343 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6344 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6345 | __ 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] | 6346 | __ Bind(slow_path->GetExitLabel()); |
| 6347 | } |
| 6348 | |
| 6349 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6350 | Location out, |
| 6351 | Location ref, |
| 6352 | Location obj, |
| 6353 | uint32_t offset, |
| 6354 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6355 | DCHECK(kEmitCompilerReadBarrier); |
| 6356 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6357 | // Insert a slow path based read barrier *after* the reference load. |
| 6358 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6359 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6360 | // reference will be carried out by the runtime within the slow |
| 6361 | // path. |
| 6362 | // |
| 6363 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6364 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6365 | // not used by the artReadBarrierSlow entry point. |
| 6366 | // |
| 6367 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6368 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6369 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6370 | AddSlowPath(slow_path); |
| 6371 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6372 | __ b(slow_path->GetEntryLabel()); |
| 6373 | __ Bind(slow_path->GetExitLabel()); |
| 6374 | } |
| 6375 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6376 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6377 | Location out, |
| 6378 | Location ref, |
| 6379 | Location obj, |
| 6380 | uint32_t offset, |
| 6381 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6382 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6383 | // Baker's read barriers shall be handled by the fast path |
| 6384 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6385 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6386 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6387 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6388 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6389 | } else if (kPoisonHeapReferences) { |
| 6390 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6391 | } |
| 6392 | } |
| 6393 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6394 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6395 | Location out, |
| 6396 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6397 | DCHECK(kEmitCompilerReadBarrier); |
| 6398 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6399 | // Insert a slow path based read barrier *after* the GC root load. |
| 6400 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6401 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6402 | // not need to do anything special for this here. |
| 6403 | SlowPathCode* slow_path = |
| 6404 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6405 | AddSlowPath(slow_path); |
| 6406 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6407 | __ b(slow_path->GetEntryLabel()); |
| 6408 | __ Bind(slow_path->GetExitLabel()); |
| 6409 | } |
| 6410 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6411 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6412 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6413 | MethodReference target_method) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6414 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6415 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6416 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6417 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6418 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6419 | if (GetGraph()->HasIrreducibleLoops() && |
| 6420 | (dispatch_info.method_load_kind == |
| 6421 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6422 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6423 | } |
| 6424 | |
| 6425 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6426 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6427 | if (&outer_dex_file != target_method.dex_file) { |
| 6428 | // Calls across dex files are more likely to exceed the available BL range, |
| 6429 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6430 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6431 | (desired_dispatch_info.method_load_kind == |
| 6432 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6433 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6434 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6435 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6436 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6437 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6438 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6439 | 0u |
| 6440 | }; |
| 6441 | } |
| 6442 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6443 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6444 | } |
| 6445 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6446 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6447 | Register temp) { |
| 6448 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6449 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6450 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6451 | return location.AsRegister<Register>(); |
| 6452 | } |
| 6453 | // For intrinsics we allow any location, so it may be on the stack. |
| 6454 | if (!location.IsRegister()) { |
| 6455 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6456 | return temp; |
| 6457 | } |
| 6458 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6459 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6460 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6461 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6462 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6463 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6464 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6465 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6466 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6467 | return temp; |
| 6468 | } |
| 6469 | return location.AsRegister<Register>(); |
| 6470 | } |
| 6471 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6472 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6473 | // 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] | 6474 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6475 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6476 | // LR = code address from literal pool with link-time patch. |
| 6477 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6478 | break; |
| 6479 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6480 | // LR = invoke->GetDirectCodePtr(); |
| 6481 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6482 | break; |
| 6483 | default: |
| 6484 | break; |
| 6485 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6486 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6487 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6488 | switch (invoke->GetMethodLoadKind()) { |
| 6489 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6490 | // temp = thread->string_init_entrypoint |
| 6491 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6492 | break; |
| 6493 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6494 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6495 | break; |
| 6496 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6497 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6498 | break; |
| 6499 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6500 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6501 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6502 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6503 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6504 | HArmDexCacheArraysBase* base = |
| 6505 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6506 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6507 | temp.AsRegister<Register>()); |
| 6508 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6509 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6510 | break; |
| 6511 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6512 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6513 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6514 | Register method_reg; |
| 6515 | Register reg = temp.AsRegister<Register>(); |
| 6516 | if (current_method.IsRegister()) { |
| 6517 | method_reg = current_method.AsRegister<Register>(); |
| 6518 | } else { |
| 6519 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6520 | DCHECK(!current_method.IsValid()); |
| 6521 | method_reg = reg; |
| 6522 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6523 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6524 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6525 | __ LoadFromOffset(kLoadWord, |
| 6526 | reg, |
| 6527 | method_reg, |
| 6528 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6529 | // temp = temp[index_in_cache]; |
| 6530 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6531 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6532 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6533 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6534 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6535 | } |
| 6536 | |
| 6537 | switch (invoke->GetCodePtrLocation()) { |
| 6538 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6539 | __ bl(GetFrameEntryLabel()); |
| 6540 | break; |
| 6541 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6542 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6543 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6544 | // Arbitrarily branch to the BL itself, override at link time. |
| 6545 | __ bl(&relative_call_patches_.back().label); |
| 6546 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6547 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6548 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6549 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6550 | // LR() |
| 6551 | __ blx(LR); |
| 6552 | break; |
| 6553 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6554 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6555 | __ LoadFromOffset( |
| 6556 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 6557 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 6558 | // LR() |
| 6559 | __ blx(LR); |
| 6560 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6561 | } |
| 6562 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6563 | DCHECK(!IsLeafMethod()); |
| 6564 | } |
| 6565 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6566 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6567 | Register temp = temp_location.AsRegister<Register>(); |
| 6568 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6569 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6570 | |
| 6571 | // Use the calling convention instead of the location of the receiver, as |
| 6572 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6573 | // slow path, the arguments have been moved to the right place, so here we are |
| 6574 | // guaranteed that the receiver is the first register of the calling convention. |
| 6575 | InvokeDexCallingConvention calling_convention; |
| 6576 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6577 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6578 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6579 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6580 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6581 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6582 | // emit a read barrier for the previous class reference load. |
| 6583 | // However this is not required in practice, as this is an |
| 6584 | // intermediate/temporary reference and because the current |
| 6585 | // concurrent copying collector keeps the from-space memory |
| 6586 | // intact/accessible until the end of the marking phase (the |
| 6587 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6588 | __ MaybeUnpoisonHeapReference(temp); |
| 6589 | // temp = temp->GetMethodAt(method_offset); |
| 6590 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 6591 | kArmWordSize).Int32Value(); |
| 6592 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6593 | // LR = temp->GetEntryPoint(); |
| 6594 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6595 | // LR(); |
| 6596 | __ blx(LR); |
| 6597 | } |
| 6598 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6599 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 6600 | const DexFile& dex_file, uint32_t string_index) { |
| 6601 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 6602 | } |
| 6603 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6604 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
| 6605 | const DexFile& dex_file, uint32_t type_index) { |
| 6606 | return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_); |
| 6607 | } |
| 6608 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6609 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 6610 | const DexFile& dex_file, uint32_t element_offset) { |
| 6611 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 6612 | } |
| 6613 | |
| 6614 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 6615 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 6616 | patches->emplace_back(dex_file, offset_or_index); |
| 6617 | return &patches->back(); |
| 6618 | } |
| 6619 | |
| 6620 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 6621 | uint32_t string_index) { |
| 6622 | return boot_image_string_patches_.GetOrCreate( |
| 6623 | StringReference(&dex_file, string_index), |
| 6624 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6625 | } |
| 6626 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6627 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
| 6628 | uint32_t type_index) { |
| 6629 | return boot_image_type_patches_.GetOrCreate( |
| 6630 | TypeReference(&dex_file, type_index), |
| 6631 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6632 | } |
| 6633 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6634 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 6635 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 6636 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 6637 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 6638 | } |
| 6639 | |
| 6640 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 6641 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 6642 | } |
| 6643 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6644 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6645 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6646 | size_t size = |
| 6647 | method_patches_.size() + |
| 6648 | call_patches_.size() + |
| 6649 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6650 | /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() + |
| 6651 | boot_image_string_patches_.size() + |
| 6652 | /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6653 | boot_image_type_patches_.size() + |
| 6654 | /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6655 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6656 | linker_patches->reserve(size); |
| 6657 | for (const auto& entry : method_patches_) { |
| 6658 | const MethodReference& target_method = entry.first; |
| 6659 | Literal* literal = entry.second; |
| 6660 | DCHECK(literal->GetLabel()->IsBound()); |
| 6661 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6662 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6663 | target_method.dex_file, |
| 6664 | target_method.dex_method_index)); |
| 6665 | } |
| 6666 | for (const auto& entry : call_patches_) { |
| 6667 | const MethodReference& target_method = entry.first; |
| 6668 | Literal* literal = entry.second; |
| 6669 | DCHECK(literal->GetLabel()->IsBound()); |
| 6670 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6671 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6672 | target_method.dex_file, |
| 6673 | target_method.dex_method_index)); |
| 6674 | } |
| 6675 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6676 | uint32_t literal_offset = info.label.Position(); |
| 6677 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6678 | info.target_method.dex_file, |
| 6679 | info.target_method.dex_method_index)); |
| 6680 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6681 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
| 6682 | const DexFile& dex_file = info.target_dex_file; |
| 6683 | size_t base_element_offset = info.offset_or_index; |
| 6684 | DCHECK(info.add_pc_label.IsBound()); |
| 6685 | 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] | 6686 | // Add MOVW patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6687 | DCHECK(info.movw_label.IsBound()); |
| 6688 | 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] | 6689 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6690 | &dex_file, |
| 6691 | add_pc_offset, |
| 6692 | base_element_offset)); |
| 6693 | // Add MOVT patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6694 | DCHECK(info.movt_label.IsBound()); |
| 6695 | 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] | 6696 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6697 | &dex_file, |
| 6698 | add_pc_offset, |
| 6699 | base_element_offset)); |
| 6700 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6701 | for (const auto& entry : boot_image_string_patches_) { |
| 6702 | const StringReference& target_string = entry.first; |
| 6703 | Literal* literal = entry.second; |
| 6704 | DCHECK(literal->GetLabel()->IsBound()); |
| 6705 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6706 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 6707 | target_string.dex_file, |
| 6708 | target_string.string_index)); |
| 6709 | } |
| 6710 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 6711 | const DexFile& dex_file = info.target_dex_file; |
| 6712 | uint32_t string_index = info.offset_or_index; |
| 6713 | DCHECK(info.add_pc_label.IsBound()); |
| 6714 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6715 | // Add MOVW patch. |
| 6716 | DCHECK(info.movw_label.IsBound()); |
| 6717 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6718 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset, |
| 6719 | &dex_file, |
| 6720 | add_pc_offset, |
| 6721 | string_index)); |
| 6722 | // Add MOVT patch. |
| 6723 | DCHECK(info.movt_label.IsBound()); |
| 6724 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6725 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset, |
| 6726 | &dex_file, |
| 6727 | add_pc_offset, |
| 6728 | string_index)); |
| 6729 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6730 | for (const auto& entry : boot_image_type_patches_) { |
| 6731 | const TypeReference& target_type = entry.first; |
| 6732 | Literal* literal = entry.second; |
| 6733 | DCHECK(literal->GetLabel()->IsBound()); |
| 6734 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6735 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 6736 | target_type.dex_file, |
| 6737 | target_type.type_index)); |
| 6738 | } |
| 6739 | for (const PcRelativePatchInfo& info : pc_relative_type_patches_) { |
| 6740 | const DexFile& dex_file = info.target_dex_file; |
| 6741 | uint32_t type_index = info.offset_or_index; |
| 6742 | DCHECK(info.add_pc_label.IsBound()); |
| 6743 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6744 | // Add MOVW patch. |
| 6745 | DCHECK(info.movw_label.IsBound()); |
| 6746 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6747 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset, |
| 6748 | &dex_file, |
| 6749 | add_pc_offset, |
| 6750 | type_index)); |
| 6751 | // Add MOVT patch. |
| 6752 | DCHECK(info.movt_label.IsBound()); |
| 6753 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6754 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset, |
| 6755 | &dex_file, |
| 6756 | add_pc_offset, |
| 6757 | type_index)); |
| 6758 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6759 | for (const auto& entry : boot_image_address_patches_) { |
| 6760 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 6761 | Literal* literal = entry.second; |
| 6762 | DCHECK(literal->GetLabel()->IsBound()); |
| 6763 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6764 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 6769 | return map->GetOrCreate( |
| 6770 | value, |
| 6771 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 6775 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6776 | return map->GetOrCreate( |
| 6777 | target_method, |
| 6778 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 6782 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 6783 | } |
| 6784 | |
| 6785 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 6786 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 6787 | } |
| 6788 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6789 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 6790 | LocationSummary* locations = |
| 6791 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 6792 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 6793 | Location::RequiresRegister()); |
| 6794 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 6795 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 6796 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6797 | } |
| 6798 | |
| 6799 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 6800 | LocationSummary* locations = instr->GetLocations(); |
| 6801 | Register res = locations->Out().AsRegister<Register>(); |
| 6802 | Register accumulator = |
| 6803 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 6804 | Register mul_left = |
| 6805 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 6806 | Register mul_right = |
| 6807 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 6808 | |
| 6809 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 6810 | __ mla(res, mul_left, mul_right, accumulator); |
| 6811 | } else { |
| 6812 | __ mls(res, mul_left, mul_right, accumulator); |
| 6813 | } |
| 6814 | } |
| 6815 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6816 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6817 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6818 | LOG(FATAL) << "Unreachable"; |
| 6819 | } |
| 6820 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6821 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6822 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6823 | LOG(FATAL) << "Unreachable"; |
| 6824 | } |
| 6825 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6826 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6827 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6828 | LocationSummary* locations = |
| 6829 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6830 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6831 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6832 | codegen_->GetAssembler()->IsThumb()) { |
| 6833 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 6834 | if (switch_instr->GetStartValue() != 0) { |
| 6835 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 6836 | } |
| 6837 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6841 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6842 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6843 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6844 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6845 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6846 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6847 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6848 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6849 | Register temp_reg = IP; |
| 6850 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 6851 | // the immediate, because IP is used as the destination register. For the other |
| 6852 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 6853 | // and they can be encoded in the instruction without making use of IP register. |
| 6854 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 6855 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6856 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6857 | // Jump to successors[0] if value == lower_bound. |
| 6858 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 6859 | int32_t last_index = 0; |
| 6860 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6861 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 6862 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6863 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 6864 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6865 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 6866 | } |
| 6867 | if (num_entries - last_index == 2) { |
| 6868 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 6869 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6870 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6871 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6872 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6873 | // And the default for any other value. |
| 6874 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6875 | __ b(codegen_->GetLabelOf(default_block)); |
| 6876 | } |
| 6877 | } else { |
| 6878 | // Create a table lookup. |
| 6879 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6880 | |
| 6881 | // Materialize a pointer to the switch table |
| 6882 | std::vector<Label*> labels(num_entries); |
| 6883 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6884 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6885 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6886 | } |
| 6887 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 6888 | |
| 6889 | // Remove the bias. |
| 6890 | Register key_reg; |
| 6891 | if (lower_bound != 0) { |
| 6892 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 6893 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 6894 | } else { |
| 6895 | key_reg = value_reg; |
| 6896 | } |
| 6897 | |
| 6898 | // Check whether the value is in the table, jump to default block if not. |
| 6899 | __ CmpConstant(key_reg, num_entries - 1); |
| 6900 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 6901 | |
| 6902 | // Load the displacement from the table. |
| 6903 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 6904 | |
| 6905 | // Dispatch is a direct add to the PC (for Thumb2). |
| 6906 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6907 | } |
| 6908 | } |
| 6909 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6910 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6911 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6912 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6916 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6917 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6918 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6919 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6920 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6921 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6922 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6923 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6924 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 6925 | } |
| 6926 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6927 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6928 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6929 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6930 | return; |
| 6931 | } |
| 6932 | |
| 6933 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6934 | |
| 6935 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 6936 | if (return_loc.Equals(trg)) { |
| 6937 | return; |
| 6938 | } |
| 6939 | |
| 6940 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 6941 | // with the last branch. |
| 6942 | if (type == Primitive::kPrimLong) { |
| 6943 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6944 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 6945 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 6946 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6947 | } else if (type == Primitive::kPrimDouble) { |
| 6948 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6949 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 6950 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 6951 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6952 | } else { |
| 6953 | // Let the parallel move resolver take care of all of this. |
| 6954 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6955 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6956 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6957 | } |
| 6958 | } |
| 6959 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6960 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 6961 | LocationSummary* locations = |
| 6962 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6964 | locations->SetOut(Location::RequiresRegister()); |
| 6965 | } |
| 6966 | |
| 6967 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 6968 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6969 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6970 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6971 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6972 | __ LoadFromOffset(kLoadWord, |
| 6973 | locations->Out().AsRegister<Register>(), |
| 6974 | locations->InAt(0).AsRegister<Register>(), |
| 6975 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6976 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6977 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6978 | instruction->GetIndex() % ImTable::kSize, kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6979 | __ LoadFromOffset(kLoadWord, |
| 6980 | locations->Out().AsRegister<Register>(), |
| 6981 | locations->InAt(0).AsRegister<Register>(), |
| 6982 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 6983 | __ LoadFromOffset(kLoadWord, |
| 6984 | locations->Out().AsRegister<Register>(), |
| 6985 | locations->Out().AsRegister<Register>(), |
| 6986 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6987 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6988 | } |
| 6989 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6990 | #undef __ |
| 6991 | #undef QUICK_ENTRY_POINT |
| 6992 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6993 | } // namespace arm |
| 6994 | } // namespace art |