Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 62 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 63 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 65 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 67 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 69 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 70 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 72 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 73 | // Live registers will be restored in the catch block if caught. |
| 74 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 75 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 76 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 77 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 78 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | bool IsFatal() const OVERRIDE { return true; } |
| 82 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 83 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 84 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 86 | HNullCheck* const instruction_; |
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: |
| 92 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 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: |
| 111 | HDivZeroCheck* const instruction_; |
| 112 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 113 | }; |
| 114 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 115 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 116 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 117 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 118 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 119 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 120 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 121 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 122 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 123 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 124 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 125 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 126 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 127 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 128 | if (successor_ == nullptr) { |
| 129 | __ b(GetReturnLabel()); |
| 130 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 132 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 135 | Label* GetReturnLabel() { |
| 136 | DCHECK(successor_ == nullptr); |
| 137 | return &return_label_; |
| 138 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 139 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 140 | HBasicBlock* GetSuccessor() const { |
| 141 | return successor_; |
| 142 | } |
| 143 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 144 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 145 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | private: |
| 147 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 148 | // If not null, the block to branch to after the suspend check. |
| 149 | HBasicBlock* const successor_; |
| 150 | |
| 151 | // 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] | 152 | Label return_label_; |
| 153 | |
| 154 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 155 | }; |
| 156 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 157 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 159 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
| 160 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 162 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 163 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 164 | LocationSummary* locations = instruction_->GetLocations(); |
| 165 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 166 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 167 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 168 | // Live registers will be restored in the catch block if caught. |
| 169 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 170 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 171 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 172 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 173 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 174 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 175 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 176 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 177 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 179 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 180 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 181 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 182 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 183 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 186 | bool IsFatal() const OVERRIDE { return true; } |
| 187 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 188 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 189 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 191 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | |
| 193 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 194 | }; |
| 195 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 196 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 197 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 198 | LoadClassSlowPathARM(HLoadClass* cls, |
| 199 | HInstruction* at, |
| 200 | uint32_t dex_pc, |
| 201 | bool do_clinit) |
| 202 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 203 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 204 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 206 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 207 | LocationSummary* locations = at_->GetLocations(); |
| 208 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 209 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 210 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 211 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 212 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 213 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 214 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 215 | int32_t entry_point_offset = do_clinit_ |
| 216 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 217 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 218 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 219 | if (do_clinit_) { |
| 220 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 221 | } else { |
| 222 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 223 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | |
| 225 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 226 | Location out = locations->Out(); |
| 227 | if (out.IsValid()) { |
| 228 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 229 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 230 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 231 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | __ b(GetExitLabel()); |
| 233 | } |
| 234 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 235 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 236 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 237 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | // The class this slow path will load. |
| 239 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | // The instruction where this slow path is happening. |
| 242 | // (Might be the load class or an initialization check). |
| 243 | HInstruction* const at_; |
| 244 | |
| 245 | // The dex PC of `at_`. |
| 246 | const uint32_t dex_pc_; |
| 247 | |
| 248 | // Whether to initialize the class. |
| 249 | const bool do_clinit_; |
| 250 | |
| 251 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | }; |
| 253 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 254 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 255 | public: |
| 256 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 257 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 258 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 259 | LocationSummary* locations = instruction_->GetLocations(); |
| 260 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 261 | |
| 262 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 263 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 264 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 265 | |
| 266 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 267 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
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: |
| 280 | HLoadString* const instruction_; |
| 281 | |
| 282 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 283 | }; |
| 284 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 285 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 287 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
| 288 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 289 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 292 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 293 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 294 | DCHECK(instruction_->IsCheckCast() |
| 295 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 296 | |
| 297 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 298 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 299 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 300 | if (!is_fatal_) { |
| 301 | SaveLiveRegisters(codegen, locations); |
| 302 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | |
| 304 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 305 | // move resolver. |
| 306 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 307 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 308 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 309 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 310 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 311 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 312 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 313 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 316 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 317 | instruction_, |
| 318 | instruction_->GetDexPc(), |
| 319 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 320 | CheckEntrypointTypes< |
| 321 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 322 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 323 | } else { |
| 324 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 325 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 326 | instruction_, |
| 327 | instruction_->GetDexPc(), |
| 328 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 329 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 | if (!is_fatal_) { |
| 333 | RestoreLiveRegisters(codegen, locations); |
| 334 | __ b(GetExitLabel()); |
| 335 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 338 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 339 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 341 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 344 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
| 346 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 347 | }; |
| 348 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 349 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 350 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 351 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 352 | : instruction_(instruction) {} |
| 353 | |
| 354 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 355 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 356 | __ Bind(GetEntryLabel()); |
| 357 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 358 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 359 | instruction_, |
| 360 | instruction_->GetDexPc(), |
| 361 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 362 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 365 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 366 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 367 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 368 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 369 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 370 | }; |
| 371 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 372 | class ArraySetSlowPathARM : public SlowPathCode { |
| 373 | public: |
| 374 | explicit ArraySetSlowPathARM(HInstruction* instruction) : instruction_(instruction) {} |
| 375 | |
| 376 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 377 | LocationSummary* locations = instruction_->GetLocations(); |
| 378 | __ Bind(GetEntryLabel()); |
| 379 | SaveLiveRegisters(codegen, locations); |
| 380 | |
| 381 | InvokeRuntimeCallingConvention calling_convention; |
| 382 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 383 | parallel_move.AddMove( |
| 384 | locations->InAt(0), |
| 385 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 386 | Primitive::kPrimNot, |
| 387 | nullptr); |
| 388 | parallel_move.AddMove( |
| 389 | locations->InAt(1), |
| 390 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 391 | Primitive::kPrimInt, |
| 392 | nullptr); |
| 393 | parallel_move.AddMove( |
| 394 | locations->InAt(2), |
| 395 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 396 | Primitive::kPrimNot, |
| 397 | nullptr); |
| 398 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 399 | |
| 400 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 401 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 402 | instruction_, |
| 403 | instruction_->GetDexPc(), |
| 404 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 405 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 406 | RestoreLiveRegisters(codegen, locations); |
| 407 | __ b(GetExitLabel()); |
| 408 | } |
| 409 | |
| 410 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 411 | |
| 412 | private: |
| 413 | HInstruction* const instruction_; |
| 414 | |
| 415 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 416 | }; |
| 417 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 418 | // Slow path marking an object during a read barrier. |
| 419 | class ReadBarrierMarkSlowPathARM : public SlowPathCode { |
| 420 | public: |
| 421 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location out, Location obj) |
| 422 | : instruction_(instruction), out_(out), obj_(obj) { |
| 423 | DCHECK(kEmitCompilerReadBarrier); |
| 424 | } |
| 425 | |
| 426 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 427 | |
| 428 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 429 | LocationSummary* locations = instruction_->GetLocations(); |
| 430 | Register reg_out = out_.AsRegister<Register>(); |
| 431 | DCHECK(locations->CanCall()); |
| 432 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 433 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 434 | instruction_->IsStaticFieldGet() || |
| 435 | instruction_->IsArrayGet() || |
| 436 | instruction_->IsLoadClass() || |
| 437 | instruction_->IsLoadString() || |
| 438 | instruction_->IsInstanceOf() || |
| 439 | instruction_->IsCheckCast()) |
| 440 | << "Unexpected instruction in read barrier marking slow path: " |
| 441 | << instruction_->DebugName(); |
| 442 | |
| 443 | __ Bind(GetEntryLabel()); |
| 444 | SaveLiveRegisters(codegen, locations); |
| 445 | |
| 446 | InvokeRuntimeCallingConvention calling_convention; |
| 447 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 448 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 449 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 450 | instruction_, |
| 451 | instruction_->GetDexPc(), |
| 452 | this); |
| 453 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 454 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 455 | |
| 456 | RestoreLiveRegisters(codegen, locations); |
| 457 | __ b(GetExitLabel()); |
| 458 | } |
| 459 | |
| 460 | private: |
| 461 | HInstruction* const instruction_; |
| 462 | const Location out_; |
| 463 | const Location obj_; |
| 464 | |
| 465 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 466 | }; |
| 467 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 468 | // Slow path generating a read barrier for a heap reference. |
| 469 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 470 | public: |
| 471 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 472 | Location out, |
| 473 | Location ref, |
| 474 | Location obj, |
| 475 | uint32_t offset, |
| 476 | Location index) |
| 477 | : instruction_(instruction), |
| 478 | out_(out), |
| 479 | ref_(ref), |
| 480 | obj_(obj), |
| 481 | offset_(offset), |
| 482 | index_(index) { |
| 483 | DCHECK(kEmitCompilerReadBarrier); |
| 484 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 485 | // has been overwritten by (or after) the heap object reference load |
| 486 | // to be instrumented, e.g.: |
| 487 | // |
| 488 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 489 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 490 | // |
| 491 | // In that case, we have lost the information about the original |
| 492 | // object, and the emitted read barrier cannot work properly. |
| 493 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 494 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 495 | } |
| 496 | |
| 497 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 498 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 499 | LocationSummary* locations = instruction_->GetLocations(); |
| 500 | Register reg_out = out_.AsRegister<Register>(); |
| 501 | DCHECK(locations->CanCall()); |
| 502 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 503 | DCHECK(!instruction_->IsInvoke() || |
| 504 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 505 | instruction_->GetLocations()->Intrinsified())) |
| 506 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 507 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 508 | |
| 509 | __ Bind(GetEntryLabel()); |
| 510 | SaveLiveRegisters(codegen, locations); |
| 511 | |
| 512 | // We may have to change the index's value, but as `index_` is a |
| 513 | // constant member (like other "inputs" of this slow path), |
| 514 | // introduce a copy of it, `index`. |
| 515 | Location index = index_; |
| 516 | if (index_.IsValid()) { |
| 517 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 518 | if (instruction_->IsArrayGet()) { |
| 519 | // Compute the actual memory offset and store it in `index`. |
| 520 | Register index_reg = index_.AsRegister<Register>(); |
| 521 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 522 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 523 | // We are about to change the value of `index_reg` (see the |
| 524 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 525 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 526 | // not been saved by the previous call to |
| 527 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 528 | // callee-save register -- |
| 529 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 530 | // callee-save registers, as it has been designed with the |
| 531 | // assumption that callee-save registers are supposed to be |
| 532 | // handled by the called function. So, as a callee-save |
| 533 | // register, `index_reg` _would_ eventually be saved onto |
| 534 | // the stack, but it would be too late: we would have |
| 535 | // changed its value earlier. Therefore, we manually save |
| 536 | // it here into another freely available register, |
| 537 | // `free_reg`, chosen of course among the caller-save |
| 538 | // registers (as a callee-save `free_reg` register would |
| 539 | // exhibit the same problem). |
| 540 | // |
| 541 | // Note we could have requested a temporary register from |
| 542 | // the register allocator instead; but we prefer not to, as |
| 543 | // this is a slow path, and we know we can find a |
| 544 | // caller-save register that is available. |
| 545 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 546 | __ Mov(free_reg, index_reg); |
| 547 | index_reg = free_reg; |
| 548 | index = Location::RegisterLocation(index_reg); |
| 549 | } else { |
| 550 | // The initial register stored in `index_` has already been |
| 551 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 552 | // (as it is not a callee-save register), so we can freely |
| 553 | // use it. |
| 554 | } |
| 555 | // Shifting the index value contained in `index_reg` by the scale |
| 556 | // factor (2) cannot overflow in practice, as the runtime is |
| 557 | // unable to allocate object arrays with a size larger than |
| 558 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 559 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 560 | static_assert( |
| 561 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 562 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 563 | __ AddConstant(index_reg, index_reg, offset_); |
| 564 | } else { |
| 565 | DCHECK(instruction_->IsInvoke()); |
| 566 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 567 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 568 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 569 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 570 | DCHECK_EQ(offset_, 0U); |
| 571 | DCHECK(index_.IsRegisterPair()); |
| 572 | // UnsafeGet's offset location is a register pair, the low |
| 573 | // part contains the correct offset. |
| 574 | index = index_.ToLow(); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | // We're moving two or three locations to locations that could |
| 579 | // overlap, so we need a parallel move resolver. |
| 580 | InvokeRuntimeCallingConvention calling_convention; |
| 581 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 582 | parallel_move.AddMove(ref_, |
| 583 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 584 | Primitive::kPrimNot, |
| 585 | nullptr); |
| 586 | parallel_move.AddMove(obj_, |
| 587 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 588 | Primitive::kPrimNot, |
| 589 | nullptr); |
| 590 | if (index.IsValid()) { |
| 591 | parallel_move.AddMove(index, |
| 592 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 593 | Primitive::kPrimInt, |
| 594 | nullptr); |
| 595 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 596 | } else { |
| 597 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 598 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 599 | } |
| 600 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 601 | instruction_, |
| 602 | instruction_->GetDexPc(), |
| 603 | this); |
| 604 | CheckEntrypointTypes< |
| 605 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 606 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 607 | |
| 608 | RestoreLiveRegisters(codegen, locations); |
| 609 | __ b(GetExitLabel()); |
| 610 | } |
| 611 | |
| 612 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 613 | |
| 614 | private: |
| 615 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 616 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 617 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 618 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 619 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 620 | return static_cast<Register>(i); |
| 621 | } |
| 622 | } |
| 623 | // We shall never fail to find a free caller-save register, as |
| 624 | // there are more than two core caller-save registers on ARM |
| 625 | // (meaning it is possible to find one which is different from |
| 626 | // `ref` and `obj`). |
| 627 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 628 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 629 | UNREACHABLE(); |
| 630 | } |
| 631 | |
| 632 | HInstruction* const instruction_; |
| 633 | const Location out_; |
| 634 | const Location ref_; |
| 635 | const Location obj_; |
| 636 | const uint32_t offset_; |
| 637 | // An additional location containing an index to an array. |
| 638 | // Only used for HArrayGet and the UnsafeGetObject & |
| 639 | // UnsafeGetObjectVolatile intrinsics. |
| 640 | const Location index_; |
| 641 | |
| 642 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 643 | }; |
| 644 | |
| 645 | // Slow path generating a read barrier for a GC root. |
| 646 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 647 | public: |
| 648 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 649 | : instruction_(instruction), out_(out), root_(root) { |
| 650 | DCHECK(kEmitCompilerReadBarrier); |
| 651 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 652 | |
| 653 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 654 | LocationSummary* locations = instruction_->GetLocations(); |
| 655 | Register reg_out = out_.AsRegister<Register>(); |
| 656 | DCHECK(locations->CanCall()); |
| 657 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 658 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 659 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 660 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 661 | |
| 662 | __ Bind(GetEntryLabel()); |
| 663 | SaveLiveRegisters(codegen, locations); |
| 664 | |
| 665 | InvokeRuntimeCallingConvention calling_convention; |
| 666 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 667 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 668 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 669 | instruction_, |
| 670 | instruction_->GetDexPc(), |
| 671 | this); |
| 672 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 673 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 674 | |
| 675 | RestoreLiveRegisters(codegen, locations); |
| 676 | __ b(GetExitLabel()); |
| 677 | } |
| 678 | |
| 679 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 680 | |
| 681 | private: |
| 682 | HInstruction* const instruction_; |
| 683 | const Location out_; |
| 684 | const Location root_; |
| 685 | |
| 686 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 687 | }; |
| 688 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 689 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 690 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 691 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 692 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 693 | switch (cond) { |
| 694 | case kCondEQ: return EQ; |
| 695 | case kCondNE: return NE; |
| 696 | case kCondLT: return LT; |
| 697 | case kCondLE: return LE; |
| 698 | case kCondGT: return GT; |
| 699 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 700 | case kCondB: return LO; |
| 701 | case kCondBE: return LS; |
| 702 | case kCondA: return HI; |
| 703 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 704 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 705 | LOG(FATAL) << "Unreachable"; |
| 706 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 709 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 710 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 711 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 712 | case kCondEQ: return EQ; |
| 713 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 714 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 715 | case kCondLT: return LO; |
| 716 | case kCondLE: return LS; |
| 717 | case kCondGT: return HI; |
| 718 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 719 | // Unsigned remain unchanged. |
| 720 | case kCondB: return LO; |
| 721 | case kCondBE: return LS; |
| 722 | case kCondA: return HI; |
| 723 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 724 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 725 | LOG(FATAL) << "Unreachable"; |
| 726 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 729 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 730 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 734 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | } |
| 736 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 737 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 738 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 739 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 742 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 743 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 744 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 745 | } |
| 746 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 747 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 748 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 749 | return kArmWordSize; |
| 750 | } |
| 751 | |
| 752 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 753 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 754 | return kArmWordSize; |
| 755 | } |
| 756 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 757 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 758 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 759 | const CompilerOptions& compiler_options, |
| 760 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 761 | : CodeGenerator(graph, |
| 762 | kNumberOfCoreRegisters, |
| 763 | kNumberOfSRegisters, |
| 764 | kNumberOfRegisterPairs, |
| 765 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 766 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 767 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 768 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 769 | compiler_options, |
| 770 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 771 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 772 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 773 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 774 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 775 | assembler_(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 776 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 777 | method_patches_(MethodReferenceComparator(), |
| 778 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 779 | call_patches_(MethodReferenceComparator(), |
| 780 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 781 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 782 | dex_cache_arrays_base_labels_(std::less<HArmDexCacheArraysBase*>(), |
| 783 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 784 | // Always save the LR register to mimic Quick. |
| 785 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 786 | } |
| 787 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 788 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 789 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 790 | __ FinalizeCode(); |
| 791 | |
| 792 | // Adjust native pc offsets in stack maps. |
| 793 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 794 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 795 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 796 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 797 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 798 | // Adjust pc offsets for the disassembly information. |
| 799 | if (disasm_info_ != nullptr) { |
| 800 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 801 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 802 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 803 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 804 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 805 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 806 | } |
| 807 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 808 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 809 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 810 | } |
| 811 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 812 | |
| 813 | CodeGenerator::Finalize(allocator); |
| 814 | } |
| 815 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 816 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 817 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 818 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 819 | |
| 820 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 821 | blocked_core_registers_[SP] = true; |
| 822 | blocked_core_registers_[LR] = true; |
| 823 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 824 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 825 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 826 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 827 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 828 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 829 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 830 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 831 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 832 | // Stubs do not save callee-save floating point registers. If the graph |
| 833 | // is debuggable, we need to deal with these registers differently. For |
| 834 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 835 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 836 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 837 | } |
| 838 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 839 | |
| 840 | UpdateBlockedPairRegisters(); |
| 841 | } |
| 842 | |
| 843 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 844 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 845 | ArmManagedRegister current = |
| 846 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 847 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 848 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 849 | blocked_register_pairs_[i] = true; |
| 850 | } |
| 851 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 852 | } |
| 853 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 854 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 855 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 856 | assembler_(codegen->GetAssembler()), |
| 857 | codegen_(codegen) {} |
| 858 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 859 | void CodeGeneratorARM::ComputeSpillMask() { |
| 860 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 861 | 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^] | 862 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 863 | // restore another arbitrary register. |
| 864 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 865 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 866 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 867 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 868 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 869 | // but in the range. |
| 870 | if (fpu_spill_mask_ != 0) { |
| 871 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 872 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 873 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 874 | fpu_spill_mask_ |= (1 << i); |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 879 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 880 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 884 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 887 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 888 | bool skip_overflow_check = |
| 889 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 890 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 891 | __ Bind(&frame_entry_label_); |
| 892 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 893 | if (HasEmptyFrame()) { |
| 894 | return; |
| 895 | } |
| 896 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 897 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 898 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 899 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 900 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 901 | } |
| 902 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 903 | __ PushList(core_spill_mask_); |
| 904 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 905 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 906 | if (fpu_spill_mask_ != 0) { |
| 907 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 908 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 909 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 910 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 911 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 912 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 913 | __ AddConstant(SP, -adjust); |
| 914 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 915 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 919 | if (HasEmptyFrame()) { |
| 920 | __ bx(LR); |
| 921 | return; |
| 922 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 923 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 924 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 925 | __ AddConstant(SP, adjust); |
| 926 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 927 | if (fpu_spill_mask_ != 0) { |
| 928 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 929 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 930 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 931 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 932 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 933 | // Pop LR into PC to return. |
| 934 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 935 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 936 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 937 | __ cfi().RestoreState(); |
| 938 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 941 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 942 | Label* label = GetLabelOf(block); |
| 943 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 946 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 947 | switch (load->GetType()) { |
| 948 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 949 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 950 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 951 | |
| 952 | case Primitive::kPrimInt: |
| 953 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 954 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 955 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 956 | |
| 957 | case Primitive::kPrimBoolean: |
| 958 | case Primitive::kPrimByte: |
| 959 | case Primitive::kPrimChar: |
| 960 | case Primitive::kPrimShort: |
| 961 | case Primitive::kPrimVoid: |
| 962 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 963 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 967 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 970 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 971 | switch (type) { |
| 972 | case Primitive::kPrimBoolean: |
| 973 | case Primitive::kPrimByte: |
| 974 | case Primitive::kPrimChar: |
| 975 | case Primitive::kPrimShort: |
| 976 | case Primitive::kPrimInt: |
| 977 | case Primitive::kPrimNot: { |
| 978 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 979 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 980 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 981 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 982 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 983 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 984 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 985 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 986 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 987 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 988 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 989 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 990 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 991 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 992 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 993 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 994 | // Skip R1, and use R2_R3 instead. |
| 995 | gp_index_++; |
| 996 | index++; |
| 997 | } |
| 998 | } |
| 999 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1000 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1001 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1002 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1003 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1004 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1005 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1006 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | case Primitive::kPrimFloat: { |
| 1011 | uint32_t stack_index = stack_index_++; |
| 1012 | if (float_index_ % 2 == 0) { |
| 1013 | float_index_ = std::max(double_index_, float_index_); |
| 1014 | } |
| 1015 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1016 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1017 | } else { |
| 1018 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | case Primitive::kPrimDouble: { |
| 1023 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1024 | uint32_t stack_index = stack_index_; |
| 1025 | stack_index_ += 2; |
| 1026 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1027 | uint32_t index = double_index_; |
| 1028 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1029 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1030 | calling_convention.GetFpuRegisterAt(index), |
| 1031 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1032 | DCHECK(ExpectedPairLayout(result)); |
| 1033 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1034 | } else { |
| 1035 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1039 | case Primitive::kPrimVoid: |
| 1040 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1041 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1042 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1043 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1044 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1045 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1046 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1047 | switch (type) { |
| 1048 | case Primitive::kPrimBoolean: |
| 1049 | case Primitive::kPrimByte: |
| 1050 | case Primitive::kPrimChar: |
| 1051 | case Primitive::kPrimShort: |
| 1052 | case Primitive::kPrimInt: |
| 1053 | case Primitive::kPrimNot: { |
| 1054 | return Location::RegisterLocation(R0); |
| 1055 | } |
| 1056 | |
| 1057 | case Primitive::kPrimFloat: { |
| 1058 | return Location::FpuRegisterLocation(S0); |
| 1059 | } |
| 1060 | |
| 1061 | case Primitive::kPrimLong: { |
| 1062 | return Location::RegisterPairLocation(R0, R1); |
| 1063 | } |
| 1064 | |
| 1065 | case Primitive::kPrimDouble: { |
| 1066 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1067 | } |
| 1068 | |
| 1069 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1070 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1071 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1072 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1073 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1076 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1077 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1078 | } |
| 1079 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1080 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1081 | if (source.Equals(destination)) { |
| 1082 | return; |
| 1083 | } |
| 1084 | if (destination.IsRegister()) { |
| 1085 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1086 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1087 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1088 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1089 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1090 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1091 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1092 | } else if (destination.IsFpuRegister()) { |
| 1093 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1094 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1095 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1096 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1097 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1098 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1099 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1100 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1101 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1102 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1103 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1104 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1105 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1106 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1107 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1108 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1109 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1115 | if (source.Equals(destination)) { |
| 1116 | return; |
| 1117 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1118 | if (destination.IsRegisterPair()) { |
| 1119 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1120 | EmitParallelMoves( |
| 1121 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1122 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1123 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1124 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1125 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1126 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1127 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1128 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1129 | } else if (source.IsFpuRegisterPair()) { |
| 1130 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1131 | destination.AsRegisterPairHigh<Register>(), |
| 1132 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1133 | } else { |
| 1134 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1135 | DCHECK(ExpectedPairLayout(destination)); |
| 1136 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1137 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1138 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1139 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1140 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1141 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1142 | SP, |
| 1143 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1144 | } else if (source.IsRegisterPair()) { |
| 1145 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1146 | source.AsRegisterPairLow<Register>(), |
| 1147 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1148 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1149 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1150 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1151 | } else { |
| 1152 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1153 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1154 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1155 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1156 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1157 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1158 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1159 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1160 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1161 | SP, destination.GetStackIndex()); |
| 1162 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1163 | } else if (source.IsFpuRegisterPair()) { |
| 1164 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1165 | SP, |
| 1166 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1167 | } else { |
| 1168 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1169 | EmitParallelMoves( |
| 1170 | Location::StackSlot(source.GetStackIndex()), |
| 1171 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1172 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1173 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1174 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1175 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1180 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1181 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1182 | if (instruction->IsCurrentMethod()) { |
| 1183 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1184 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1185 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1186 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1187 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1188 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1189 | int32_t value = GetInt32ValueOf(const_to_move); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1190 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1191 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1192 | } else { |
| 1193 | DCHECK(location.IsStackSlot()); |
| 1194 | __ LoadImmediate(IP, value); |
| 1195 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 1196 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1197 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 1198 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1199 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1200 | if (location.IsRegisterPair()) { |
| 1201 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 1202 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 1203 | } else { |
| 1204 | DCHECK(location.IsDoubleStackSlot()); |
| 1205 | __ LoadImmediate(IP, Low32Bits(value)); |
| 1206 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 1207 | __ LoadImmediate(IP, High32Bits(value)); |
| 1208 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 1209 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1210 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1211 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1212 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 1213 | switch (instruction->GetType()) { |
| 1214 | case Primitive::kPrimBoolean: |
| 1215 | case Primitive::kPrimByte: |
| 1216 | case Primitive::kPrimChar: |
| 1217 | case Primitive::kPrimShort: |
| 1218 | case Primitive::kPrimInt: |
| 1219 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1220 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1221 | Move32(location, Location::StackSlot(stack_slot)); |
| 1222 | break; |
| 1223 | |
| 1224 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1225 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1226 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 1227 | break; |
| 1228 | |
| 1229 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1230 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1231 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1232 | } else if (instruction->IsTemporary()) { |
| 1233 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1234 | if (temp_location.IsStackSlot()) { |
| 1235 | Move32(location, temp_location); |
| 1236 | } else { |
| 1237 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1238 | Move64(location, temp_location); |
| 1239 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1240 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1241 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1242 | switch (instruction->GetType()) { |
| 1243 | case Primitive::kPrimBoolean: |
| 1244 | case Primitive::kPrimByte: |
| 1245 | case Primitive::kPrimChar: |
| 1246 | case Primitive::kPrimShort: |
| 1247 | case Primitive::kPrimNot: |
| 1248 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1249 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1250 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1251 | break; |
| 1252 | |
| 1253 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1254 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1255 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1256 | break; |
| 1257 | |
| 1258 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1259 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1260 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1264 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1265 | DCHECK(location.IsRegister()); |
| 1266 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1267 | } |
| 1268 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1269 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1270 | if (Primitive::Is64BitType(dst_type)) { |
| 1271 | Move64(dst, src); |
| 1272 | } else { |
| 1273 | Move32(dst, src); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1278 | if (location.IsRegister()) { |
| 1279 | locations->AddTemp(location); |
| 1280 | } else if (location.IsRegisterPair()) { |
| 1281 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1282 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1283 | } else { |
| 1284 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1285 | } |
| 1286 | } |
| 1287 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1288 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1289 | HInstruction* instruction, |
| 1290 | uint32_t dex_pc, |
| 1291 | SlowPathCode* slow_path) { |
| 1292 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1293 | instruction, |
| 1294 | dex_pc, |
| 1295 | slow_path); |
| 1296 | } |
| 1297 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1298 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1299 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1300 | uint32_t dex_pc, |
| 1301 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1302 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1303 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1304 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1305 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1306 | } |
| 1307 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1308 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1309 | DCHECK(!successor->IsExitBlock()); |
| 1310 | |
| 1311 | HBasicBlock* block = got->GetBlock(); |
| 1312 | HInstruction* previous = got->GetPrevious(); |
| 1313 | |
| 1314 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1315 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1316 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1317 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1318 | return; |
| 1319 | } |
| 1320 | |
| 1321 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1322 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1323 | } |
| 1324 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1325 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1329 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1330 | got->SetLocations(nullptr); |
| 1331 | } |
| 1332 | |
| 1333 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1334 | HandleGoto(got, got->GetSuccessor()); |
| 1335 | } |
| 1336 | |
| 1337 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1338 | try_boundary->SetLocations(nullptr); |
| 1339 | } |
| 1340 | |
| 1341 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1342 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1343 | if (!successor->IsExitBlock()) { |
| 1344 | HandleGoto(try_boundary, successor); |
| 1345 | } |
| 1346 | } |
| 1347 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1348 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1349 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1352 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1355 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1356 | Label* true_label, |
| 1357 | Label* false_label) { |
| 1358 | __ vmstat(); // transfer FP status register to ARM APSR. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1359 | // TODO: merge into a single branch (except "equal or unordered" and "not equal") |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1360 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1361 | __ b(true_label, VS); // VS for unordered. |
| 1362 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1363 | __ b(false_label, VS); // VS for unordered. |
| 1364 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1365 | __ b(true_label, ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1369 | Label* true_label, |
| 1370 | Label* false_label) { |
| 1371 | LocationSummary* locations = cond->GetLocations(); |
| 1372 | Location left = locations->InAt(0); |
| 1373 | Location right = locations->InAt(1); |
| 1374 | IfCondition if_cond = cond->GetCondition(); |
| 1375 | |
| 1376 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1377 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1378 | IfCondition true_high_cond = if_cond; |
| 1379 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1380 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1381 | |
| 1382 | // Set the conditions for the test, remembering that == needs to be |
| 1383 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1384 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1385 | switch (if_cond) { |
| 1386 | case kCondEQ: |
| 1387 | case kCondNE: |
| 1388 | // Nothing to do. |
| 1389 | break; |
| 1390 | case kCondLT: |
| 1391 | false_high_cond = kCondGT; |
| 1392 | break; |
| 1393 | case kCondLE: |
| 1394 | true_high_cond = kCondLT; |
| 1395 | break; |
| 1396 | case kCondGT: |
| 1397 | false_high_cond = kCondLT; |
| 1398 | break; |
| 1399 | case kCondGE: |
| 1400 | true_high_cond = kCondGT; |
| 1401 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1402 | case kCondB: |
| 1403 | false_high_cond = kCondA; |
| 1404 | break; |
| 1405 | case kCondBE: |
| 1406 | true_high_cond = kCondB; |
| 1407 | break; |
| 1408 | case kCondA: |
| 1409 | false_high_cond = kCondB; |
| 1410 | break; |
| 1411 | case kCondAE: |
| 1412 | true_high_cond = kCondA; |
| 1413 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1414 | } |
| 1415 | if (right.IsConstant()) { |
| 1416 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1417 | int32_t val_low = Low32Bits(value); |
| 1418 | int32_t val_high = High32Bits(value); |
| 1419 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1420 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1421 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1422 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1423 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1424 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1425 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1426 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1427 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1428 | } |
| 1429 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1430 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1431 | } else { |
| 1432 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1433 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1434 | |
| 1435 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1436 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1437 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1438 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1439 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1440 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1441 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1442 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1443 | } |
| 1444 | // Must be equal high, so compare the lows. |
| 1445 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1446 | } |
| 1447 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1448 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1449 | __ b(true_label, final_condition); |
| 1450 | } |
| 1451 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1452 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1453 | Label* true_target_in, |
| 1454 | Label* false_target_in) { |
| 1455 | // Generated branching requires both targets to be explicit. If either of the |
| 1456 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1457 | Label fallthrough_target; |
| 1458 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1459 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1460 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1461 | LocationSummary* locations = condition->GetLocations(); |
| 1462 | Location left = locations->InAt(0); |
| 1463 | Location right = locations->InAt(1); |
| 1464 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1465 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1466 | switch (type) { |
| 1467 | case Primitive::kPrimLong: |
| 1468 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1469 | break; |
| 1470 | case Primitive::kPrimFloat: |
| 1471 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1472 | GenerateFPJumps(condition, true_target, false_target); |
| 1473 | break; |
| 1474 | case Primitive::kPrimDouble: |
| 1475 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1476 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1477 | GenerateFPJumps(condition, true_target, false_target); |
| 1478 | break; |
| 1479 | default: |
| 1480 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1481 | } |
| 1482 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1483 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1484 | __ b(false_target); |
| 1485 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1486 | |
| 1487 | if (fallthrough_target.IsLinked()) { |
| 1488 | __ Bind(&fallthrough_target); |
| 1489 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1490 | } |
| 1491 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1492 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1493 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1494 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1495 | Label* false_target) { |
| 1496 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1497 | |
| 1498 | if (true_target == nullptr && false_target == nullptr) { |
| 1499 | // Nothing to do. The code always falls through. |
| 1500 | return; |
| 1501 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1502 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1503 | if (cond->AsIntConstant()->IsOne()) { |
| 1504 | if (true_target != nullptr) { |
| 1505 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1506 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1507 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1508 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1509 | if (false_target != nullptr) { |
| 1510 | __ b(false_target); |
| 1511 | } |
| 1512 | } |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | // The following code generates these patterns: |
| 1517 | // (1) true_target == nullptr && false_target != nullptr |
| 1518 | // - opposite condition true => branch to false_target |
| 1519 | // (2) true_target != nullptr && false_target == nullptr |
| 1520 | // - condition true => branch to true_target |
| 1521 | // (3) true_target != nullptr && false_target != nullptr |
| 1522 | // - condition true => branch to true_target |
| 1523 | // - branch to false_target |
| 1524 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1525 | // Condition has been materialized, compare the output to 0. |
| 1526 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1527 | DCHECK(cond_val.IsRegister()); |
| 1528 | if (true_target == nullptr) { |
| 1529 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1530 | } else { |
| 1531 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1532 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1533 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1534 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1535 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1536 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1537 | |
| 1538 | // If this is a long or FP comparison that has been folded into |
| 1539 | // the HCondition, generate the comparison directly. |
| 1540 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1541 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1542 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1543 | return; |
| 1544 | } |
| 1545 | |
| 1546 | LocationSummary* locations = cond->GetLocations(); |
| 1547 | DCHECK(locations->InAt(0).IsRegister()); |
| 1548 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1549 | Location right = locations->InAt(1); |
| 1550 | if (right.IsRegister()) { |
| 1551 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1552 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1553 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1554 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1555 | } |
| 1556 | if (true_target == nullptr) { |
| 1557 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1558 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1559 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1560 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1561 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1562 | |
| 1563 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1564 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1565 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1566 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1570 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1571 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1572 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1578 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1579 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1580 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1581 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1582 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1583 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1584 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1588 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1589 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1590 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1591 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1596 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1597 | GenerateTestAndBranch(deoptimize, |
| 1598 | /* condition_input_index */ 0, |
| 1599 | slow_path->GetEntryLabel(), |
| 1600 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1601 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1602 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1603 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1604 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1605 | } |
| 1606 | |
| 1607 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1608 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1609 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1610 | __ nop(); |
| 1611 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1612 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1613 | } |
| 1614 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1615 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1616 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1617 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1618 | // Handle the long/FP comparisons made in instruction simplification. |
| 1619 | switch (cond->InputAt(0)->GetType()) { |
| 1620 | case Primitive::kPrimLong: |
| 1621 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1622 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1623 | if (cond->NeedsMaterialization()) { |
| 1624 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1625 | } |
| 1626 | break; |
| 1627 | |
| 1628 | case Primitive::kPrimFloat: |
| 1629 | case Primitive::kPrimDouble: |
| 1630 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1631 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1632 | if (cond->NeedsMaterialization()) { |
| 1633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1634 | } |
| 1635 | break; |
| 1636 | |
| 1637 | default: |
| 1638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1639 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1640 | if (cond->NeedsMaterialization()) { |
| 1641 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1642 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1643 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1646 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1647 | if (!cond->NeedsMaterialization()) { |
| 1648 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1649 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1650 | |
| 1651 | LocationSummary* locations = cond->GetLocations(); |
| 1652 | Location left = locations->InAt(0); |
| 1653 | Location right = locations->InAt(1); |
| 1654 | Register out = locations->Out().AsRegister<Register>(); |
| 1655 | Label true_label, false_label; |
| 1656 | |
| 1657 | switch (cond->InputAt(0)->GetType()) { |
| 1658 | default: { |
| 1659 | // Integer case. |
| 1660 | if (right.IsRegister()) { |
| 1661 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1662 | } else { |
| 1663 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1664 | __ CmpConstant(left.AsRegister<Register>(), |
| 1665 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1666 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1667 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1668 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1669 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1670 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1671 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1672 | return; |
| 1673 | } |
| 1674 | case Primitive::kPrimLong: |
| 1675 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1676 | break; |
| 1677 | case Primitive::kPrimFloat: |
| 1678 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1679 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1680 | break; |
| 1681 | case Primitive::kPrimDouble: |
| 1682 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1683 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1684 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1685 | break; |
| 1686 | } |
| 1687 | |
| 1688 | // Convert the jumps into the result. |
| 1689 | Label done_label; |
| 1690 | |
| 1691 | // False case: result = 0. |
| 1692 | __ Bind(&false_label); |
| 1693 | __ LoadImmediate(out, 0); |
| 1694 | __ b(&done_label); |
| 1695 | |
| 1696 | // True case: result = 1. |
| 1697 | __ Bind(&true_label); |
| 1698 | __ LoadImmediate(out, 1); |
| 1699 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1703 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1707 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1711 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1715 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1719 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1723 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1727 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1731 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1735 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1739 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1743 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1747 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1750 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1751 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1755 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1759 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1763 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1767 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1771 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1775 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1779 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1782 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1783 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1786 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1787 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1790 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1791 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1794 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1795 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1799 | LocationSummary* locations = |
| 1800 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1801 | switch (store->InputAt(1)->GetType()) { |
| 1802 | case Primitive::kPrimBoolean: |
| 1803 | case Primitive::kPrimByte: |
| 1804 | case Primitive::kPrimChar: |
| 1805 | case Primitive::kPrimShort: |
| 1806 | case Primitive::kPrimInt: |
| 1807 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1808 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1809 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1810 | break; |
| 1811 | |
| 1812 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1813 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1814 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1815 | break; |
| 1816 | |
| 1817 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1818 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1819 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1822 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1826 | LocationSummary* locations = |
| 1827 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1828 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1831 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1832 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1835 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1836 | LocationSummary* locations = |
| 1837 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1838 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1839 | } |
| 1840 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1841 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1842 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1845 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1846 | LocationSummary* locations = |
| 1847 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1848 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1851 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1852 | // Will be generated at use site. |
| 1853 | } |
| 1854 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1855 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1856 | LocationSummary* locations = |
| 1857 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1858 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1859 | } |
| 1860 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1861 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1862 | // Will be generated at use site. |
| 1863 | } |
| 1864 | |
| 1865 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1866 | LocationSummary* locations = |
| 1867 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1868 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1869 | } |
| 1870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1871 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1872 | // Will be generated at use site. |
| 1873 | } |
| 1874 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1875 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1876 | memory_barrier->SetLocations(nullptr); |
| 1877 | } |
| 1878 | |
| 1879 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1880 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1881 | } |
| 1882 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1883 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1884 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1887 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1888 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1891 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1892 | LocationSummary* locations = |
| 1893 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1894 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1897 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1898 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1901 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1902 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1903 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1904 | // the method_idx. |
| 1905 | HandleInvoke(invoke); |
| 1906 | } |
| 1907 | |
| 1908 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1909 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1910 | } |
| 1911 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1912 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 1913 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1914 | // art::PrepareForRegisterAllocation. |
| 1915 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1916 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1917 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1918 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1919 | codegen_->GetInstructionSetFeatures()); |
| 1920 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1921 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1922 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1923 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1924 | return; |
| 1925 | } |
| 1926 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1927 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1928 | |
| 1929 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1930 | if (invoke->HasPcRelativeDexCache()) { |
| 1931 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 1932 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1935 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1936 | if (invoke->GetLocations()->Intrinsified()) { |
| 1937 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1938 | intrinsic.Dispatch(invoke); |
| 1939 | return true; |
| 1940 | } |
| 1941 | return false; |
| 1942 | } |
| 1943 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1944 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame^] | 1945 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1946 | // art::PrepareForRegisterAllocation. |
| 1947 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1948 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1949 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1950 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1951 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1952 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1953 | LocationSummary* locations = invoke->GetLocations(); |
| 1954 | codegen_->GenerateStaticOrDirectCall( |
| 1955 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1956 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1959 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1960 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1961 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1964 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1965 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1966 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1967 | codegen_->GetInstructionSetFeatures()); |
| 1968 | if (intrinsic.TryDispatch(invoke)) { |
| 1969 | return; |
| 1970 | } |
| 1971 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1972 | HandleInvoke(invoke); |
| 1973 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1974 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1975 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1976 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1977 | return; |
| 1978 | } |
| 1979 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1980 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1981 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1982 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1985 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1986 | HandleInvoke(invoke); |
| 1987 | // Add the hidden argument. |
| 1988 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1989 | } |
| 1990 | |
| 1991 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1992 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1993 | LocationSummary* locations = invoke->GetLocations(); |
| 1994 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1995 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1996 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1997 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1998 | Location receiver = locations->InAt(0); |
| 1999 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2000 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2001 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2002 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2003 | DCHECK_EQ(R12, hidden_reg); |
| 2004 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2005 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2006 | if (receiver.IsStackSlot()) { |
| 2007 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2008 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2009 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2010 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2011 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2012 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2013 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2014 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2015 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2016 | // emit a read barrier for the previous class reference load. |
| 2017 | // However this is not required in practice, as this is an |
| 2018 | // intermediate/temporary reference and because the current |
| 2019 | // concurrent copying collector keeps the from-space memory |
| 2020 | // intact/accessible until the end of the marking phase (the |
| 2021 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2022 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2023 | // temp = temp->GetImtEntryAt(method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2024 | uint32_t entry_point = |
| 2025 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2026 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 2027 | // LR = temp->GetEntryPoint(); |
| 2028 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2029 | // LR(); |
| 2030 | __ blx(LR); |
| 2031 | DCHECK(!codegen_->IsLeafMethod()); |
| 2032 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2033 | } |
| 2034 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2035 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2036 | LocationSummary* locations = |
| 2037 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2038 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2039 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2040 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2041 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2042 | break; |
| 2043 | } |
| 2044 | case Primitive::kPrimLong: { |
| 2045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2046 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2047 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2048 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2049 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2050 | case Primitive::kPrimFloat: |
| 2051 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2052 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2053 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2054 | break; |
| 2055 | |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2062 | LocationSummary* locations = neg->GetLocations(); |
| 2063 | Location out = locations->Out(); |
| 2064 | Location in = locations->InAt(0); |
| 2065 | switch (neg->GetResultType()) { |
| 2066 | case Primitive::kPrimInt: |
| 2067 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2068 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2069 | break; |
| 2070 | |
| 2071 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2072 | DCHECK(in.IsRegisterPair()); |
| 2073 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2074 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2075 | in.AsRegisterPairLow<Register>(), |
| 2076 | ShifterOperand(0)); |
| 2077 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2078 | // instruction here, as it does not exist in the Thumb-2 |
| 2079 | // instruction set. We use the following approach |
| 2080 | // using SBC and SUB instead. |
| 2081 | // |
| 2082 | // out.hi = -C |
| 2083 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2084 | out.AsRegisterPairHigh<Register>(), |
| 2085 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2086 | // out.hi = out.hi - in.hi |
| 2087 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2088 | out.AsRegisterPairHigh<Register>(), |
| 2089 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2090 | break; |
| 2091 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2092 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2093 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2094 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2095 | break; |
| 2096 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2097 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2098 | DCHECK(in.IsFpuRegisterPair()); |
| 2099 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2100 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2101 | break; |
| 2102 | |
| 2103 | default: |
| 2104 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2105 | } |
| 2106 | } |
| 2107 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2108 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2109 | Primitive::Type result_type = conversion->GetResultType(); |
| 2110 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2111 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2112 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2113 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2114 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2115 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2116 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2117 | && result_type == Primitive::kPrimLong) |
| 2118 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2119 | ? LocationSummary::kCall |
| 2120 | : LocationSummary::kNoCall; |
| 2121 | LocationSummary* locations = |
| 2122 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2123 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2124 | // The Java language does not allow treating boolean as an integral type but |
| 2125 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2126 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2127 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2128 | case Primitive::kPrimByte: |
| 2129 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2130 | case Primitive::kPrimBoolean: |
| 2131 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2132 | case Primitive::kPrimShort: |
| 2133 | case Primitive::kPrimInt: |
| 2134 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2135 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2137 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2138 | break; |
| 2139 | |
| 2140 | default: |
| 2141 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2142 | << " to " << result_type; |
| 2143 | } |
| 2144 | break; |
| 2145 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimShort: |
| 2147 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2148 | case Primitive::kPrimBoolean: |
| 2149 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2150 | case Primitive::kPrimByte: |
| 2151 | case Primitive::kPrimInt: |
| 2152 | case Primitive::kPrimChar: |
| 2153 | // Processing a Dex `int-to-short' instruction. |
| 2154 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2155 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2156 | break; |
| 2157 | |
| 2158 | default: |
| 2159 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2160 | << " to " << result_type; |
| 2161 | } |
| 2162 | break; |
| 2163 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2164 | case Primitive::kPrimInt: |
| 2165 | switch (input_type) { |
| 2166 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2167 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2168 | locations->SetInAt(0, Location::Any()); |
| 2169 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2170 | break; |
| 2171 | |
| 2172 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2173 | // Processing a Dex `float-to-int' instruction. |
| 2174 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2175 | locations->SetOut(Location::RequiresRegister()); |
| 2176 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2177 | break; |
| 2178 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2180 | // Processing a Dex `double-to-int' instruction. |
| 2181 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2182 | locations->SetOut(Location::RequiresRegister()); |
| 2183 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | |
| 2186 | default: |
| 2187 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2188 | << " to " << result_type; |
| 2189 | } |
| 2190 | break; |
| 2191 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2192 | case Primitive::kPrimLong: |
| 2193 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2194 | case Primitive::kPrimBoolean: |
| 2195 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2196 | case Primitive::kPrimByte: |
| 2197 | case Primitive::kPrimShort: |
| 2198 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2199 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2200 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2201 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2202 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2203 | break; |
| 2204 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2205 | case Primitive::kPrimFloat: { |
| 2206 | // Processing a Dex `float-to-long' instruction. |
| 2207 | InvokeRuntimeCallingConvention calling_convention; |
| 2208 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2209 | calling_convention.GetFpuRegisterAt(0))); |
| 2210 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2211 | break; |
| 2212 | } |
| 2213 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2214 | case Primitive::kPrimDouble: { |
| 2215 | // Processing a Dex `double-to-long' instruction. |
| 2216 | InvokeRuntimeCallingConvention calling_convention; |
| 2217 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2218 | calling_convention.GetFpuRegisterAt(0), |
| 2219 | calling_convention.GetFpuRegisterAt(1))); |
| 2220 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2221 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2222 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2223 | |
| 2224 | default: |
| 2225 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2226 | << " to " << result_type; |
| 2227 | } |
| 2228 | break; |
| 2229 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimChar: |
| 2231 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimBoolean: |
| 2233 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimByte: |
| 2235 | case Primitive::kPrimShort: |
| 2236 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2237 | // Processing a Dex `int-to-char' instruction. |
| 2238 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2239 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2240 | break; |
| 2241 | |
| 2242 | default: |
| 2243 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2244 | << " to " << result_type; |
| 2245 | } |
| 2246 | break; |
| 2247 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2249 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimBoolean: |
| 2251 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2252 | case Primitive::kPrimByte: |
| 2253 | case Primitive::kPrimShort: |
| 2254 | case Primitive::kPrimInt: |
| 2255 | case Primitive::kPrimChar: |
| 2256 | // Processing a Dex `int-to-float' instruction. |
| 2257 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2258 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2259 | break; |
| 2260 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2261 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2262 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2263 | InvokeRuntimeCallingConvention calling_convention; |
| 2264 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2265 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2266 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2267 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2268 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2269 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2271 | // Processing a Dex `double-to-float' instruction. |
| 2272 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2273 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2274 | break; |
| 2275 | |
| 2276 | default: |
| 2277 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2278 | << " to " << result_type; |
| 2279 | }; |
| 2280 | break; |
| 2281 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2282 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2283 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2284 | case Primitive::kPrimBoolean: |
| 2285 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimByte: |
| 2287 | case Primitive::kPrimShort: |
| 2288 | case Primitive::kPrimInt: |
| 2289 | case Primitive::kPrimChar: |
| 2290 | // Processing a Dex `int-to-double' instruction. |
| 2291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2292 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2293 | break; |
| 2294 | |
| 2295 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2296 | // Processing a Dex `long-to-double' instruction. |
| 2297 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2298 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2299 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2300 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2301 | break; |
| 2302 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2303 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2304 | // Processing a Dex `float-to-double' instruction. |
| 2305 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2306 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | |
| 2309 | default: |
| 2310 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2311 | << " to " << result_type; |
| 2312 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2313 | break; |
| 2314 | |
| 2315 | default: |
| 2316 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2317 | << " to " << result_type; |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2322 | LocationSummary* locations = conversion->GetLocations(); |
| 2323 | Location out = locations->Out(); |
| 2324 | Location in = locations->InAt(0); |
| 2325 | Primitive::Type result_type = conversion->GetResultType(); |
| 2326 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2327 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimByte: |
| 2330 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimBoolean: |
| 2332 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2333 | case Primitive::kPrimShort: |
| 2334 | case Primitive::kPrimInt: |
| 2335 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2336 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2337 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2338 | break; |
| 2339 | |
| 2340 | default: |
| 2341 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2342 | << " to " << result_type; |
| 2343 | } |
| 2344 | break; |
| 2345 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2346 | case Primitive::kPrimShort: |
| 2347 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2348 | case Primitive::kPrimBoolean: |
| 2349 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2350 | case Primitive::kPrimByte: |
| 2351 | case Primitive::kPrimInt: |
| 2352 | case Primitive::kPrimChar: |
| 2353 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2354 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | |
| 2357 | default: |
| 2358 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2359 | << " to " << result_type; |
| 2360 | } |
| 2361 | break; |
| 2362 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimInt: |
| 2364 | switch (input_type) { |
| 2365 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2366 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2367 | DCHECK(out.IsRegister()); |
| 2368 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2369 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2370 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2371 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2372 | } else { |
| 2373 | DCHECK(in.IsConstant()); |
| 2374 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2375 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2376 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2377 | } |
| 2378 | break; |
| 2379 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimFloat: { |
| 2381 | // Processing a Dex `float-to-int' instruction. |
| 2382 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2383 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 2384 | __ vcvtis(temp, temp); |
| 2385 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2386 | break; |
| 2387 | } |
| 2388 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2389 | case Primitive::kPrimDouble: { |
| 2390 | // Processing a Dex `double-to-int' instruction. |
| 2391 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2392 | DRegister temp_d = FromLowSToD(temp_s); |
| 2393 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 2394 | __ vcvtid(temp_s, temp_d); |
| 2395 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2396 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2397 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2398 | |
| 2399 | default: |
| 2400 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2401 | << " to " << result_type; |
| 2402 | } |
| 2403 | break; |
| 2404 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimLong: |
| 2406 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimBoolean: |
| 2408 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimByte: |
| 2410 | case Primitive::kPrimShort: |
| 2411 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2412 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2413 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2414 | DCHECK(out.IsRegisterPair()); |
| 2415 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2416 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2417 | // Sign extension. |
| 2418 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2419 | out.AsRegisterPairLow<Register>(), |
| 2420 | 31); |
| 2421 | break; |
| 2422 | |
| 2423 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2424 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2425 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2426 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2427 | conversion->GetDexPc(), |
| 2428 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2429 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2433 | // Processing a Dex `double-to-long' instruction. |
| 2434 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2435 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2436 | conversion->GetDexPc(), |
| 2437 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2438 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2439 | break; |
| 2440 | |
| 2441 | default: |
| 2442 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2443 | << " to " << result_type; |
| 2444 | } |
| 2445 | break; |
| 2446 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2447 | case Primitive::kPrimChar: |
| 2448 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2449 | case Primitive::kPrimBoolean: |
| 2450 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2451 | case Primitive::kPrimByte: |
| 2452 | case Primitive::kPrimShort: |
| 2453 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2454 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2455 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | |
| 2458 | default: |
| 2459 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2460 | << " to " << result_type; |
| 2461 | } |
| 2462 | break; |
| 2463 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2465 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2466 | case Primitive::kPrimBoolean: |
| 2467 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimByte: |
| 2469 | case Primitive::kPrimShort: |
| 2470 | case Primitive::kPrimInt: |
| 2471 | case Primitive::kPrimChar: { |
| 2472 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2473 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2474 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2475 | break; |
| 2476 | } |
| 2477 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2478 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2479 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2480 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2481 | conversion, |
| 2482 | conversion->GetDexPc(), |
| 2483 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2484 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2485 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2486 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2488 | // Processing a Dex `double-to-float' instruction. |
| 2489 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2490 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2491 | break; |
| 2492 | |
| 2493 | default: |
| 2494 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2495 | << " to " << result_type; |
| 2496 | }; |
| 2497 | break; |
| 2498 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2500 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2501 | case Primitive::kPrimBoolean: |
| 2502 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2503 | case Primitive::kPrimByte: |
| 2504 | case Primitive::kPrimShort: |
| 2505 | case Primitive::kPrimInt: |
| 2506 | case Primitive::kPrimChar: { |
| 2507 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2508 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2509 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2510 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2511 | break; |
| 2512 | } |
| 2513 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimLong: { |
| 2515 | // Processing a Dex `long-to-double' instruction. |
| 2516 | Register low = in.AsRegisterPairLow<Register>(); |
| 2517 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2518 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2519 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2520 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2521 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2522 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2523 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2524 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2525 | // temp_d = int-to-double(high) |
| 2526 | __ vmovsr(temp_s, high); |
| 2527 | __ vcvtdi(temp_d, temp_s); |
| 2528 | // constant_d = k2Pow32EncodingForDouble |
| 2529 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2530 | // out_d = unsigned-to-double(low) |
| 2531 | __ vmovsr(out_s, low); |
| 2532 | __ vcvtdu(out_d, out_s); |
| 2533 | // out_d += temp_d * constant_d |
| 2534 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | } |
| 2537 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2539 | // Processing a Dex `float-to-double' instruction. |
| 2540 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2541 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2542 | break; |
| 2543 | |
| 2544 | default: |
| 2545 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2546 | << " to " << result_type; |
| 2547 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2548 | break; |
| 2549 | |
| 2550 | default: |
| 2551 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2552 | << " to " << result_type; |
| 2553 | } |
| 2554 | } |
| 2555 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2556 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2557 | LocationSummary* locations = |
| 2558 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2559 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2561 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2562 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2563 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2564 | break; |
| 2565 | } |
| 2566 | |
| 2567 | case Primitive::kPrimLong: { |
| 2568 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2569 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2570 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2571 | break; |
| 2572 | } |
| 2573 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2574 | case Primitive::kPrimFloat: |
| 2575 | case Primitive::kPrimDouble: { |
| 2576 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2577 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2578 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2579 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2580 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2581 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2582 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2583 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2584 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2588 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2589 | Location out = locations->Out(); |
| 2590 | Location first = locations->InAt(0); |
| 2591 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2592 | switch (add->GetResultType()) { |
| 2593 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2594 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2595 | __ add(out.AsRegister<Register>(), |
| 2596 | first.AsRegister<Register>(), |
| 2597 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2598 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ AddConstant(out.AsRegister<Register>(), |
| 2600 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2601 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2602 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2603 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2604 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimLong: { |
| 2606 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2607 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2608 | first.AsRegisterPairLow<Register>(), |
| 2609 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2610 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2611 | first.AsRegisterPairHigh<Register>(), |
| 2612 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2613 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2614 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2615 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2616 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2617 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2618 | first.AsFpuRegister<SRegister>(), |
| 2619 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2620 | break; |
| 2621 | |
| 2622 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2623 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2624 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2625 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2626 | break; |
| 2627 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2628 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2629 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2633 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2634 | LocationSummary* locations = |
| 2635 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2636 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2639 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2640 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2641 | break; |
| 2642 | } |
| 2643 | |
| 2644 | case Primitive::kPrimLong: { |
| 2645 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2646 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2647 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2648 | break; |
| 2649 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2650 | case Primitive::kPrimFloat: |
| 2651 | case Primitive::kPrimDouble: { |
| 2652 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2653 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2654 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2655 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2656 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2657 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2658 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2659 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2663 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2664 | Location out = locations->Out(); |
| 2665 | Location first = locations->InAt(0); |
| 2666 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2667 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2668 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2669 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2670 | __ sub(out.AsRegister<Register>(), |
| 2671 | first.AsRegister<Register>(), |
| 2672 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2673 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2674 | __ AddConstant(out.AsRegister<Register>(), |
| 2675 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2676 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2677 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2678 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2679 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2680 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2681 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2682 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2683 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2684 | first.AsRegisterPairLow<Register>(), |
| 2685 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2686 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2687 | first.AsRegisterPairHigh<Register>(), |
| 2688 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2689 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2690 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2691 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2692 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2693 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2694 | first.AsFpuRegister<SRegister>(), |
| 2695 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2696 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2700 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2701 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2702 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2703 | break; |
| 2704 | } |
| 2705 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2706 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2707 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2708 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2712 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2713 | LocationSummary* locations = |
| 2714 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2715 | switch (mul->GetResultType()) { |
| 2716 | case Primitive::kPrimInt: |
| 2717 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2718 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2719 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2720 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2721 | break; |
| 2722 | } |
| 2723 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2724 | case Primitive::kPrimFloat: |
| 2725 | case Primitive::kPrimDouble: { |
| 2726 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2727 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2728 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2729 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2730 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2731 | |
| 2732 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2733 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2738 | LocationSummary* locations = mul->GetLocations(); |
| 2739 | Location out = locations->Out(); |
| 2740 | Location first = locations->InAt(0); |
| 2741 | Location second = locations->InAt(1); |
| 2742 | switch (mul->GetResultType()) { |
| 2743 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2744 | __ mul(out.AsRegister<Register>(), |
| 2745 | first.AsRegister<Register>(), |
| 2746 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2747 | break; |
| 2748 | } |
| 2749 | case Primitive::kPrimLong: { |
| 2750 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2751 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2752 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2753 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2754 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2755 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2756 | |
| 2757 | // Extra checks to protect caused by the existence of R1_R2. |
| 2758 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2759 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2760 | DCHECK_NE(out_hi, in1_lo); |
| 2761 | DCHECK_NE(out_hi, in2_lo); |
| 2762 | |
| 2763 | // input: in1 - 64 bits, in2 - 64 bits |
| 2764 | // output: out |
| 2765 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2766 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2767 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2768 | |
| 2769 | // IP <- in1.lo * in2.hi |
| 2770 | __ mul(IP, in1_lo, in2_hi); |
| 2771 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2772 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2773 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2774 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2775 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2776 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2777 | break; |
| 2778 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2779 | |
| 2780 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2781 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2782 | first.AsFpuRegister<SRegister>(), |
| 2783 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2784 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2788 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2789 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2790 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2791 | break; |
| 2792 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2793 | |
| 2794 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2795 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2799 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2800 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2801 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2802 | |
| 2803 | LocationSummary* locations = instruction->GetLocations(); |
| 2804 | Location second = locations->InAt(1); |
| 2805 | DCHECK(second.IsConstant()); |
| 2806 | |
| 2807 | Register out = locations->Out().AsRegister<Register>(); |
| 2808 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2809 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2810 | DCHECK(imm == 1 || imm == -1); |
| 2811 | |
| 2812 | if (instruction->IsRem()) { |
| 2813 | __ LoadImmediate(out, 0); |
| 2814 | } else { |
| 2815 | if (imm == 1) { |
| 2816 | __ Mov(out, dividend); |
| 2817 | } else { |
| 2818 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2819 | } |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2824 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2825 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2826 | |
| 2827 | LocationSummary* locations = instruction->GetLocations(); |
| 2828 | Location second = locations->InAt(1); |
| 2829 | DCHECK(second.IsConstant()); |
| 2830 | |
| 2831 | Register out = locations->Out().AsRegister<Register>(); |
| 2832 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2833 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2834 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2835 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2836 | int ctz_imm = CTZ(abs_imm); |
| 2837 | |
| 2838 | if (ctz_imm == 1) { |
| 2839 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2840 | } else { |
| 2841 | __ Asr(temp, dividend, 31); |
| 2842 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2843 | } |
| 2844 | __ add(out, temp, ShifterOperand(dividend)); |
| 2845 | |
| 2846 | if (instruction->IsDiv()) { |
| 2847 | __ Asr(out, out, ctz_imm); |
| 2848 | if (imm < 0) { |
| 2849 | __ rsb(out, out, ShifterOperand(0)); |
| 2850 | } |
| 2851 | } else { |
| 2852 | __ ubfx(out, out, 0, ctz_imm); |
| 2853 | __ sub(out, out, ShifterOperand(temp)); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2858 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2859 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2860 | |
| 2861 | LocationSummary* locations = instruction->GetLocations(); |
| 2862 | Location second = locations->InAt(1); |
| 2863 | DCHECK(second.IsConstant()); |
| 2864 | |
| 2865 | Register out = locations->Out().AsRegister<Register>(); |
| 2866 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2867 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2868 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2869 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2870 | |
| 2871 | int64_t magic; |
| 2872 | int shift; |
| 2873 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2874 | |
| 2875 | __ LoadImmediate(temp1, magic); |
| 2876 | __ smull(temp2, temp1, dividend, temp1); |
| 2877 | |
| 2878 | if (imm > 0 && magic < 0) { |
| 2879 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2880 | } else if (imm < 0 && magic > 0) { |
| 2881 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2882 | } |
| 2883 | |
| 2884 | if (shift != 0) { |
| 2885 | __ Asr(temp1, temp1, shift); |
| 2886 | } |
| 2887 | |
| 2888 | if (instruction->IsDiv()) { |
| 2889 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2890 | } else { |
| 2891 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2892 | // TODO: Strength reduction for mls. |
| 2893 | __ LoadImmediate(temp2, imm); |
| 2894 | __ mls(out, temp1, temp2, dividend); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2899 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2900 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2901 | |
| 2902 | LocationSummary* locations = instruction->GetLocations(); |
| 2903 | Location second = locations->InAt(1); |
| 2904 | DCHECK(second.IsConstant()); |
| 2905 | |
| 2906 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2907 | if (imm == 0) { |
| 2908 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2909 | } else if (imm == 1 || imm == -1) { |
| 2910 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2911 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2912 | DivRemByPowerOfTwo(instruction); |
| 2913 | } else { |
| 2914 | DCHECK(imm <= -2 || imm >= 2); |
| 2915 | GenerateDivRemWithAnyConstant(instruction); |
| 2916 | } |
| 2917 | } |
| 2918 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2919 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2920 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2921 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2922 | // pLdiv runtime call. |
| 2923 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2924 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2925 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2926 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2927 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2928 | // pIdivmod runtime call. |
| 2929 | call_kind = LocationSummary::kCall; |
| 2930 | } |
| 2931 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2932 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2933 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2934 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2935 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2936 | if (div->InputAt(1)->IsConstant()) { |
| 2937 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2938 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2939 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2940 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 2941 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2942 | // No temp register required. |
| 2943 | } else { |
| 2944 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2945 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2946 | locations->AddTemp(Location::RequiresRegister()); |
| 2947 | } |
| 2948 | } |
| 2949 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2951 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2952 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2953 | } else { |
| 2954 | InvokeRuntimeCallingConvention calling_convention; |
| 2955 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2956 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2957 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2958 | // we only need the former. |
| 2959 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2960 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2961 | break; |
| 2962 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2963 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2964 | InvokeRuntimeCallingConvention calling_convention; |
| 2965 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2966 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2967 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2968 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2969 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2970 | break; |
| 2971 | } |
| 2972 | case Primitive::kPrimFloat: |
| 2973 | case Primitive::kPrimDouble: { |
| 2974 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2975 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2976 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2977 | break; |
| 2978 | } |
| 2979 | |
| 2980 | default: |
| 2981 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2986 | LocationSummary* locations = div->GetLocations(); |
| 2987 | Location out = locations->Out(); |
| 2988 | Location first = locations->InAt(0); |
| 2989 | Location second = locations->InAt(1); |
| 2990 | |
| 2991 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2992 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2993 | if (second.IsConstant()) { |
| 2994 | GenerateDivRemConstantIntegral(div); |
| 2995 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2996 | __ sdiv(out.AsRegister<Register>(), |
| 2997 | first.AsRegister<Register>(), |
| 2998 | second.AsRegister<Register>()); |
| 2999 | } else { |
| 3000 | InvokeRuntimeCallingConvention calling_convention; |
| 3001 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3002 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3003 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3004 | |
| 3005 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3006 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3007 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | } |
| 3010 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3011 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3012 | InvokeRuntimeCallingConvention calling_convention; |
| 3013 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3014 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3015 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3016 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3017 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3018 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3019 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3020 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3021 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3022 | break; |
| 3023 | } |
| 3024 | |
| 3025 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3026 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3027 | first.AsFpuRegister<SRegister>(), |
| 3028 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3029 | break; |
| 3030 | } |
| 3031 | |
| 3032 | case Primitive::kPrimDouble: { |
| 3033 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3034 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3035 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3036 | break; |
| 3037 | } |
| 3038 | |
| 3039 | default: |
| 3040 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3041 | } |
| 3042 | } |
| 3043 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3044 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3045 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3046 | |
| 3047 | // Most remainders are implemented in the runtime. |
| 3048 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3049 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3050 | // sdiv will be replaced by other instruction sequence. |
| 3051 | call_kind = LocationSummary::kNoCall; |
| 3052 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3053 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3054 | // Have hardware divide instruction for int, do it with three instructions. |
| 3055 | call_kind = LocationSummary::kNoCall; |
| 3056 | } |
| 3057 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3058 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3059 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3060 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3061 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3062 | if (rem->InputAt(1)->IsConstant()) { |
| 3063 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3064 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3065 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3066 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3067 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3068 | // No temp register required. |
| 3069 | } else { |
| 3070 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3071 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3072 | locations->AddTemp(Location::RequiresRegister()); |
| 3073 | } |
| 3074 | } |
| 3075 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3077 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3078 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3079 | locations->AddTemp(Location::RequiresRegister()); |
| 3080 | } else { |
| 3081 | InvokeRuntimeCallingConvention calling_convention; |
| 3082 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3083 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3084 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3085 | // we only need the latter. |
| 3086 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3087 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3088 | break; |
| 3089 | } |
| 3090 | case Primitive::kPrimLong: { |
| 3091 | InvokeRuntimeCallingConvention calling_convention; |
| 3092 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3093 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3094 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3095 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3096 | // The runtime helper puts the output in R2,R3. |
| 3097 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3098 | break; |
| 3099 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3100 | case Primitive::kPrimFloat: { |
| 3101 | InvokeRuntimeCallingConvention calling_convention; |
| 3102 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3103 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3104 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3105 | break; |
| 3106 | } |
| 3107 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3108 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3109 | InvokeRuntimeCallingConvention calling_convention; |
| 3110 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3111 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3112 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3113 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3114 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3115 | break; |
| 3116 | } |
| 3117 | |
| 3118 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3119 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3124 | LocationSummary* locations = rem->GetLocations(); |
| 3125 | Location out = locations->Out(); |
| 3126 | Location first = locations->InAt(0); |
| 3127 | Location second = locations->InAt(1); |
| 3128 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3129 | Primitive::Type type = rem->GetResultType(); |
| 3130 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3131 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3132 | if (second.IsConstant()) { |
| 3133 | GenerateDivRemConstantIntegral(rem); |
| 3134 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3135 | Register reg1 = first.AsRegister<Register>(); |
| 3136 | Register reg2 = second.AsRegister<Register>(); |
| 3137 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3138 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3139 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3140 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3141 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3142 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3143 | } else { |
| 3144 | InvokeRuntimeCallingConvention calling_convention; |
| 3145 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3146 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3147 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3148 | |
| 3149 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3150 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3151 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | |
| 3155 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3156 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3157 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3158 | break; |
| 3159 | } |
| 3160 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3161 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3162 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3163 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3164 | break; |
| 3165 | } |
| 3166 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3167 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3168 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3169 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3170 | break; |
| 3171 | } |
| 3172 | |
| 3173 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3174 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3178 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3179 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3180 | ? LocationSummary::kCallOnSlowPath |
| 3181 | : LocationSummary::kNoCall; |
| 3182 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3183 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3184 | if (instruction->HasUses()) { |
| 3185 | locations->SetOut(Location::SameAsFirstInput()); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3190 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3191 | codegen_->AddSlowPath(slow_path); |
| 3192 | |
| 3193 | LocationSummary* locations = instruction->GetLocations(); |
| 3194 | Location value = locations->InAt(0); |
| 3195 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3196 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3197 | case Primitive::kPrimByte: |
| 3198 | case Primitive::kPrimChar: |
| 3199 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3200 | case Primitive::kPrimInt: { |
| 3201 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3202 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3203 | } else { |
| 3204 | DCHECK(value.IsConstant()) << value; |
| 3205 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3206 | __ b(slow_path->GetEntryLabel()); |
| 3207 | } |
| 3208 | } |
| 3209 | break; |
| 3210 | } |
| 3211 | case Primitive::kPrimLong: { |
| 3212 | if (value.IsRegisterPair()) { |
| 3213 | __ orrs(IP, |
| 3214 | value.AsRegisterPairLow<Register>(), |
| 3215 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3216 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3217 | } else { |
| 3218 | DCHECK(value.IsConstant()) << value; |
| 3219 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3220 | __ b(slow_path->GetEntryLabel()); |
| 3221 | } |
| 3222 | } |
| 3223 | break; |
| 3224 | default: |
| 3225 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3226 | } |
| 3227 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3230 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3231 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3232 | Location rhs = locations->InAt(1); |
| 3233 | Register out = locations->Out().AsRegister<Register>(); |
| 3234 | |
| 3235 | if (rhs.IsConstant()) { |
| 3236 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3237 | // so map all rotations to a +ve. equivalent in that range. |
| 3238 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3239 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3240 | if (rot) { |
| 3241 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3242 | // (e.g. left by 2 bits == right by 30.) |
| 3243 | __ Ror(out, in, rot); |
| 3244 | } else if (out != in) { |
| 3245 | __ Mov(out, in); |
| 3246 | } |
| 3247 | } else { |
| 3248 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3253 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3254 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3255 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3256 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3257 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3258 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3259 | Location rhs = locations->InAt(1); |
| 3260 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3261 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3262 | |
| 3263 | if (rhs.IsConstant()) { |
| 3264 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3265 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 3266 | rot &= kMaxLongShiftValue; |
| 3267 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3268 | // logic below to a simple pair of binary orr. |
| 3269 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3270 | if (rot >= kArmBitsPerWord) { |
| 3271 | rot -= kArmBitsPerWord; |
| 3272 | std::swap(in_reg_hi, in_reg_lo); |
| 3273 | } |
| 3274 | // Rotate, or mov to out for zero or word size rotations. |
| 3275 | if (rot != 0u) { |
| 3276 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3277 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3278 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3279 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3280 | } else { |
| 3281 | __ Mov(out_reg_lo, in_reg_lo); |
| 3282 | __ Mov(out_reg_hi, in_reg_hi); |
| 3283 | } |
| 3284 | } else { |
| 3285 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3286 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3287 | Label end; |
| 3288 | Label shift_by_32_plus_shift_right; |
| 3289 | |
| 3290 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3291 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3292 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3293 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3294 | |
| 3295 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3296 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3297 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3298 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3299 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3300 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3301 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3302 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3303 | __ b(&end); |
| 3304 | |
| 3305 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3306 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3307 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3308 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3309 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3310 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3311 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3312 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3313 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3314 | |
| 3315 | __ Bind(&end); |
| 3316 | } |
| 3317 | } |
| 3318 | void LocationsBuilderARM::HandleRotate(HRor* ror) { |
| 3319 | LocationSummary* locations = |
| 3320 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3321 | switch (ror->GetResultType()) { |
| 3322 | case Primitive::kPrimInt: { |
| 3323 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3324 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3325 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3326 | break; |
| 3327 | } |
| 3328 | case Primitive::kPrimLong: { |
| 3329 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3330 | if (ror->InputAt(1)->IsConstant()) { |
| 3331 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3332 | } else { |
| 3333 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3334 | locations->AddTemp(Location::RequiresRegister()); |
| 3335 | locations->AddTemp(Location::RequiresRegister()); |
| 3336 | } |
| 3337 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3338 | break; |
| 3339 | } |
| 3340 | default: |
| 3341 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | void InstructionCodeGeneratorARM::HandleRotate(HRor* ror) { |
| 3346 | LocationSummary* locations = ror->GetLocations(); |
| 3347 | Primitive::Type type = ror->GetResultType(); |
| 3348 | switch (type) { |
| 3349 | case Primitive::kPrimInt: { |
| 3350 | HandleIntegerRotate(locations); |
| 3351 | break; |
| 3352 | } |
| 3353 | case Primitive::kPrimLong: { |
| 3354 | HandleLongRotate(locations); |
| 3355 | break; |
| 3356 | } |
| 3357 | default: |
| 3358 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3359 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | void LocationsBuilderARM::VisitRor(HRor* op) { |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3364 | HandleRotate(op); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | void InstructionCodeGeneratorARM::VisitRor(HRor* op) { |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3368 | HandleRotate(op); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3369 | } |
| 3370 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3371 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3372 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3373 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3374 | LocationSummary* locations = |
| 3375 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3376 | |
| 3377 | switch (op->GetResultType()) { |
| 3378 | case Primitive::kPrimInt: { |
| 3379 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3380 | if (op->InputAt(1)->IsConstant()) { |
| 3381 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3383 | } else { |
| 3384 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3385 | // Make the output overlap, as it will be used to hold the masked |
| 3386 | // second input. |
| 3387 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3388 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3389 | break; |
| 3390 | } |
| 3391 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3392 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3393 | if (op->InputAt(1)->IsConstant()) { |
| 3394 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3395 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3396 | // don't clash with high registers which the register allocator currently guarantees. |
| 3397 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3398 | } else { |
| 3399 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3400 | locations->AddTemp(Location::RequiresRegister()); |
| 3401 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3402 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3403 | break; |
| 3404 | } |
| 3405 | default: |
| 3406 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3411 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3412 | |
| 3413 | LocationSummary* locations = op->GetLocations(); |
| 3414 | Location out = locations->Out(); |
| 3415 | Location first = locations->InAt(0); |
| 3416 | Location second = locations->InAt(1); |
| 3417 | |
| 3418 | Primitive::Type type = op->GetResultType(); |
| 3419 | switch (type) { |
| 3420 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3421 | Register out_reg = out.AsRegister<Register>(); |
| 3422 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3423 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3424 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3425 | // ARM doesn't mask the shift count so we need to do it ourselves. |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3426 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3427 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3428 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3429 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3430 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3431 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3432 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3433 | } |
| 3434 | } else { |
| 3435 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3436 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3437 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3438 | __ Mov(out_reg, first_reg); |
| 3439 | } else if (op->IsShl()) { |
| 3440 | __ Lsl(out_reg, first_reg, shift_value); |
| 3441 | } else if (op->IsShr()) { |
| 3442 | __ Asr(out_reg, first_reg, shift_value); |
| 3443 | } else { |
| 3444 | __ Lsr(out_reg, first_reg, shift_value); |
| 3445 | } |
| 3446 | } |
| 3447 | break; |
| 3448 | } |
| 3449 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3450 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3451 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3452 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3453 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3454 | Register low = first.AsRegisterPairLow<Register>(); |
| 3455 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3456 | if (second.IsRegister()) { |
| 3457 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3458 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3459 | Register second_reg = second.AsRegister<Register>(); |
| 3460 | |
| 3461 | if (op->IsShl()) { |
| 3462 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3463 | // Shift the high part |
| 3464 | __ Lsl(o_h, high, o_l); |
| 3465 | // Shift the low part and `or` what overflew on the high part |
| 3466 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3467 | __ Lsr(temp, low, temp); |
| 3468 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3469 | // If the shift is > 32 bits, override the high part |
| 3470 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3471 | __ it(PL); |
| 3472 | __ Lsl(o_h, low, temp, PL); |
| 3473 | // Shift the low part |
| 3474 | __ Lsl(o_l, low, o_l); |
| 3475 | } else if (op->IsShr()) { |
| 3476 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3477 | // Shift the low part |
| 3478 | __ Lsr(o_l, low, o_h); |
| 3479 | // Shift the high part and `or` what underflew on the low part |
| 3480 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3481 | __ Lsl(temp, high, temp); |
| 3482 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3483 | // If the shift is > 32 bits, override the low part |
| 3484 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3485 | __ it(PL); |
| 3486 | __ Asr(o_l, high, temp, PL); |
| 3487 | // Shift the high part |
| 3488 | __ Asr(o_h, high, o_h); |
| 3489 | } else { |
| 3490 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3491 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3492 | __ Lsr(o_l, low, o_h); |
| 3493 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3494 | __ Lsl(temp, high, temp); |
| 3495 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3496 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3497 | __ it(PL); |
| 3498 | __ Lsr(o_l, high, temp, PL); |
| 3499 | __ Lsr(o_h, high, o_h); |
| 3500 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3501 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3502 | // Register allocator doesn't create partial overlap. |
| 3503 | DCHECK_NE(o_l, high); |
| 3504 | DCHECK_NE(o_h, low); |
| 3505 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3506 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxLongShiftValue); |
| 3507 | if (shift_value > 32) { |
| 3508 | if (op->IsShl()) { |
| 3509 | __ Lsl(o_h, low, shift_value - 32); |
| 3510 | __ LoadImmediate(o_l, 0); |
| 3511 | } else if (op->IsShr()) { |
| 3512 | __ Asr(o_l, high, shift_value - 32); |
| 3513 | __ Asr(o_h, high, 31); |
| 3514 | } else { |
| 3515 | __ Lsr(o_l, high, shift_value - 32); |
| 3516 | __ LoadImmediate(o_h, 0); |
| 3517 | } |
| 3518 | } else if (shift_value == 32) { |
| 3519 | if (op->IsShl()) { |
| 3520 | __ mov(o_h, ShifterOperand(low)); |
| 3521 | __ LoadImmediate(o_l, 0); |
| 3522 | } else if (op->IsShr()) { |
| 3523 | __ mov(o_l, ShifterOperand(high)); |
| 3524 | __ Asr(o_h, high, 31); |
| 3525 | } else { |
| 3526 | __ mov(o_l, ShifterOperand(high)); |
| 3527 | __ LoadImmediate(o_h, 0); |
| 3528 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3529 | } else if (shift_value == 1) { |
| 3530 | if (op->IsShl()) { |
| 3531 | __ Lsls(o_l, low, 1); |
| 3532 | __ adc(o_h, high, ShifterOperand(high)); |
| 3533 | } else if (op->IsShr()) { |
| 3534 | __ Asrs(o_h, high, 1); |
| 3535 | __ Rrx(o_l, low); |
| 3536 | } else { |
| 3537 | __ Lsrs(o_h, high, 1); |
| 3538 | __ Rrx(o_l, low); |
| 3539 | } |
| 3540 | } else { |
| 3541 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3542 | if (op->IsShl()) { |
| 3543 | __ Lsl(o_h, high, shift_value); |
| 3544 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3545 | __ Lsl(o_l, low, shift_value); |
| 3546 | } else if (op->IsShr()) { |
| 3547 | __ Lsr(o_l, low, shift_value); |
| 3548 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3549 | __ Asr(o_h, high, shift_value); |
| 3550 | } else { |
| 3551 | __ Lsr(o_l, low, shift_value); |
| 3552 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3553 | __ Lsr(o_h, high, shift_value); |
| 3554 | } |
| 3555 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3556 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3557 | break; |
| 3558 | } |
| 3559 | default: |
| 3560 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3561 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3566 | HandleShift(shl); |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3570 | HandleShift(shl); |
| 3571 | } |
| 3572 | |
| 3573 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3574 | HandleShift(shr); |
| 3575 | } |
| 3576 | |
| 3577 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3578 | HandleShift(shr); |
| 3579 | } |
| 3580 | |
| 3581 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3582 | HandleShift(ushr); |
| 3583 | } |
| 3584 | |
| 3585 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3586 | HandleShift(ushr); |
| 3587 | } |
| 3588 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3589 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3590 | LocationSummary* locations = |
| 3591 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3592 | if (instruction->IsStringAlloc()) { |
| 3593 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3594 | } else { |
| 3595 | InvokeRuntimeCallingConvention calling_convention; |
| 3596 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3597 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3598 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3599 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3603 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3604 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3605 | if (instruction->IsStringAlloc()) { |
| 3606 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3607 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3608 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize); |
| 3609 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3610 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3611 | __ blx(LR); |
| 3612 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3613 | } else { |
| 3614 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3615 | instruction, |
| 3616 | instruction->GetDexPc(), |
| 3617 | nullptr); |
| 3618 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3619 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3622 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3623 | LocationSummary* locations = |
| 3624 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3625 | InvokeRuntimeCallingConvention calling_convention; |
| 3626 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3627 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3628 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3629 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3633 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3634 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3635 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3636 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3637 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3638 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3639 | instruction->GetDexPc(), |
| 3640 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3641 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3642 | } |
| 3643 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3644 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3645 | LocationSummary* locations = |
| 3646 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3647 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3648 | if (location.IsStackSlot()) { |
| 3649 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3650 | } else if (location.IsDoubleStackSlot()) { |
| 3651 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3652 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3653 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3654 | } |
| 3655 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3656 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3657 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3658 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3662 | LocationSummary* locations = |
| 3663 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3664 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3665 | } |
| 3666 | |
| 3667 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3668 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3669 | } |
| 3670 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3671 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3672 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3673 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3674 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3675 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3676 | } |
| 3677 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3678 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3679 | LocationSummary* locations = not_->GetLocations(); |
| 3680 | Location out = locations->Out(); |
| 3681 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3682 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3683 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3684 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3685 | break; |
| 3686 | |
| 3687 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3688 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3689 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3690 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3691 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3692 | break; |
| 3693 | |
| 3694 | default: |
| 3695 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3696 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3697 | } |
| 3698 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3699 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3700 | LocationSummary* locations = |
| 3701 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3703 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3704 | } |
| 3705 | |
| 3706 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3707 | LocationSummary* locations = bool_not->GetLocations(); |
| 3708 | Location out = locations->Out(); |
| 3709 | Location in = locations->InAt(0); |
| 3710 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3711 | } |
| 3712 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3713 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3714 | LocationSummary* locations = |
| 3715 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3716 | switch (compare->InputAt(0)->GetType()) { |
| 3717 | case Primitive::kPrimLong: { |
| 3718 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3719 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3720 | // Output overlaps because it is written before doing the low comparison. |
| 3721 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3722 | break; |
| 3723 | } |
| 3724 | case Primitive::kPrimFloat: |
| 3725 | case Primitive::kPrimDouble: { |
| 3726 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3727 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3728 | locations->SetOut(Location::RequiresRegister()); |
| 3729 | break; |
| 3730 | } |
| 3731 | default: |
| 3732 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3733 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3737 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3738 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3739 | Location left = locations->InAt(0); |
| 3740 | Location right = locations->InAt(1); |
| 3741 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3742 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3743 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 3744 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3745 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3746 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3747 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3748 | __ b(&less, LT); |
| 3749 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3750 | // 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] | 3751 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3752 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3753 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | case Primitive::kPrimFloat: |
| 3757 | case Primitive::kPrimDouble: { |
| 3758 | __ LoadImmediate(out, 0); |
| 3759 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3760 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3761 | } else { |
| 3762 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3763 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3764 | } |
| 3765 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 3766 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3767 | break; |
| 3768 | } |
| 3769 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3770 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3771 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3772 | __ b(&done, EQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3773 | __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3774 | |
| 3775 | __ Bind(&greater); |
| 3776 | __ LoadImmediate(out, 1); |
| 3777 | __ b(&done); |
| 3778 | |
| 3779 | __ Bind(&less); |
| 3780 | __ LoadImmediate(out, -1); |
| 3781 | |
| 3782 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3783 | } |
| 3784 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3785 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3786 | LocationSummary* locations = |
| 3787 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3788 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3789 | locations->SetInAt(i, Location::Any()); |
| 3790 | } |
| 3791 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3792 | } |
| 3793 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3794 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3795 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3796 | } |
| 3797 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3798 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3799 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3800 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3801 | switch (kind) { |
| 3802 | case MemBarrierKind::kAnyStore: |
| 3803 | case MemBarrierKind::kLoadAny: |
| 3804 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3805 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3806 | break; |
| 3807 | } |
| 3808 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3809 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3810 | break; |
| 3811 | } |
| 3812 | default: |
| 3813 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3814 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3815 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3819 | uint32_t offset, |
| 3820 | Register out_lo, |
| 3821 | Register out_hi) { |
| 3822 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3823 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3824 | // `offset` into `out_lo` does not clutter `addr`. |
| 3825 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3826 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3827 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3828 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3829 | } |
| 3830 | __ ldrexd(out_lo, out_hi, addr); |
| 3831 | } |
| 3832 | |
| 3833 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3834 | uint32_t offset, |
| 3835 | Register value_lo, |
| 3836 | Register value_hi, |
| 3837 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3838 | Register temp2, |
| 3839 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3840 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3841 | if (offset != 0) { |
| 3842 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3843 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3844 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3845 | } |
| 3846 | __ Bind(&fail); |
| 3847 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3848 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3849 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3850 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3851 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3852 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3856 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3857 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3858 | LocationSummary* locations = |
| 3859 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3860 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3861 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3862 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3863 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3864 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3865 | } else { |
| 3866 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3867 | } |
| 3868 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3869 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3870 | bool generate_volatile = field_info.IsVolatile() |
| 3871 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3872 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3873 | bool needs_write_barrier = |
| 3874 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3875 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3876 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3877 | if (needs_write_barrier) { |
| 3878 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3879 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3880 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3881 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3882 | // - registers need to be consecutive |
| 3883 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3884 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3885 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3886 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3887 | |
| 3888 | locations->AddTemp(Location::RequiresRegister()); |
| 3889 | locations->AddTemp(Location::RequiresRegister()); |
| 3890 | if (field_type == Primitive::kPrimDouble) { |
| 3891 | // For doubles we need two more registers to copy the value. |
| 3892 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3893 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3894 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3895 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3896 | } |
| 3897 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3898 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3899 | const FieldInfo& field_info, |
| 3900 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3901 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3902 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3903 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3904 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3905 | Location value = locations->InAt(1); |
| 3906 | |
| 3907 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3908 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3909 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3910 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3911 | bool needs_write_barrier = |
| 3912 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3913 | |
| 3914 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3915 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3916 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3917 | |
| 3918 | switch (field_type) { |
| 3919 | case Primitive::kPrimBoolean: |
| 3920 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3921 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3922 | break; |
| 3923 | } |
| 3924 | |
| 3925 | case Primitive::kPrimShort: |
| 3926 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3927 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3928 | break; |
| 3929 | } |
| 3930 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3931 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3932 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3933 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3934 | // Note that in the case where `value` is a null reference, |
| 3935 | // we do not enter this block, as a null reference does not |
| 3936 | // need poisoning. |
| 3937 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3938 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3939 | __ Mov(temp, value.AsRegister<Register>()); |
| 3940 | __ PoisonHeapReference(temp); |
| 3941 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3942 | } else { |
| 3943 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3944 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3945 | break; |
| 3946 | } |
| 3947 | |
| 3948 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3949 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3950 | GenerateWideAtomicStore(base, offset, |
| 3951 | value.AsRegisterPairLow<Register>(), |
| 3952 | value.AsRegisterPairHigh<Register>(), |
| 3953 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3954 | locations->GetTemp(1).AsRegister<Register>(), |
| 3955 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3956 | } else { |
| 3957 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3958 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3959 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3960 | break; |
| 3961 | } |
| 3962 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3963 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3964 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3965 | break; |
| 3966 | } |
| 3967 | |
| 3968 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3969 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3970 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3971 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3972 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3973 | |
| 3974 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3975 | |
| 3976 | GenerateWideAtomicStore(base, offset, |
| 3977 | value_reg_lo, |
| 3978 | value_reg_hi, |
| 3979 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3980 | locations->GetTemp(3).AsRegister<Register>(), |
| 3981 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3982 | } else { |
| 3983 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3984 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3985 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3986 | break; |
| 3987 | } |
| 3988 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3989 | case Primitive::kPrimVoid: |
| 3990 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3991 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3992 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3993 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3994 | // Longs and doubles are handled in the switch. |
| 3995 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3996 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3997 | } |
| 3998 | |
| 3999 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4000 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4001 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4002 | codegen_->MarkGCCard( |
| 4003 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4006 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4007 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4008 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4011 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4012 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4013 | |
| 4014 | bool object_field_get_with_read_barrier = |
| 4015 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4016 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4017 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4018 | object_field_get_with_read_barrier ? |
| 4019 | LocationSummary::kCallOnSlowPath : |
| 4020 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4021 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4022 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4023 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4024 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4025 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4026 | // The output overlaps in case of volatile long: we don't want the |
| 4027 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4028 | // object's location. Likewise, in the case of an object field get |
| 4029 | // with read barriers enabled, we do not want the load to overwrite |
| 4030 | // the object's location, as we need it to emit the read barrier. |
| 4031 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4032 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4033 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4034 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4035 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4036 | } else { |
| 4037 | locations->SetOut(Location::RequiresRegister(), |
| 4038 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4039 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4040 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4041 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4042 | // - registers need to be consecutive |
| 4043 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4044 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4045 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4046 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4047 | locations->AddTemp(Location::RequiresRegister()); |
| 4048 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4049 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4050 | // We need a temporary register for the read barrier marking slow |
| 4051 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4052 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4053 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4054 | } |
| 4055 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4056 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4057 | Opcode opcode) { |
| 4058 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4059 | if (constant->IsConstant() && |
| 4060 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4061 | return Location::ConstantLocation(constant->AsConstant()); |
| 4062 | } |
| 4063 | return Location::RequiresRegister(); |
| 4064 | } |
| 4065 | |
| 4066 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4067 | Opcode opcode) { |
| 4068 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4069 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 4070 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode) && |
| 4071 | CanEncodeConstantAsImmediate(High32Bits(value), opcode); |
| 4072 | } else { |
| 4073 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode) { |
| 4078 | ShifterOperand so; |
| 4079 | ArmAssembler* assembler = codegen_->GetAssembler(); |
| 4080 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, &so)) { |
| 4081 | return true; |
| 4082 | } |
| 4083 | Opcode neg_opcode = kNoOperand; |
| 4084 | switch (opcode) { |
| 4085 | case AND: |
| 4086 | neg_opcode = BIC; |
| 4087 | break; |
| 4088 | case ORR: |
| 4089 | neg_opcode = ORN; |
| 4090 | break; |
| 4091 | default: |
| 4092 | return false; |
| 4093 | } |
| 4094 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, ~value, &so); |
| 4095 | } |
| 4096 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4097 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4098 | const FieldInfo& field_info) { |
| 4099 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4100 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4101 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4102 | Location base_loc = locations->InAt(0); |
| 4103 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4104 | Location out = locations->Out(); |
| 4105 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4106 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4107 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4108 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4109 | |
| 4110 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4111 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4112 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4113 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4114 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4115 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4116 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4117 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4118 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4119 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4120 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4121 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4122 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4123 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4124 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4125 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4126 | |
| 4127 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4128 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4129 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4130 | |
| 4131 | case Primitive::kPrimNot: { |
| 4132 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4133 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4134 | Location temp_loc = locations->GetTemp(0); |
| 4135 | // Note that a potential implicit null check is handled in this |
| 4136 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4137 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4138 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4139 | if (is_volatile) { |
| 4140 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4141 | } |
| 4142 | } else { |
| 4143 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4144 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4145 | if (is_volatile) { |
| 4146 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4147 | } |
| 4148 | // If read barriers are enabled, emit read barriers other than |
| 4149 | // Baker's using a slow path (and also unpoison the loaded |
| 4150 | // reference, if heap poisoning is enabled). |
| 4151 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4152 | } |
| 4153 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4156 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4157 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4158 | GenerateWideAtomicLoad(base, offset, |
| 4159 | out.AsRegisterPairLow<Register>(), |
| 4160 | out.AsRegisterPairHigh<Register>()); |
| 4161 | } else { |
| 4162 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4163 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4164 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4165 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4166 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4167 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4168 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4169 | |
| 4170 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4171 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4172 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4173 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4174 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4175 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4176 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | __ vmovdrr(out_reg, lo, hi); |
| 4178 | } else { |
| 4179 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4180 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4181 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4182 | break; |
| 4183 | } |
| 4184 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4185 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4186 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4187 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4188 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4189 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4190 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4191 | // Potential implicit null checks, in the case of reference or |
| 4192 | // double fields, are handled in the previous switch statement. |
| 4193 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4194 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4195 | } |
| 4196 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4197 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4198 | if (field_type == Primitive::kPrimNot) { |
| 4199 | // Memory barriers, in the case of references, are also handled |
| 4200 | // in the previous switch statement. |
| 4201 | } else { |
| 4202 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4203 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4204 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4208 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4212 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4216 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4217 | } |
| 4218 | |
| 4219 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4220 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4221 | } |
| 4222 | |
| 4223 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4224 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4225 | } |
| 4226 | |
| 4227 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4228 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4229 | } |
| 4230 | |
| 4231 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4232 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4233 | } |
| 4234 | |
| 4235 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4236 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4237 | } |
| 4238 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4239 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4240 | HUnresolvedInstanceFieldGet* instruction) { |
| 4241 | FieldAccessCallingConventionARM calling_convention; |
| 4242 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4243 | instruction, instruction->GetFieldType(), calling_convention); |
| 4244 | } |
| 4245 | |
| 4246 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4247 | HUnresolvedInstanceFieldGet* instruction) { |
| 4248 | FieldAccessCallingConventionARM calling_convention; |
| 4249 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4250 | instruction->GetFieldType(), |
| 4251 | instruction->GetFieldIndex(), |
| 4252 | instruction->GetDexPc(), |
| 4253 | calling_convention); |
| 4254 | } |
| 4255 | |
| 4256 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4257 | HUnresolvedInstanceFieldSet* instruction) { |
| 4258 | FieldAccessCallingConventionARM calling_convention; |
| 4259 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4260 | instruction, instruction->GetFieldType(), calling_convention); |
| 4261 | } |
| 4262 | |
| 4263 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4264 | HUnresolvedInstanceFieldSet* instruction) { |
| 4265 | FieldAccessCallingConventionARM calling_convention; |
| 4266 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4267 | instruction->GetFieldType(), |
| 4268 | instruction->GetFieldIndex(), |
| 4269 | instruction->GetDexPc(), |
| 4270 | calling_convention); |
| 4271 | } |
| 4272 | |
| 4273 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4274 | HUnresolvedStaticFieldGet* instruction) { |
| 4275 | FieldAccessCallingConventionARM calling_convention; |
| 4276 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4277 | instruction, instruction->GetFieldType(), calling_convention); |
| 4278 | } |
| 4279 | |
| 4280 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4281 | HUnresolvedStaticFieldGet* instruction) { |
| 4282 | FieldAccessCallingConventionARM calling_convention; |
| 4283 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4284 | instruction->GetFieldType(), |
| 4285 | instruction->GetFieldIndex(), |
| 4286 | instruction->GetDexPc(), |
| 4287 | calling_convention); |
| 4288 | } |
| 4289 | |
| 4290 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4291 | HUnresolvedStaticFieldSet* instruction) { |
| 4292 | FieldAccessCallingConventionARM calling_convention; |
| 4293 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4294 | instruction, instruction->GetFieldType(), calling_convention); |
| 4295 | } |
| 4296 | |
| 4297 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4298 | HUnresolvedStaticFieldSet* instruction) { |
| 4299 | FieldAccessCallingConventionARM calling_convention; |
| 4300 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4301 | instruction->GetFieldType(), |
| 4302 | instruction->GetFieldIndex(), |
| 4303 | instruction->GetDexPc(), |
| 4304 | calling_convention); |
| 4305 | } |
| 4306 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4307 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4308 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4309 | ? LocationSummary::kCallOnSlowPath |
| 4310 | : LocationSummary::kNoCall; |
| 4311 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4312 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4313 | if (instruction->HasUses()) { |
| 4314 | locations->SetOut(Location::SameAsFirstInput()); |
| 4315 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4316 | } |
| 4317 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4318 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4319 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4320 | return; |
| 4321 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4322 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4323 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4324 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 4325 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4326 | } |
| 4327 | |
| 4328 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4329 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4330 | codegen_->AddSlowPath(slow_path); |
| 4331 | |
| 4332 | LocationSummary* locations = instruction->GetLocations(); |
| 4333 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4334 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4335 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4336 | } |
| 4337 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4338 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4339 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4340 | GenerateImplicitNullCheck(instruction); |
| 4341 | } else { |
| 4342 | GenerateExplicitNullCheck(instruction); |
| 4343 | } |
| 4344 | } |
| 4345 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4346 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4347 | bool object_array_get_with_read_barrier = |
| 4348 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4349 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4350 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4351 | object_array_get_with_read_barrier ? |
| 4352 | LocationSummary::kCallOnSlowPath : |
| 4353 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4355 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4356 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4357 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4358 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4359 | // The output overlaps in the case of an object array get with |
| 4360 | // read barriers enabled: we do not want the move to overwrite the |
| 4361 | // array's location, as we need it to emit the read barrier. |
| 4362 | locations->SetOut( |
| 4363 | Location::RequiresRegister(), |
| 4364 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4365 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4366 | // We need a temporary register for the read barrier marking slow |
| 4367 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4368 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4369 | locations->AddTemp(Location::RequiresRegister()); |
| 4370 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4374 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4375 | Location obj_loc = locations->InAt(0); |
| 4376 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4377 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4378 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4379 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4380 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4381 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4382 | case Primitive::kPrimBoolean: { |
| 4383 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4384 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4385 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4386 | size_t offset = |
| 4387 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4388 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 4389 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4390 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4391 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 4392 | } |
| 4393 | break; |
| 4394 | } |
| 4395 | |
| 4396 | case Primitive::kPrimByte: { |
| 4397 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4398 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4399 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4400 | size_t offset = |
| 4401 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4402 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 4403 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4404 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4405 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 4406 | } |
| 4407 | break; |
| 4408 | } |
| 4409 | |
| 4410 | case Primitive::kPrimShort: { |
| 4411 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4412 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4413 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4414 | size_t offset = |
| 4415 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4416 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 4417 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4418 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4419 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 4420 | } |
| 4421 | break; |
| 4422 | } |
| 4423 | |
| 4424 | case Primitive::kPrimChar: { |
| 4425 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4426 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4427 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4428 | size_t offset = |
| 4429 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4430 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 4431 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4432 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4433 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 4434 | } |
| 4435 | break; |
| 4436 | } |
| 4437 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4438 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4439 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4440 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4441 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4442 | size_t offset = |
| 4443 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4444 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4445 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4446 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4447 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4448 | } |
| 4449 | break; |
| 4450 | } |
| 4451 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4452 | case Primitive::kPrimNot: { |
| 4453 | static_assert( |
| 4454 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4455 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4456 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4457 | // /* HeapReference<Object> */ out = |
| 4458 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4459 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4460 | Location temp = locations->GetTemp(0); |
| 4461 | // Note that a potential implicit null check is handled in this |
| 4462 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4463 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4464 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4465 | } else { |
| 4466 | Register out = out_loc.AsRegister<Register>(); |
| 4467 | if (index.IsConstant()) { |
| 4468 | size_t offset = |
| 4469 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4470 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4471 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4472 | // If read barriers are enabled, emit read barriers other than |
| 4473 | // Baker's using a slow path (and also unpoison the loaded |
| 4474 | // reference, if heap poisoning is enabled). |
| 4475 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4476 | } else { |
| 4477 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4478 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4479 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4480 | // If read barriers are enabled, emit read barriers other than |
| 4481 | // Baker's using a slow path (and also unpoison the loaded |
| 4482 | // reference, if heap poisoning is enabled). |
| 4483 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4484 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4485 | } |
| 4486 | } |
| 4487 | break; |
| 4488 | } |
| 4489 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4490 | case Primitive::kPrimLong: { |
| 4491 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4492 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4493 | size_t offset = |
| 4494 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4495 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4496 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4497 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4498 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4499 | } |
| 4500 | break; |
| 4501 | } |
| 4502 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4503 | case Primitive::kPrimFloat: { |
| 4504 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4505 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4506 | if (index.IsConstant()) { |
| 4507 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4508 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4509 | } else { |
| 4510 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4511 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4512 | } |
| 4513 | break; |
| 4514 | } |
| 4515 | |
| 4516 | case Primitive::kPrimDouble: { |
| 4517 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4518 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4519 | if (index.IsConstant()) { |
| 4520 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4521 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4522 | } else { |
| 4523 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4524 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4525 | } |
| 4526 | break; |
| 4527 | } |
| 4528 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4529 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4530 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4531 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4532 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4533 | |
| 4534 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4535 | // Potential implicit null checks, in the case of reference |
| 4536 | // arrays, are handled in the previous switch statement. |
| 4537 | } else { |
| 4538 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4539 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4543 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4544 | |
| 4545 | bool needs_write_barrier = |
| 4546 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4547 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 4548 | bool object_array_set_with_read_barrier = |
| 4549 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4550 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4551 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4552 | instruction, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4553 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 4554 | LocationSummary::kCallOnSlowPath : |
| 4555 | LocationSummary::kNoCall); |
| 4556 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4558 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4559 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4560 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4561 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4562 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4563 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4564 | if (needs_write_barrier) { |
| 4565 | // Temporary registers for the write barrier. |
| 4566 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4567 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4568 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4572 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4573 | Location array_loc = locations->InAt(0); |
| 4574 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4575 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4576 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4577 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4578 | bool needs_write_barrier = |
| 4579 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4580 | |
| 4581 | switch (value_type) { |
| 4582 | case Primitive::kPrimBoolean: |
| 4583 | case Primitive::kPrimByte: { |
| 4584 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4585 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4586 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4587 | size_t offset = |
| 4588 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4589 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4590 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4591 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4592 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 4593 | } |
| 4594 | break; |
| 4595 | } |
| 4596 | |
| 4597 | case Primitive::kPrimShort: |
| 4598 | case Primitive::kPrimChar: { |
| 4599 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4600 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4601 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4602 | size_t offset = |
| 4603 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4604 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4605 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4606 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4607 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 4608 | } |
| 4609 | break; |
| 4610 | } |
| 4611 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4612 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4613 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4614 | Location value_loc = locations->InAt(2); |
| 4615 | Register value = value_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4616 | Register source = value; |
| 4617 | |
| 4618 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4619 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4620 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4621 | size_t offset = |
| 4622 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4623 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4624 | } else { |
| 4625 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4626 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4627 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4628 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4629 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4630 | DCHECK(!needs_write_barrier); |
| 4631 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4632 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4633 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4634 | |
| 4635 | DCHECK(needs_write_barrier); |
| 4636 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4637 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4638 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4639 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4640 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4641 | Label done; |
| 4642 | SlowPathCode* slow_path = nullptr; |
| 4643 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4644 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4645 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4646 | codegen_->AddSlowPath(slow_path); |
| 4647 | if (instruction->GetValueCanBeNull()) { |
| 4648 | Label non_zero; |
| 4649 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4650 | if (index.IsConstant()) { |
| 4651 | size_t offset = |
| 4652 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4653 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4654 | } else { |
| 4655 | DCHECK(index.IsRegister()) << index; |
| 4656 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4657 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4658 | } |
| 4659 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4660 | __ b(&done); |
| 4661 | __ Bind(&non_zero); |
| 4662 | } |
| 4663 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4664 | if (kEmitCompilerReadBarrier) { |
| 4665 | // When read barriers are enabled, the type checking |
| 4666 | // instrumentation requires two read barriers: |
| 4667 | // |
| 4668 | // __ Mov(temp2, temp1); |
| 4669 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4670 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4671 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4672 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4673 | // |
| 4674 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4675 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4676 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4677 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4678 | // |
| 4679 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4680 | // |
| 4681 | // However, the second read barrier may trash `temp`, as it |
| 4682 | // is a temporary register, and as such would not be saved |
| 4683 | // along with live registers before calling the runtime (nor |
| 4684 | // restored afterwards). So in this case, we bail out and |
| 4685 | // delegate the work to the array set slow path. |
| 4686 | // |
| 4687 | // TODO: Extend the register allocator to support a new |
| 4688 | // "(locally) live temp" location so as to avoid always |
| 4689 | // going into the slow path when read barriers are enabled. |
| 4690 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4691 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4692 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4693 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4694 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4695 | __ MaybeUnpoisonHeapReference(temp1); |
| 4696 | |
| 4697 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4698 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4699 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4700 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4701 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4702 | // nor `temp2`, as we are comparing two poisoned references. |
| 4703 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4704 | |
| 4705 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4706 | Label do_put; |
| 4707 | __ b(&do_put, EQ); |
| 4708 | // If heap poisoning is enabled, the `temp1` reference has |
| 4709 | // not been unpoisoned yet; unpoison it now. |
| 4710 | __ MaybeUnpoisonHeapReference(temp1); |
| 4711 | |
| 4712 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4713 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4714 | // If heap poisoning is enabled, no need to unpoison |
| 4715 | // `temp1`, as we are comparing against null below. |
| 4716 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4717 | __ Bind(&do_put); |
| 4718 | } else { |
| 4719 | __ b(slow_path->GetEntryLabel(), NE); |
| 4720 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4721 | } |
| 4722 | } |
| 4723 | |
| 4724 | if (kPoisonHeapReferences) { |
| 4725 | // Note that in the case where `value` is a null reference, |
| 4726 | // we do not enter this block, as a null reference does not |
| 4727 | // need poisoning. |
| 4728 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4729 | __ Mov(temp1, value); |
| 4730 | __ PoisonHeapReference(temp1); |
| 4731 | source = temp1; |
| 4732 | } |
| 4733 | |
| 4734 | if (index.IsConstant()) { |
| 4735 | size_t offset = |
| 4736 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4737 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4738 | } else { |
| 4739 | DCHECK(index.IsRegister()) << index; |
| 4740 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4741 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4742 | } |
| 4743 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4744 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4745 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4746 | } |
| 4747 | |
| 4748 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4749 | |
| 4750 | if (done.IsLinked()) { |
| 4751 | __ Bind(&done); |
| 4752 | } |
| 4753 | |
| 4754 | if (slow_path != nullptr) { |
| 4755 | __ Bind(slow_path->GetExitLabel()); |
| 4756 | } |
| 4757 | |
| 4758 | break; |
| 4759 | } |
| 4760 | |
| 4761 | case Primitive::kPrimInt: { |
| 4762 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4763 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4764 | if (index.IsConstant()) { |
| 4765 | size_t offset = |
| 4766 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4767 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4768 | } else { |
| 4769 | DCHECK(index.IsRegister()) << index; |
| 4770 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4771 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4772 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4773 | break; |
| 4774 | } |
| 4775 | |
| 4776 | case Primitive::kPrimLong: { |
| 4777 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4778 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4779 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4780 | size_t offset = |
| 4781 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4782 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4783 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4784 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4785 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4786 | } |
| 4787 | break; |
| 4788 | } |
| 4789 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4790 | case Primitive::kPrimFloat: { |
| 4791 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4792 | Location value = locations->InAt(2); |
| 4793 | DCHECK(value.IsFpuRegister()); |
| 4794 | if (index.IsConstant()) { |
| 4795 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4796 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4797 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4798 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4799 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4800 | } |
| 4801 | break; |
| 4802 | } |
| 4803 | |
| 4804 | case Primitive::kPrimDouble: { |
| 4805 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4806 | Location value = locations->InAt(2); |
| 4807 | DCHECK(value.IsFpuRegisterPair()); |
| 4808 | if (index.IsConstant()) { |
| 4809 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4810 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4811 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4812 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4813 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4814 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4815 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4816 | break; |
| 4817 | } |
| 4818 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4819 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4820 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4821 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4822 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4823 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 4824 | // Objects are handled in the switch. |
| 4825 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4826 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4827 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4831 | LocationSummary* locations = |
| 4832 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4833 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4834 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4838 | LocationSummary* locations = instruction->GetLocations(); |
| 4839 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4840 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4841 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4842 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4843 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4847 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4848 | ? LocationSummary::kCallOnSlowPath |
| 4849 | : LocationSummary::kNoCall; |
| 4850 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4851 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4852 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4853 | if (instruction->HasUses()) { |
| 4854 | locations->SetOut(Location::SameAsFirstInput()); |
| 4855 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4859 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4860 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4861 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4862 | codegen_->AddSlowPath(slow_path); |
| 4863 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4864 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4865 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4866 | |
| 4867 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4868 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4869 | } |
| 4870 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4871 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4872 | Register card, |
| 4873 | Register object, |
| 4874 | Register value, |
| 4875 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4876 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4877 | if (can_be_null) { |
| 4878 | __ CompareAndBranchIfZero(value, &is_null); |
| 4879 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4880 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4881 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4882 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4883 | if (can_be_null) { |
| 4884 | __ Bind(&is_null); |
| 4885 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4886 | } |
| 4887 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4888 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 4889 | temp->SetLocations(nullptr); |
| 4890 | } |
| 4891 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4892 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4893 | // Nothing to do, this is driven by the code generator. |
| 4894 | } |
| 4895 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4896 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4897 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4901 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4902 | } |
| 4903 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4904 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4905 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4906 | } |
| 4907 | |
| 4908 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4909 | HBasicBlock* block = instruction->GetBlock(); |
| 4910 | if (block->GetLoopInformation() != nullptr) { |
| 4911 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4912 | // The back edge will generate the suspend check. |
| 4913 | return; |
| 4914 | } |
| 4915 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4916 | // The goto will generate the suspend check. |
| 4917 | return; |
| 4918 | } |
| 4919 | GenerateSuspendCheck(instruction, nullptr); |
| 4920 | } |
| 4921 | |
| 4922 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4923 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4924 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4925 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4926 | if (slow_path == nullptr) { |
| 4927 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4928 | instruction->SetSlowPath(slow_path); |
| 4929 | codegen_->AddSlowPath(slow_path); |
| 4930 | if (successor != nullptr) { |
| 4931 | DCHECK(successor->IsLoopHeader()); |
| 4932 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4933 | } |
| 4934 | } else { |
| 4935 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4936 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4937 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4938 | __ LoadFromOffset( |
| 4939 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4940 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4941 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4942 | __ Bind(slow_path->GetReturnLabel()); |
| 4943 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4944 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4945 | __ b(slow_path->GetEntryLabel()); |
| 4946 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4947 | } |
| 4948 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4949 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4950 | return codegen_->GetAssembler(); |
| 4951 | } |
| 4952 | |
| 4953 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4954 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4955 | Location source = move->GetSource(); |
| 4956 | Location destination = move->GetDestination(); |
| 4957 | |
| 4958 | if (source.IsRegister()) { |
| 4959 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4960 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4961 | } else { |
| 4962 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4963 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4964 | SP, destination.GetStackIndex()); |
| 4965 | } |
| 4966 | } else if (source.IsStackSlot()) { |
| 4967 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4968 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4969 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4970 | } else if (destination.IsFpuRegister()) { |
| 4971 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4972 | } else { |
| 4973 | DCHECK(destination.IsStackSlot()); |
| 4974 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4975 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4976 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4977 | } else if (source.IsFpuRegister()) { |
| 4978 | if (destination.IsFpuRegister()) { |
| 4979 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4980 | } else { |
| 4981 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4982 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4983 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4984 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4985 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4986 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4987 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4988 | } else if (destination.IsRegisterPair()) { |
| 4989 | DCHECK(ExpectedPairLayout(destination)); |
| 4990 | __ LoadFromOffset( |
| 4991 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4992 | } else { |
| 4993 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4994 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4995 | SP, |
| 4996 | source.GetStackIndex()); |
| 4997 | } |
| 4998 | } else if (source.IsRegisterPair()) { |
| 4999 | if (destination.IsRegisterPair()) { |
| 5000 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5001 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 5002 | } else { |
| 5003 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5004 | DCHECK(ExpectedPairLayout(source)); |
| 5005 | __ StoreToOffset( |
| 5006 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5007 | } |
| 5008 | } else if (source.IsFpuRegisterPair()) { |
| 5009 | if (destination.IsFpuRegisterPair()) { |
| 5010 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5011 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5012 | } else { |
| 5013 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5014 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5015 | SP, |
| 5016 | destination.GetStackIndex()); |
| 5017 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5018 | } else { |
| 5019 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5020 | HConstant* constant = source.GetConstant(); |
| 5021 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5022 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5023 | if (destination.IsRegister()) { |
| 5024 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5025 | } else { |
| 5026 | DCHECK(destination.IsStackSlot()); |
| 5027 | __ LoadImmediate(IP, value); |
| 5028 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5029 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5030 | } else if (constant->IsLongConstant()) { |
| 5031 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5032 | if (destination.IsRegisterPair()) { |
| 5033 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5034 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5035 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5036 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5037 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5038 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5039 | __ LoadImmediate(IP, High32Bits(value)); |
| 5040 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5041 | } |
| 5042 | } else if (constant->IsDoubleConstant()) { |
| 5043 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5044 | if (destination.IsFpuRegisterPair()) { |
| 5045 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5046 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5047 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5048 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5049 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5050 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5051 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5052 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5053 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5054 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5055 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5056 | float value = constant->AsFloatConstant()->GetValue(); |
| 5057 | if (destination.IsFpuRegister()) { |
| 5058 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5059 | } else { |
| 5060 | DCHECK(destination.IsStackSlot()); |
| 5061 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5062 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5063 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5064 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5069 | __ Mov(IP, reg); |
| 5070 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5071 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5072 | } |
| 5073 | |
| 5074 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5075 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5076 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5077 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5078 | SP, mem1 + stack_offset); |
| 5079 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5080 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5081 | SP, mem2 + stack_offset); |
| 5082 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5083 | } |
| 5084 | |
| 5085 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5086 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5087 | Location source = move->GetSource(); |
| 5088 | Location destination = move->GetDestination(); |
| 5089 | |
| 5090 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5091 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5092 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5093 | __ Mov(IP, source.AsRegister<Register>()); |
| 5094 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5095 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5096 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5097 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5098 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5099 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5100 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5101 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5102 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5103 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5104 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5105 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5106 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5107 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5108 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5109 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5110 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5111 | destination.AsRegisterPairHigh<Register>(), |
| 5112 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5113 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5114 | Register low_reg = source.IsRegisterPair() |
| 5115 | ? source.AsRegisterPairLow<Register>() |
| 5116 | : destination.AsRegisterPairLow<Register>(); |
| 5117 | int mem = source.IsRegisterPair() |
| 5118 | ? destination.GetStackIndex() |
| 5119 | : source.GetStackIndex(); |
| 5120 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5121 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5122 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5123 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5124 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5125 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5126 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5127 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5128 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5129 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5130 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5131 | DRegister reg = source.IsFpuRegisterPair() |
| 5132 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5133 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5134 | int mem = source.IsFpuRegisterPair() |
| 5135 | ? destination.GetStackIndex() |
| 5136 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5137 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5138 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5139 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5140 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5141 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5142 | : destination.AsFpuRegister<SRegister>(); |
| 5143 | int mem = source.IsFpuRegister() |
| 5144 | ? destination.GetStackIndex() |
| 5145 | : source.GetStackIndex(); |
| 5146 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5147 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5148 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5149 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5150 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5151 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5152 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5153 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5154 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5155 | } |
| 5156 | } |
| 5157 | |
| 5158 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5159 | __ Push(static_cast<Register>(reg)); |
| 5160 | } |
| 5161 | |
| 5162 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5163 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5166 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5167 | InvokeRuntimeCallingConvention calling_convention; |
| 5168 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5169 | cls, |
| 5170 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5171 | Location::RegisterLocation(R0), |
| 5172 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5176 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5177 | if (cls->NeedsAccessCheck()) { |
| 5178 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5179 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5180 | cls, |
| 5181 | cls->GetDexPc(), |
| 5182 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5183 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5184 | return; |
| 5185 | } |
| 5186 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5187 | Location out_loc = locations->Out(); |
| 5188 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5189 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5190 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5191 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5192 | DCHECK(!cls->CanCallRuntime()); |
| 5193 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5194 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5195 | GenerateGcRootFieldLoad( |
| 5196 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5197 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5198 | // /* GcRoot<mirror::Class>[] */ out = |
| 5199 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5200 | __ LoadFromOffset(kLoadWord, |
| 5201 | out, |
| 5202 | current_method, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5203 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5204 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5205 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5206 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5207 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5208 | DCHECK(cls->CanCallRuntime()); |
| 5209 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 5210 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5211 | codegen_->AddSlowPath(slow_path); |
| 5212 | if (!cls->IsInDexCache()) { |
| 5213 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5214 | } |
| 5215 | if (cls->MustGenerateClinitCheck()) { |
| 5216 | GenerateClassInitializationCheck(slow_path, out); |
| 5217 | } else { |
| 5218 | __ Bind(slow_path->GetExitLabel()); |
| 5219 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5220 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5225 | LocationSummary* locations = |
| 5226 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5227 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5228 | if (check->HasUses()) { |
| 5229 | locations->SetOut(Location::SameAsFirstInput()); |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5234 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5235 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5236 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5237 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5238 | GenerateClassInitializationCheck(slow_path, |
| 5239 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5240 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5241 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5242 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5243 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5244 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5245 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5246 | __ b(slow_path->GetEntryLabel(), LT); |
| 5247 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5248 | // properly. Therefore, we do a memory fence. |
| 5249 | __ dmb(ISH); |
| 5250 | __ Bind(slow_path->GetExitLabel()); |
| 5251 | } |
| 5252 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5253 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5254 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5255 | ? LocationSummary::kCallOnSlowPath |
| 5256 | : LocationSummary::kNoCall; |
| 5257 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5258 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5259 | locations->SetOut(Location::RequiresRegister()); |
| 5260 | } |
| 5261 | |
| 5262 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5263 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5264 | Location out_loc = locations->Out(); |
| 5265 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5266 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5267 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5268 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5269 | GenerateGcRootFieldLoad( |
| 5270 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5271 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5272 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5273 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5274 | GenerateGcRootFieldLoad( |
| 5275 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5276 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5277 | if (!load->IsInDexCache()) { |
| 5278 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5279 | codegen_->AddSlowPath(slow_path); |
| 5280 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5281 | __ Bind(slow_path->GetExitLabel()); |
| 5282 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5283 | } |
| 5284 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5285 | static int32_t GetExceptionTlsOffset() { |
| 5286 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 5287 | } |
| 5288 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5289 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5290 | LocationSummary* locations = |
| 5291 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5292 | locations->SetOut(Location::RequiresRegister()); |
| 5293 | } |
| 5294 | |
| 5295 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5296 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5297 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5298 | } |
| 5299 | |
| 5300 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5301 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5302 | } |
| 5303 | |
| 5304 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5305 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5306 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5310 | LocationSummary* locations = |
| 5311 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5312 | InvokeRuntimeCallingConvention calling_convention; |
| 5313 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5314 | } |
| 5315 | |
| 5316 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 5317 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5318 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5319 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5320 | } |
| 5321 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5322 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5323 | return kEmitCompilerReadBarrier && |
| 5324 | (kUseBakerReadBarrier || |
| 5325 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5326 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5327 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5328 | } |
| 5329 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5330 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5331 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5332 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5333 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5334 | case TypeCheckKind::kExactCheck: |
| 5335 | case TypeCheckKind::kAbstractClassCheck: |
| 5336 | case TypeCheckKind::kClassHierarchyCheck: |
| 5337 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5338 | call_kind = |
| 5339 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5340 | break; |
| 5341 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5342 | case TypeCheckKind::kUnresolvedCheck: |
| 5343 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5344 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5345 | break; |
| 5346 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5347 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5348 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5350 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5351 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5352 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5353 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5354 | // When read barriers are enabled, we need a temporary register for |
| 5355 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5356 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5357 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5358 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5359 | } |
| 5360 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5361 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5362 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5363 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5364 | Location obj_loc = locations->InAt(0); |
| 5365 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5366 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5367 | Location out_loc = locations->Out(); |
| 5368 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5369 | Location temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5370 | locations->GetTemp(0) : |
| 5371 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5372 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5373 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5374 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5375 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5376 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5377 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5378 | |
| 5379 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5380 | // avoid null check if we know obj is not null. |
| 5381 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5382 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5383 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5384 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5385 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5386 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5387 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5388 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5389 | case TypeCheckKind::kExactCheck: { |
| 5390 | __ cmp(out, ShifterOperand(cls)); |
| 5391 | // Classes must be equal for the instanceof to succeed. |
| 5392 | __ b(&zero, NE); |
| 5393 | __ LoadImmediate(out, 1); |
| 5394 | __ b(&done); |
| 5395 | break; |
| 5396 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5397 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5398 | case TypeCheckKind::kAbstractClassCheck: { |
| 5399 | // If the class is abstract, we eagerly fetch the super class of the |
| 5400 | // object to avoid doing a comparison we know will fail. |
| 5401 | Label loop; |
| 5402 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5403 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5404 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5405 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5406 | __ CompareAndBranchIfZero(out, &done); |
| 5407 | __ cmp(out, ShifterOperand(cls)); |
| 5408 | __ b(&loop, NE); |
| 5409 | __ LoadImmediate(out, 1); |
| 5410 | if (zero.IsLinked()) { |
| 5411 | __ b(&done); |
| 5412 | } |
| 5413 | break; |
| 5414 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5415 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5416 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5417 | // Walk over the class hierarchy to find a match. |
| 5418 | Label loop, success; |
| 5419 | __ Bind(&loop); |
| 5420 | __ cmp(out, ShifterOperand(cls)); |
| 5421 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5422 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5423 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5424 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5425 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5426 | __ b(&done); |
| 5427 | __ Bind(&success); |
| 5428 | __ LoadImmediate(out, 1); |
| 5429 | if (zero.IsLinked()) { |
| 5430 | __ b(&done); |
| 5431 | } |
| 5432 | break; |
| 5433 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5434 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5435 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5436 | // Do an exact check. |
| 5437 | Label exact_check; |
| 5438 | __ cmp(out, ShifterOperand(cls)); |
| 5439 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5440 | // 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] | 5441 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5442 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5443 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5444 | __ CompareAndBranchIfZero(out, &done); |
| 5445 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5446 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5447 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5448 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5449 | __ LoadImmediate(out, 1); |
| 5450 | __ b(&done); |
| 5451 | break; |
| 5452 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5453 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5454 | case TypeCheckKind::kArrayCheck: { |
| 5455 | __ cmp(out, ShifterOperand(cls)); |
| 5456 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5457 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5458 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5459 | codegen_->AddSlowPath(slow_path); |
| 5460 | __ b(slow_path->GetEntryLabel(), NE); |
| 5461 | __ LoadImmediate(out, 1); |
| 5462 | if (zero.IsLinked()) { |
| 5463 | __ b(&done); |
| 5464 | } |
| 5465 | break; |
| 5466 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5467 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5468 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5469 | case TypeCheckKind::kInterfaceCheck: { |
| 5470 | // Note that we indeed only call on slow path, but we always go |
| 5471 | // into the slow path for the unresolved & interface check |
| 5472 | // cases. |
| 5473 | // |
| 5474 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5475 | // entry point without resorting to a type checking slow path |
| 5476 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5477 | // require to assign fixed registers for the inputs of this |
| 5478 | // HInstanceOf instruction (following the runtime calling |
| 5479 | // convention), which might be cluttered by the potential first |
| 5480 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5481 | // |
| 5482 | // TODO: Introduce a new runtime entry point taking the object |
| 5483 | // to test (instead of its class) as argument, and let it deal |
| 5484 | // with the read barrier issues. This will let us refactor this |
| 5485 | // case of the `switch` code as it was previously (with a direct |
| 5486 | // call to the runtime not using a type checking slow path). |
| 5487 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5488 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5489 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5490 | /* is_fatal */ false); |
| 5491 | codegen_->AddSlowPath(slow_path); |
| 5492 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5493 | if (zero.IsLinked()) { |
| 5494 | __ b(&done); |
| 5495 | } |
| 5496 | break; |
| 5497 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5498 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5500 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5501 | __ Bind(&zero); |
| 5502 | __ LoadImmediate(out, 0); |
| 5503 | } |
| 5504 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5505 | if (done.IsLinked()) { |
| 5506 | __ Bind(&done); |
| 5507 | } |
| 5508 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5509 | if (slow_path != nullptr) { |
| 5510 | __ Bind(slow_path->GetExitLabel()); |
| 5511 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5512 | } |
| 5513 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5514 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5515 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5516 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5517 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5518 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5519 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5520 | case TypeCheckKind::kExactCheck: |
| 5521 | case TypeCheckKind::kAbstractClassCheck: |
| 5522 | case TypeCheckKind::kClassHierarchyCheck: |
| 5523 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5524 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5525 | LocationSummary::kCallOnSlowPath : |
| 5526 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5527 | break; |
| 5528 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5529 | case TypeCheckKind::kUnresolvedCheck: |
| 5530 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5531 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5532 | break; |
| 5533 | } |
| 5534 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5535 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5537 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5538 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5539 | locations->AddTemp(Location::RequiresRegister()); |
| 5540 | // When read barriers are enabled, we need an additional temporary |
| 5541 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5542 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5543 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5544 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5548 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5549 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5550 | Location obj_loc = locations->InAt(0); |
| 5551 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5552 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5553 | Location temp_loc = locations->GetTemp(0); |
| 5554 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5555 | Location temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5556 | locations->GetTemp(1) : |
| 5557 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5558 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5559 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5560 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5561 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5562 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5563 | bool is_type_check_slow_path_fatal = |
| 5564 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5565 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5566 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5567 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5568 | !instruction->CanThrowIntoCatchBlock(); |
| 5569 | SlowPathCode* type_check_slow_path = |
| 5570 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5571 | is_type_check_slow_path_fatal); |
| 5572 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5573 | |
| 5574 | Label done; |
| 5575 | // Avoid null check if we know obj is not null. |
| 5576 | if (instruction->MustDoNullCheck()) { |
| 5577 | __ CompareAndBranchIfZero(obj, &done); |
| 5578 | } |
| 5579 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5580 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5581 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5582 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5583 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5584 | case TypeCheckKind::kExactCheck: |
| 5585 | case TypeCheckKind::kArrayCheck: { |
| 5586 | __ cmp(temp, ShifterOperand(cls)); |
| 5587 | // Jump to slow path for throwing the exception or doing a |
| 5588 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5589 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5590 | break; |
| 5591 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5592 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5593 | case TypeCheckKind::kAbstractClassCheck: { |
| 5594 | // If the class is abstract, we eagerly fetch the super class of the |
| 5595 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5596 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5597 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5598 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5599 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5600 | |
| 5601 | // If the class reference currently in `temp` is not null, jump |
| 5602 | // to the `compare_classes` label to compare it with the checked |
| 5603 | // class. |
| 5604 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5605 | // Otherwise, jump to the slow path to throw the exception. |
| 5606 | // |
| 5607 | // But before, move back the object's class into `temp` before |
| 5608 | // going into the slow path, as it has been overwritten in the |
| 5609 | // meantime. |
| 5610 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5611 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5612 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5613 | |
| 5614 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5615 | __ cmp(temp, ShifterOperand(cls)); |
| 5616 | __ b(&loop, NE); |
| 5617 | break; |
| 5618 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5619 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5620 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5621 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5622 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5623 | __ Bind(&loop); |
| 5624 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5625 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5626 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5627 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5628 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5629 | |
| 5630 | // If the class reference currently in `temp` is not null, jump |
| 5631 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5632 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5633 | // Otherwise, jump to the slow path to throw the exception. |
| 5634 | // |
| 5635 | // But before, move back the object's class into `temp` before |
| 5636 | // going into the slow path, as it has been overwritten in the |
| 5637 | // meantime. |
| 5638 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5639 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5640 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5641 | break; |
| 5642 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5643 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5644 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5645 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5646 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5647 | __ cmp(temp, ShifterOperand(cls)); |
| 5648 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5649 | |
| 5650 | // 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] | 5651 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5652 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5653 | |
| 5654 | // If the component type is not null (i.e. the object is indeed |
| 5655 | // an array), jump to label `check_non_primitive_component_type` |
| 5656 | // to further check that this component type is not a primitive |
| 5657 | // type. |
| 5658 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 5659 | // Otherwise, jump to the slow path to throw the exception. |
| 5660 | // |
| 5661 | // But before, move back the object's class into `temp` before |
| 5662 | // going into the slow path, as it has been overwritten in the |
| 5663 | // meantime. |
| 5664 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5665 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5666 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5667 | |
| 5668 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5669 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5670 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 5671 | __ CompareAndBranchIfZero(temp, &done); |
| 5672 | // Same comment as above regarding `temp` and the slow path. |
| 5673 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5674 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5675 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5676 | break; |
| 5677 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5678 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5679 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5680 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5681 | // We always go into the type check slow path for the unresolved & |
| 5682 | // interface check cases. |
| 5683 | // |
| 5684 | // We cannot directly call the CheckCast runtime entry point |
| 5685 | // without resorting to a type checking slow path here (i.e. by |
| 5686 | // calling InvokeRuntime directly), as it would require to |
| 5687 | // assign fixed registers for the inputs of this HInstanceOf |
| 5688 | // instruction (following the runtime calling convention), which |
| 5689 | // might be cluttered by the potential first read barrier |
| 5690 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5691 | // |
| 5692 | // TODO: Introduce a new runtime entry point taking the object |
| 5693 | // to test (instead of its class) as argument, and let it deal |
| 5694 | // with the read barrier issues. This will let us refactor this |
| 5695 | // case of the `switch` code as it was previously (with a direct |
| 5696 | // call to the runtime not using a type checking slow path). |
| 5697 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5698 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5699 | break; |
| 5700 | } |
| 5701 | __ Bind(&done); |
| 5702 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5703 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5706 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5707 | LocationSummary* locations = |
| 5708 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5709 | InvokeRuntimeCallingConvention calling_convention; |
| 5710 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5711 | } |
| 5712 | |
| 5713 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5714 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 5715 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 5716 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5717 | instruction->GetDexPc(), |
| 5718 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5719 | if (instruction->IsEnter()) { |
| 5720 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5721 | } else { |
| 5722 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5723 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5724 | } |
| 5725 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5726 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 5727 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 5728 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5729 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5730 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5731 | LocationSummary* locations = |
| 5732 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5733 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5734 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5735 | // 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] | 5736 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5737 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5738 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 5742 | HandleBitwiseOperation(instruction); |
| 5743 | } |
| 5744 | |
| 5745 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 5746 | HandleBitwiseOperation(instruction); |
| 5747 | } |
| 5748 | |
| 5749 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 5750 | HandleBitwiseOperation(instruction); |
| 5751 | } |
| 5752 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5753 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 5754 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 5755 | if (value == 0xffffffffu) { |
| 5756 | if (out != first) { |
| 5757 | __ mov(out, ShifterOperand(first)); |
| 5758 | } |
| 5759 | return; |
| 5760 | } |
| 5761 | if (value == 0u) { |
| 5762 | __ mov(out, ShifterOperand(0)); |
| 5763 | return; |
| 5764 | } |
| 5765 | ShifterOperand so; |
| 5766 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 5767 | __ and_(out, first, so); |
| 5768 | } else { |
| 5769 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 5770 | __ bic(out, first, ShifterOperand(~value)); |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 5775 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 5776 | if (value == 0u) { |
| 5777 | if (out != first) { |
| 5778 | __ mov(out, ShifterOperand(first)); |
| 5779 | } |
| 5780 | return; |
| 5781 | } |
| 5782 | if (value == 0xffffffffu) { |
| 5783 | __ mvn(out, ShifterOperand(0)); |
| 5784 | return; |
| 5785 | } |
| 5786 | ShifterOperand so; |
| 5787 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 5788 | __ orr(out, first, so); |
| 5789 | } else { |
| 5790 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 5791 | __ orn(out, first, ShifterOperand(~value)); |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 5796 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 5797 | if (value == 0u) { |
| 5798 | if (out != first) { |
| 5799 | __ mov(out, ShifterOperand(first)); |
| 5800 | } |
| 5801 | return; |
| 5802 | } |
| 5803 | __ eor(out, first, ShifterOperand(value)); |
| 5804 | } |
| 5805 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5806 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5807 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5808 | Location first = locations->InAt(0); |
| 5809 | Location second = locations->InAt(1); |
| 5810 | Location out = locations->Out(); |
| 5811 | |
| 5812 | if (second.IsConstant()) { |
| 5813 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 5814 | uint32_t value_low = Low32Bits(value); |
| 5815 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5816 | Register first_reg = first.AsRegister<Register>(); |
| 5817 | Register out_reg = out.AsRegister<Register>(); |
| 5818 | if (instruction->IsAnd()) { |
| 5819 | GenerateAndConst(out_reg, first_reg, value_low); |
| 5820 | } else if (instruction->IsOr()) { |
| 5821 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 5822 | } else { |
| 5823 | DCHECK(instruction->IsXor()); |
| 5824 | GenerateEorConst(out_reg, first_reg, value_low); |
| 5825 | } |
| 5826 | } else { |
| 5827 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5828 | uint32_t value_high = High32Bits(value); |
| 5829 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5830 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5831 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5832 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5833 | if (instruction->IsAnd()) { |
| 5834 | GenerateAndConst(out_low, first_low, value_low); |
| 5835 | GenerateAndConst(out_high, first_high, value_high); |
| 5836 | } else if (instruction->IsOr()) { |
| 5837 | GenerateOrrConst(out_low, first_low, value_low); |
| 5838 | GenerateOrrConst(out_high, first_high, value_high); |
| 5839 | } else { |
| 5840 | DCHECK(instruction->IsXor()); |
| 5841 | GenerateEorConst(out_low, first_low, value_low); |
| 5842 | GenerateEorConst(out_high, first_high, value_high); |
| 5843 | } |
| 5844 | } |
| 5845 | return; |
| 5846 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5847 | |
| 5848 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5849 | Register first_reg = first.AsRegister<Register>(); |
| 5850 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 5851 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5852 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5853 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5854 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5855 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5856 | } else { |
| 5857 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5858 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5859 | } |
| 5860 | } else { |
| 5861 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5862 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5863 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5864 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 5865 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 5866 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5867 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5868 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5869 | __ and_(out_low, first_low, second_low); |
| 5870 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5871 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5872 | __ orr(out_low, first_low, second_low); |
| 5873 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5874 | } else { |
| 5875 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5876 | __ eor(out_low, first_low, second_low); |
| 5877 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5878 | } |
| 5879 | } |
| 5880 | } |
| 5881 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5882 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 5883 | Location out, |
| 5884 | uint32_t offset, |
| 5885 | Location temp) { |
| 5886 | Register out_reg = out.AsRegister<Register>(); |
| 5887 | if (kEmitCompilerReadBarrier) { |
| 5888 | if (kUseBakerReadBarrier) { |
| 5889 | // Load with fast path based Baker's read barrier. |
| 5890 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5891 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5892 | instruction, out, out_reg, offset, temp, /* needs_null_check */ false); |
| 5893 | } else { |
| 5894 | // Load with slow path based read barrier. |
| 5895 | // Save the value of `out` into `temp` before overwriting it |
| 5896 | // in the following move operation, as we will need it for the |
| 5897 | // read barrier below. |
| 5898 | __ Mov(temp.AsRegister<Register>(), out_reg); |
| 5899 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5900 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 5901 | codegen_->GenerateReadBarrierSlow(instruction, out, out, temp, offset); |
| 5902 | } |
| 5903 | } else { |
| 5904 | // Plain load with no read barrier. |
| 5905 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5906 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 5907 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 5912 | Location out, |
| 5913 | Location obj, |
| 5914 | uint32_t offset, |
| 5915 | Location temp) { |
| 5916 | Register out_reg = out.AsRegister<Register>(); |
| 5917 | Register obj_reg = obj.AsRegister<Register>(); |
| 5918 | if (kEmitCompilerReadBarrier) { |
| 5919 | if (kUseBakerReadBarrier) { |
| 5920 | // Load with fast path based Baker's read barrier. |
| 5921 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5922 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5923 | instruction, out, obj_reg, offset, temp, /* needs_null_check */ false); |
| 5924 | } else { |
| 5925 | // Load with slow path based read barrier. |
| 5926 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5927 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 5928 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5929 | } |
| 5930 | } else { |
| 5931 | // Plain load with no read barrier. |
| 5932 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5933 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 5934 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5935 | } |
| 5936 | } |
| 5937 | |
| 5938 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5939 | Location root, |
| 5940 | Register obj, |
| 5941 | uint32_t offset) { |
| 5942 | Register root_reg = root.AsRegister<Register>(); |
| 5943 | if (kEmitCompilerReadBarrier) { |
| 5944 | if (kUseBakerReadBarrier) { |
| 5945 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5946 | // Baker's read barrier are used: |
| 5947 | // |
| 5948 | // root = obj.field; |
| 5949 | // if (Thread::Current()->GetIsGcMarking()) { |
| 5950 | // root = ReadBarrier::Mark(root) |
| 5951 | // } |
| 5952 | |
| 5953 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5954 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 5955 | static_assert( |
| 5956 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5957 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5958 | "have different sizes."); |
| 5959 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5960 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5961 | "have different sizes."); |
| 5962 | |
| 5963 | // Slow path used to mark the GC root `root`. |
| 5964 | SlowPathCode* slow_path = |
| 5965 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root, root); |
| 5966 | codegen_->AddSlowPath(slow_path); |
| 5967 | |
| 5968 | __ LoadFromOffset( |
| 5969 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmWordSize>().Int32Value()); |
| 5970 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 5971 | __ Bind(slow_path->GetExitLabel()); |
| 5972 | } else { |
| 5973 | // GC root loaded through a slow path for read barriers other |
| 5974 | // than Baker's. |
| 5975 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 5976 | __ AddConstant(root_reg, obj, offset); |
| 5977 | // /* mirror::Object* */ root = root->Read() |
| 5978 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5979 | } |
| 5980 | } else { |
| 5981 | // Plain GC root load with no read barrier. |
| 5982 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5983 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 5984 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5985 | // do not have to unpoison `root_reg` here. |
| 5986 | } |
| 5987 | } |
| 5988 | |
| 5989 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5990 | Location ref, |
| 5991 | Register obj, |
| 5992 | uint32_t offset, |
| 5993 | Location temp, |
| 5994 | bool needs_null_check) { |
| 5995 | DCHECK(kEmitCompilerReadBarrier); |
| 5996 | DCHECK(kUseBakerReadBarrier); |
| 5997 | |
| 5998 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5999 | Location no_index = Location::NoLocation(); |
| 6000 | GenerateReferenceLoadWithBakerReadBarrier( |
| 6001 | instruction, ref, obj, offset, no_index, temp, needs_null_check); |
| 6002 | } |
| 6003 | |
| 6004 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6005 | Location ref, |
| 6006 | Register obj, |
| 6007 | uint32_t data_offset, |
| 6008 | Location index, |
| 6009 | Location temp, |
| 6010 | bool needs_null_check) { |
| 6011 | DCHECK(kEmitCompilerReadBarrier); |
| 6012 | DCHECK(kUseBakerReadBarrier); |
| 6013 | |
| 6014 | // /* HeapReference<Object> */ ref = |
| 6015 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6016 | GenerateReferenceLoadWithBakerReadBarrier( |
| 6017 | instruction, ref, obj, data_offset, index, temp, needs_null_check); |
| 6018 | } |
| 6019 | |
| 6020 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6021 | Location ref, |
| 6022 | Register obj, |
| 6023 | uint32_t offset, |
| 6024 | Location index, |
| 6025 | Location temp, |
| 6026 | bool needs_null_check) { |
| 6027 | DCHECK(kEmitCompilerReadBarrier); |
| 6028 | DCHECK(kUseBakerReadBarrier); |
| 6029 | |
| 6030 | // In slow path based read barriers, the read barrier call is |
| 6031 | // inserted after the original load. However, in fast path based |
| 6032 | // Baker's read barriers, we need to perform the load of |
| 6033 | // mirror::Object::monitor_ *before* the original reference load. |
| 6034 | // This load-load ordering is required by the read barrier. |
| 6035 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6036 | // |
| 6037 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6038 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6039 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6040 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6041 | // if (is_gray) { |
| 6042 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6043 | // } |
| 6044 | // |
| 6045 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6046 | // slightly more complex as: |
| 6047 | // - it implements the load-load fence using a data dependency on |
| 6048 | // the high-bits of rb_state, which are expected to be all zeroes; |
| 6049 | // - it performs additional checks that we do not do here for |
| 6050 | // performance reasons. |
| 6051 | |
| 6052 | Register ref_reg = ref.AsRegister<Register>(); |
| 6053 | Register temp_reg = temp.AsRegister<Register>(); |
| 6054 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6055 | |
| 6056 | // /* int32_t */ monitor = obj->monitor_ |
| 6057 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6058 | if (needs_null_check) { |
| 6059 | MaybeRecordImplicitNullCheck(instruction); |
| 6060 | } |
| 6061 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6062 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6063 | "art::LockWord and int32_t have different sizes."); |
| 6064 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6065 | __ Lsr(temp_reg, temp_reg, LockWord::kReadBarrierStateShift); |
| 6066 | __ and_(temp_reg, temp_reg, ShifterOperand(LockWord::kReadBarrierStateMask)); |
| 6067 | static_assert( |
| 6068 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6069 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6070 | |
| 6071 | // Introduce a dependency on the high bits of rb_state, which shall |
| 6072 | // be all zeroes, to prevent load-load reordering, and without using |
| 6073 | // a memory barrier (which would be more expensive). |
| 6074 | // IP = rb_state & ~LockWord::kReadBarrierStateMask = 0 |
| 6075 | __ bic(IP, temp_reg, ShifterOperand(LockWord::kReadBarrierStateMask)); |
| 6076 | // obj is unchanged by this operation, but its value now depends on |
| 6077 | // IP, which depends on temp_reg. |
| 6078 | __ add(obj, obj, ShifterOperand(IP)); |
| 6079 | |
| 6080 | // The actual reference load. |
| 6081 | if (index.IsValid()) { |
| 6082 | static_assert( |
| 6083 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6084 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6085 | // /* HeapReference<Object> */ ref = |
| 6086 | // *(obj + offset + index * sizeof(HeapReference<Object>)) |
| 6087 | if (index.IsConstant()) { |
| 6088 | size_t computed_offset = |
| 6089 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset; |
| 6090 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6091 | } else { |
| 6092 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 6093 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6094 | } |
| 6095 | } else { |
| 6096 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6097 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6098 | } |
| 6099 | |
| 6100 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6101 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6102 | |
| 6103 | // Slow path used to mark the object `ref` when it is gray. |
| 6104 | SlowPathCode* slow_path = |
| 6105 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref, ref); |
| 6106 | AddSlowPath(slow_path); |
| 6107 | |
| 6108 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6109 | // ref = ReadBarrier::Mark(ref); |
| 6110 | __ cmp(temp_reg, ShifterOperand(ReadBarrier::gray_ptr_)); |
| 6111 | __ b(slow_path->GetEntryLabel(), EQ); |
| 6112 | __ Bind(slow_path->GetExitLabel()); |
| 6113 | } |
| 6114 | |
| 6115 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6116 | Location out, |
| 6117 | Location ref, |
| 6118 | Location obj, |
| 6119 | uint32_t offset, |
| 6120 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6121 | DCHECK(kEmitCompilerReadBarrier); |
| 6122 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6123 | // Insert a slow path based read barrier *after* the reference load. |
| 6124 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6125 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6126 | // reference will be carried out by the runtime within the slow |
| 6127 | // path. |
| 6128 | // |
| 6129 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6130 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6131 | // not used by the artReadBarrierSlow entry point. |
| 6132 | // |
| 6133 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6134 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6135 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6136 | AddSlowPath(slow_path); |
| 6137 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6138 | __ b(slow_path->GetEntryLabel()); |
| 6139 | __ Bind(slow_path->GetExitLabel()); |
| 6140 | } |
| 6141 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6142 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6143 | Location out, |
| 6144 | Location ref, |
| 6145 | Location obj, |
| 6146 | uint32_t offset, |
| 6147 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6148 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6149 | // Baker's read barriers shall be handled by the fast path |
| 6150 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6151 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6152 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6153 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6154 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6155 | } else if (kPoisonHeapReferences) { |
| 6156 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6157 | } |
| 6158 | } |
| 6159 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6160 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6161 | Location out, |
| 6162 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6163 | DCHECK(kEmitCompilerReadBarrier); |
| 6164 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6165 | // Insert a slow path based read barrier *after* the GC root load. |
| 6166 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6167 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6168 | // not need to do anything special for this here. |
| 6169 | SlowPathCode* slow_path = |
| 6170 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6171 | AddSlowPath(slow_path); |
| 6172 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6173 | __ b(slow_path->GetEntryLabel()); |
| 6174 | __ Bind(slow_path->GetExitLabel()); |
| 6175 | } |
| 6176 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6177 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6178 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6179 | MethodReference target_method) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6180 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6181 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6182 | // is incompatible with it. |
| 6183 | if (GetGraph()->HasIrreducibleLoops() && |
| 6184 | (dispatch_info.method_load_kind == |
| 6185 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6186 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6187 | } |
| 6188 | |
| 6189 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6190 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6191 | if (&outer_dex_file != target_method.dex_file) { |
| 6192 | // Calls across dex files are more likely to exceed the available BL range, |
| 6193 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6194 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6195 | (desired_dispatch_info.method_load_kind == |
| 6196 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6197 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6198 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6199 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6200 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6201 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6202 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6203 | 0u |
| 6204 | }; |
| 6205 | } |
| 6206 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6207 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6208 | } |
| 6209 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6210 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6211 | Register temp) { |
| 6212 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6213 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6214 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6215 | return location.AsRegister<Register>(); |
| 6216 | } |
| 6217 | // For intrinsics we allow any location, so it may be on the stack. |
| 6218 | if (!location.IsRegister()) { |
| 6219 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6220 | return temp; |
| 6221 | } |
| 6222 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6223 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6224 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6225 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6226 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6227 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6228 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6229 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6230 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6231 | return temp; |
| 6232 | } |
| 6233 | return location.AsRegister<Register>(); |
| 6234 | } |
| 6235 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6236 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6237 | // 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] | 6238 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6239 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6240 | // LR = code address from literal pool with link-time patch. |
| 6241 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6242 | break; |
| 6243 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6244 | // LR = invoke->GetDirectCodePtr(); |
| 6245 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6246 | break; |
| 6247 | default: |
| 6248 | break; |
| 6249 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6250 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6251 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6252 | switch (invoke->GetMethodLoadKind()) { |
| 6253 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6254 | // temp = thread->string_init_entrypoint |
| 6255 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6256 | break; |
| 6257 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6258 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6259 | break; |
| 6260 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6261 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6262 | break; |
| 6263 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6264 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6265 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6266 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6267 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6268 | HArmDexCacheArraysBase* base = |
| 6269 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6270 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6271 | temp.AsRegister<Register>()); |
| 6272 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6273 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6274 | break; |
| 6275 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6276 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6277 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6278 | Register method_reg; |
| 6279 | Register reg = temp.AsRegister<Register>(); |
| 6280 | if (current_method.IsRegister()) { |
| 6281 | method_reg = current_method.AsRegister<Register>(); |
| 6282 | } else { |
| 6283 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6284 | DCHECK(!current_method.IsValid()); |
| 6285 | method_reg = reg; |
| 6286 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6287 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6288 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6289 | __ LoadFromOffset(kLoadWord, |
| 6290 | reg, |
| 6291 | method_reg, |
| 6292 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6293 | // temp = temp[index_in_cache] |
| 6294 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 6295 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6296 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6297 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | switch (invoke->GetCodePtrLocation()) { |
| 6301 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6302 | __ bl(GetFrameEntryLabel()); |
| 6303 | break; |
| 6304 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6305 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6306 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6307 | // Arbitrarily branch to the BL itself, override at link time. |
| 6308 | __ bl(&relative_call_patches_.back().label); |
| 6309 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6310 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6311 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6312 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6313 | // LR() |
| 6314 | __ blx(LR); |
| 6315 | break; |
| 6316 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6317 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6318 | __ LoadFromOffset( |
| 6319 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 6320 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 6321 | // LR() |
| 6322 | __ blx(LR); |
| 6323 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6324 | } |
| 6325 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6326 | DCHECK(!IsLeafMethod()); |
| 6327 | } |
| 6328 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6329 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6330 | Register temp = temp_location.AsRegister<Register>(); |
| 6331 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6332 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6333 | |
| 6334 | // Use the calling convention instead of the location of the receiver, as |
| 6335 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6336 | // slow path, the arguments have been moved to the right place, so here we are |
| 6337 | // guaranteed that the receiver is the first register of the calling convention. |
| 6338 | InvokeDexCallingConvention calling_convention; |
| 6339 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6340 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6341 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6342 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6343 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6344 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6345 | // emit a read barrier for the previous class reference load. |
| 6346 | // However this is not required in practice, as this is an |
| 6347 | // intermediate/temporary reference and because the current |
| 6348 | // concurrent copying collector keeps the from-space memory |
| 6349 | // intact/accessible until the end of the marking phase (the |
| 6350 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6351 | __ MaybeUnpoisonHeapReference(temp); |
| 6352 | // temp = temp->GetMethodAt(method_offset); |
| 6353 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 6354 | kArmWordSize).Int32Value(); |
| 6355 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6356 | // LR = temp->GetEntryPoint(); |
| 6357 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6358 | // LR(); |
| 6359 | __ blx(LR); |
| 6360 | } |
| 6361 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6362 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6363 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6364 | size_t size = |
| 6365 | method_patches_.size() + |
| 6366 | call_patches_.size() + |
| 6367 | relative_call_patches_.size() + |
| 6368 | /* MOVW+MOVT for each base */ 2u * dex_cache_arrays_base_labels_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6369 | linker_patches->reserve(size); |
| 6370 | for (const auto& entry : method_patches_) { |
| 6371 | const MethodReference& target_method = entry.first; |
| 6372 | Literal* literal = entry.second; |
| 6373 | DCHECK(literal->GetLabel()->IsBound()); |
| 6374 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6375 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6376 | target_method.dex_file, |
| 6377 | target_method.dex_method_index)); |
| 6378 | } |
| 6379 | for (const auto& entry : call_patches_) { |
| 6380 | const MethodReference& target_method = entry.first; |
| 6381 | Literal* literal = entry.second; |
| 6382 | DCHECK(literal->GetLabel()->IsBound()); |
| 6383 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6384 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6385 | target_method.dex_file, |
| 6386 | target_method.dex_method_index)); |
| 6387 | } |
| 6388 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6389 | uint32_t literal_offset = info.label.Position(); |
| 6390 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6391 | info.target_method.dex_file, |
| 6392 | info.target_method.dex_method_index)); |
| 6393 | } |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6394 | for (const auto& pair : dex_cache_arrays_base_labels_) { |
| 6395 | HArmDexCacheArraysBase* base = pair.first; |
| 6396 | const DexCacheArraysBaseLabels* labels = &pair.second; |
| 6397 | const DexFile& dex_file = base->GetDexFile(); |
| 6398 | size_t base_element_offset = base->GetElementOffset(); |
| 6399 | DCHECK(labels->add_pc_label.IsBound()); |
| 6400 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(labels->add_pc_label.Position()); |
| 6401 | // Add MOVW patch. |
| 6402 | DCHECK(labels->movw_label.IsBound()); |
| 6403 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(labels->movw_label.Position()); |
| 6404 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6405 | &dex_file, |
| 6406 | add_pc_offset, |
| 6407 | base_element_offset)); |
| 6408 | // Add MOVT patch. |
| 6409 | DCHECK(labels->movt_label.IsBound()); |
| 6410 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(labels->movt_label.Position()); |
| 6411 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6412 | &dex_file, |
| 6413 | add_pc_offset, |
| 6414 | base_element_offset)); |
| 6415 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6416 | } |
| 6417 | |
| 6418 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 6419 | MethodToLiteralMap* map) { |
| 6420 | // Look up the literal for target_method. |
| 6421 | auto lb = map->lower_bound(target_method); |
| 6422 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 6423 | return lb->second; |
| 6424 | } |
| 6425 | // We don't have a literal for this method yet, insert a new one. |
| 6426 | Literal* literal = __ NewLiteral<uint32_t>(0u); |
| 6427 | map->PutBefore(lb, target_method, literal); |
| 6428 | return literal; |
| 6429 | } |
| 6430 | |
| 6431 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 6432 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 6433 | } |
| 6434 | |
| 6435 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 6436 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 6437 | } |
| 6438 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6439 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6440 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6441 | LOG(FATAL) << "Unreachable"; |
| 6442 | } |
| 6443 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6444 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6445 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6446 | LOG(FATAL) << "Unreachable"; |
| 6447 | } |
| 6448 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6449 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6450 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6451 | LocationSummary* locations = |
| 6452 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6453 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6454 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6455 | codegen_->GetAssembler()->IsThumb()) { |
| 6456 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 6457 | if (switch_instr->GetStartValue() != 0) { |
| 6458 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 6459 | } |
| 6460 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6461 | } |
| 6462 | |
| 6463 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6464 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6465 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6466 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6467 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6468 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6469 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6470 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6471 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6472 | Register temp_reg = IP; |
| 6473 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 6474 | // the immediate, because IP is used as the destination register. For the other |
| 6475 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 6476 | // and they can be encoded in the instruction without making use of IP register. |
| 6477 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 6478 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6479 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6480 | // Jump to successors[0] if value == lower_bound. |
| 6481 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 6482 | int32_t last_index = 0; |
| 6483 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6484 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 6485 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6486 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 6487 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6488 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 6489 | } |
| 6490 | if (num_entries - last_index == 2) { |
| 6491 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 6492 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6493 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6494 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6495 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6496 | // And the default for any other value. |
| 6497 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6498 | __ b(codegen_->GetLabelOf(default_block)); |
| 6499 | } |
| 6500 | } else { |
| 6501 | // Create a table lookup. |
| 6502 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6503 | |
| 6504 | // Materialize a pointer to the switch table |
| 6505 | std::vector<Label*> labels(num_entries); |
| 6506 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6507 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6508 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6509 | } |
| 6510 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 6511 | |
| 6512 | // Remove the bias. |
| 6513 | Register key_reg; |
| 6514 | if (lower_bound != 0) { |
| 6515 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 6516 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 6517 | } else { |
| 6518 | key_reg = value_reg; |
| 6519 | } |
| 6520 | |
| 6521 | // Check whether the value is in the table, jump to default block if not. |
| 6522 | __ CmpConstant(key_reg, num_entries - 1); |
| 6523 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 6524 | |
| 6525 | // Load the displacement from the table. |
| 6526 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 6527 | |
| 6528 | // Dispatch is a direct add to the PC (for Thumb2). |
| 6529 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6530 | } |
| 6531 | } |
| 6532 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6533 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6534 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6535 | locations->SetOut(Location::RequiresRegister()); |
| 6536 | codegen_->AddDexCacheArraysBase(base); |
| 6537 | } |
| 6538 | |
| 6539 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6540 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 6541 | CodeGeneratorARM::DexCacheArraysBaseLabels* labels = codegen_->GetDexCacheArraysBaseLabels(base); |
| 6542 | __ BindTrackedLabel(&labels->movw_label); |
| 6543 | __ movw(base_reg, 0u); |
| 6544 | __ BindTrackedLabel(&labels->movt_label); |
| 6545 | __ movt(base_reg, 0u); |
| 6546 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6547 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 6548 | } |
| 6549 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6550 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6551 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6552 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6553 | return; |
| 6554 | } |
| 6555 | |
| 6556 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6557 | |
| 6558 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 6559 | if (return_loc.Equals(trg)) { |
| 6560 | return; |
| 6561 | } |
| 6562 | |
| 6563 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 6564 | // with the last branch. |
| 6565 | if (type == Primitive::kPrimLong) { |
| 6566 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6567 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 6568 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 6569 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6570 | } else if (type == Primitive::kPrimDouble) { |
| 6571 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6572 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 6573 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 6574 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6575 | } else { |
| 6576 | // Let the parallel move resolver take care of all of this. |
| 6577 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6578 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6579 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6580 | } |
| 6581 | } |
| 6582 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6583 | #undef __ |
| 6584 | #undef QUICK_ENTRY_POINT |
| 6585 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6586 | } // namespace arm |
| 6587 | } // namespace art |