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 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 50 | // We unconditionally allocate R5 to ensure we can do long operations |
| 51 | // with baseline. |
| 52 | static constexpr Register kCoreSavedRegisterForBaseline = R5; |
| 53 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 54 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 55 | static constexpr SRegister kFpuCalleeSaves[] = |
| 56 | { 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] | 57 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 58 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 59 | // S registers. Therefore there is no need to block it. |
| 60 | static constexpr DRegister DTMP = D31; |
| 61 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 62 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 63 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 64 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 65 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 67 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 69 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 71 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 72 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 74 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 75 | // Live registers will be restored in the catch block if caught. |
| 76 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 77 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 78 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 79 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 80 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 83 | bool IsFatal() const OVERRIDE { return true; } |
| 84 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 85 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 86 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 87 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 88 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 89 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 90 | }; |
| 91 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 92 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | public: |
| 94 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 95 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 96 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 98 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 99 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 100 | // Live registers will be restored in the catch block if caught. |
| 101 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 102 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 104 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 105 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 108 | bool IsFatal() const OVERRIDE { return true; } |
| 109 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 110 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 111 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | private: |
| 113 | HDivZeroCheck* const instruction_; |
| 114 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 115 | }; |
| 116 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 117 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 118 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 119 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 120 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 121 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 122 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 123 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 124 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 125 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 126 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 127 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 128 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 129 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 130 | if (successor_ == nullptr) { |
| 131 | __ b(GetReturnLabel()); |
| 132 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 133 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 137 | Label* GetReturnLabel() { |
| 138 | DCHECK(successor_ == nullptr); |
| 139 | return &return_label_; |
| 140 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 141 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 142 | HBasicBlock* GetSuccessor() const { |
| 143 | return successor_; |
| 144 | } |
| 145 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 146 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 147 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | private: |
| 149 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 150 | // If not null, the block to branch to after the suspend check. |
| 151 | HBasicBlock* const successor_; |
| 152 | |
| 153 | // 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] | 154 | Label return_label_; |
| 155 | |
| 156 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 157 | }; |
| 158 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 159 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 161 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
| 162 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 163 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 164 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 165 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 166 | LocationSummary* locations = instruction_->GetLocations(); |
| 167 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 168 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 169 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 170 | // Live registers will be restored in the catch block if caught. |
| 171 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 172 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 173 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 174 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 175 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 176 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 177 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 178 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 179 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 180 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 181 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 182 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 183 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 184 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 185 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 188 | bool IsFatal() const OVERRIDE { return true; } |
| 189 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 190 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 191 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 193 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | |
| 195 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 196 | }; |
| 197 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 198 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 199 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 200 | LoadClassSlowPathARM(HLoadClass* cls, |
| 201 | HInstruction* at, |
| 202 | uint32_t dex_pc, |
| 203 | bool do_clinit) |
| 204 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 205 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 206 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 207 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 208 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | LocationSummary* locations = at_->GetLocations(); |
| 210 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 211 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 212 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 213 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 214 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 215 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 216 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 217 | int32_t entry_point_offset = do_clinit_ |
| 218 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 219 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 220 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 221 | if (do_clinit_) { |
| 222 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 223 | } else { |
| 224 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 225 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 226 | |
| 227 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 228 | Location out = locations->Out(); |
| 229 | if (out.IsValid()) { |
| 230 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 232 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 233 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 234 | __ b(GetExitLabel()); |
| 235 | } |
| 236 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 237 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 238 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 240 | // The class this slow path will load. |
| 241 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 242 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 243 | // The instruction where this slow path is happening. |
| 244 | // (Might be the load class or an initialization check). |
| 245 | HInstruction* const at_; |
| 246 | |
| 247 | // The dex PC of `at_`. |
| 248 | const uint32_t dex_pc_; |
| 249 | |
| 250 | // Whether to initialize the class. |
| 251 | const bool do_clinit_; |
| 252 | |
| 253 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 254 | }; |
| 255 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 256 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 257 | public: |
| 258 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 259 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 260 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 261 | LocationSummary* locations = instruction_->GetLocations(); |
| 262 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 263 | |
| 264 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 265 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 266 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | |
| 268 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 269 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 270 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 271 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 272 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 273 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 274 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 275 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 276 | __ b(GetExitLabel()); |
| 277 | } |
| 278 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 279 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 280 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 281 | private: |
| 282 | HLoadString* const instruction_; |
| 283 | |
| 284 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 285 | }; |
| 286 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 287 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 289 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
| 290 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 294 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 295 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 296 | DCHECK(instruction_->IsCheckCast() |
| 297 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 | |
| 299 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 300 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 301 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 302 | if (!is_fatal_) { |
| 303 | SaveLiveRegisters(codegen, locations); |
| 304 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | |
| 306 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 307 | // move resolver. |
| 308 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 309 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 310 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 311 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 312 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 313 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 314 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 315 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 317 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 318 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 319 | instruction_, |
| 320 | instruction_->GetDexPc(), |
| 321 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 322 | CheckEntrypointTypes< |
| 323 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 324 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 325 | } else { |
| 326 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 327 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 328 | instruction_, |
| 329 | instruction_->GetDexPc(), |
| 330 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 331 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 332 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | if (!is_fatal_) { |
| 335 | RestoreLiveRegisters(codegen, locations); |
| 336 | __ b(GetExitLabel()); |
| 337 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 340 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 341 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 342 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 343 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 344 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 345 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | |
| 348 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 349 | }; |
| 350 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 351 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 352 | public: |
| 353 | explicit DeoptimizationSlowPathARM(HInstruction* instruction) |
| 354 | : instruction_(instruction) {} |
| 355 | |
| 356 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 357 | __ Bind(GetEntryLabel()); |
| 358 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 359 | DCHECK(instruction_->IsDeoptimize()); |
| 360 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 361 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 362 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 363 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 364 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 368 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 369 | private: |
| 370 | HInstruction* const instruction_; |
| 371 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 372 | }; |
| 373 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 374 | class ArraySetSlowPathARM : public SlowPathCode { |
| 375 | public: |
| 376 | explicit ArraySetSlowPathARM(HInstruction* instruction) : instruction_(instruction) {} |
| 377 | |
| 378 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 379 | LocationSummary* locations = instruction_->GetLocations(); |
| 380 | __ Bind(GetEntryLabel()); |
| 381 | SaveLiveRegisters(codegen, locations); |
| 382 | |
| 383 | InvokeRuntimeCallingConvention calling_convention; |
| 384 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 385 | parallel_move.AddMove( |
| 386 | locations->InAt(0), |
| 387 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 388 | Primitive::kPrimNot, |
| 389 | nullptr); |
| 390 | parallel_move.AddMove( |
| 391 | locations->InAt(1), |
| 392 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 393 | Primitive::kPrimInt, |
| 394 | nullptr); |
| 395 | parallel_move.AddMove( |
| 396 | locations->InAt(2), |
| 397 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 398 | Primitive::kPrimNot, |
| 399 | nullptr); |
| 400 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 401 | |
| 402 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 403 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 404 | instruction_, |
| 405 | instruction_->GetDexPc(), |
| 406 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 407 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 408 | RestoreLiveRegisters(codegen, locations); |
| 409 | __ b(GetExitLabel()); |
| 410 | } |
| 411 | |
| 412 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 413 | |
| 414 | private: |
| 415 | HInstruction* const instruction_; |
| 416 | |
| 417 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 418 | }; |
| 419 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 420 | // Slow path marking an object during a read barrier. |
| 421 | class ReadBarrierMarkSlowPathARM : public SlowPathCode { |
| 422 | public: |
| 423 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location out, Location obj) |
| 424 | : instruction_(instruction), out_(out), obj_(obj) { |
| 425 | DCHECK(kEmitCompilerReadBarrier); |
| 426 | } |
| 427 | |
| 428 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 429 | |
| 430 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 431 | LocationSummary* locations = instruction_->GetLocations(); |
| 432 | Register reg_out = out_.AsRegister<Register>(); |
| 433 | DCHECK(locations->CanCall()); |
| 434 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 435 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 436 | instruction_->IsStaticFieldGet() || |
| 437 | instruction_->IsArrayGet() || |
| 438 | instruction_->IsLoadClass() || |
| 439 | instruction_->IsLoadString() || |
| 440 | instruction_->IsInstanceOf() || |
| 441 | instruction_->IsCheckCast()) |
| 442 | << "Unexpected instruction in read barrier marking slow path: " |
| 443 | << instruction_->DebugName(); |
| 444 | |
| 445 | __ Bind(GetEntryLabel()); |
| 446 | SaveLiveRegisters(codegen, locations); |
| 447 | |
| 448 | InvokeRuntimeCallingConvention calling_convention; |
| 449 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 450 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 451 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 452 | instruction_, |
| 453 | instruction_->GetDexPc(), |
| 454 | this); |
| 455 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 456 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 457 | |
| 458 | RestoreLiveRegisters(codegen, locations); |
| 459 | __ b(GetExitLabel()); |
| 460 | } |
| 461 | |
| 462 | private: |
| 463 | HInstruction* const instruction_; |
| 464 | const Location out_; |
| 465 | const Location obj_; |
| 466 | |
| 467 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 468 | }; |
| 469 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 470 | // Slow path generating a read barrier for a heap reference. |
| 471 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 472 | public: |
| 473 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 474 | Location out, |
| 475 | Location ref, |
| 476 | Location obj, |
| 477 | uint32_t offset, |
| 478 | Location index) |
| 479 | : instruction_(instruction), |
| 480 | out_(out), |
| 481 | ref_(ref), |
| 482 | obj_(obj), |
| 483 | offset_(offset), |
| 484 | index_(index) { |
| 485 | DCHECK(kEmitCompilerReadBarrier); |
| 486 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 487 | // has been overwritten by (or after) the heap object reference load |
| 488 | // to be instrumented, e.g.: |
| 489 | // |
| 490 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 491 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 492 | // |
| 493 | // In that case, we have lost the information about the original |
| 494 | // object, and the emitted read barrier cannot work properly. |
| 495 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 496 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 497 | } |
| 498 | |
| 499 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 500 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 501 | LocationSummary* locations = instruction_->GetLocations(); |
| 502 | Register reg_out = out_.AsRegister<Register>(); |
| 503 | DCHECK(locations->CanCall()); |
| 504 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 505 | DCHECK(!instruction_->IsInvoke() || |
| 506 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 507 | instruction_->GetLocations()->Intrinsified())) |
| 508 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 509 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 510 | |
| 511 | __ Bind(GetEntryLabel()); |
| 512 | SaveLiveRegisters(codegen, locations); |
| 513 | |
| 514 | // We may have to change the index's value, but as `index_` is a |
| 515 | // constant member (like other "inputs" of this slow path), |
| 516 | // introduce a copy of it, `index`. |
| 517 | Location index = index_; |
| 518 | if (index_.IsValid()) { |
| 519 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 520 | if (instruction_->IsArrayGet()) { |
| 521 | // Compute the actual memory offset and store it in `index`. |
| 522 | Register index_reg = index_.AsRegister<Register>(); |
| 523 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 524 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 525 | // We are about to change the value of `index_reg` (see the |
| 526 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 527 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 528 | // not been saved by the previous call to |
| 529 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 530 | // callee-save register -- |
| 531 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 532 | // callee-save registers, as it has been designed with the |
| 533 | // assumption that callee-save registers are supposed to be |
| 534 | // handled by the called function. So, as a callee-save |
| 535 | // register, `index_reg` _would_ eventually be saved onto |
| 536 | // the stack, but it would be too late: we would have |
| 537 | // changed its value earlier. Therefore, we manually save |
| 538 | // it here into another freely available register, |
| 539 | // `free_reg`, chosen of course among the caller-save |
| 540 | // registers (as a callee-save `free_reg` register would |
| 541 | // exhibit the same problem). |
| 542 | // |
| 543 | // Note we could have requested a temporary register from |
| 544 | // the register allocator instead; but we prefer not to, as |
| 545 | // this is a slow path, and we know we can find a |
| 546 | // caller-save register that is available. |
| 547 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 548 | __ Mov(free_reg, index_reg); |
| 549 | index_reg = free_reg; |
| 550 | index = Location::RegisterLocation(index_reg); |
| 551 | } else { |
| 552 | // The initial register stored in `index_` has already been |
| 553 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 554 | // (as it is not a callee-save register), so we can freely |
| 555 | // use it. |
| 556 | } |
| 557 | // Shifting the index value contained in `index_reg` by the scale |
| 558 | // factor (2) cannot overflow in practice, as the runtime is |
| 559 | // unable to allocate object arrays with a size larger than |
| 560 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 561 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 562 | static_assert( |
| 563 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 564 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 565 | __ AddConstant(index_reg, index_reg, offset_); |
| 566 | } else { |
| 567 | DCHECK(instruction_->IsInvoke()); |
| 568 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 569 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 570 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 571 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 572 | DCHECK_EQ(offset_, 0U); |
| 573 | DCHECK(index_.IsRegisterPair()); |
| 574 | // UnsafeGet's offset location is a register pair, the low |
| 575 | // part contains the correct offset. |
| 576 | index = index_.ToLow(); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // We're moving two or three locations to locations that could |
| 581 | // overlap, so we need a parallel move resolver. |
| 582 | InvokeRuntimeCallingConvention calling_convention; |
| 583 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 584 | parallel_move.AddMove(ref_, |
| 585 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 586 | Primitive::kPrimNot, |
| 587 | nullptr); |
| 588 | parallel_move.AddMove(obj_, |
| 589 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 590 | Primitive::kPrimNot, |
| 591 | nullptr); |
| 592 | if (index.IsValid()) { |
| 593 | parallel_move.AddMove(index, |
| 594 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 595 | Primitive::kPrimInt, |
| 596 | nullptr); |
| 597 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 598 | } else { |
| 599 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 600 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 601 | } |
| 602 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 603 | instruction_, |
| 604 | instruction_->GetDexPc(), |
| 605 | this); |
| 606 | CheckEntrypointTypes< |
| 607 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 608 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 609 | |
| 610 | RestoreLiveRegisters(codegen, locations); |
| 611 | __ b(GetExitLabel()); |
| 612 | } |
| 613 | |
| 614 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 615 | |
| 616 | private: |
| 617 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 618 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 619 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 620 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 621 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 622 | return static_cast<Register>(i); |
| 623 | } |
| 624 | } |
| 625 | // We shall never fail to find a free caller-save register, as |
| 626 | // there are more than two core caller-save registers on ARM |
| 627 | // (meaning it is possible to find one which is different from |
| 628 | // `ref` and `obj`). |
| 629 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 630 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 631 | UNREACHABLE(); |
| 632 | } |
| 633 | |
| 634 | HInstruction* const instruction_; |
| 635 | const Location out_; |
| 636 | const Location ref_; |
| 637 | const Location obj_; |
| 638 | const uint32_t offset_; |
| 639 | // An additional location containing an index to an array. |
| 640 | // Only used for HArrayGet and the UnsafeGetObject & |
| 641 | // UnsafeGetObjectVolatile intrinsics. |
| 642 | const Location index_; |
| 643 | |
| 644 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 645 | }; |
| 646 | |
| 647 | // Slow path generating a read barrier for a GC root. |
| 648 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 649 | public: |
| 650 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 651 | : instruction_(instruction), out_(out), root_(root) { |
| 652 | DCHECK(kEmitCompilerReadBarrier); |
| 653 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 654 | |
| 655 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 656 | LocationSummary* locations = instruction_->GetLocations(); |
| 657 | Register reg_out = out_.AsRegister<Register>(); |
| 658 | DCHECK(locations->CanCall()); |
| 659 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 660 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 661 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 662 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 663 | |
| 664 | __ Bind(GetEntryLabel()); |
| 665 | SaveLiveRegisters(codegen, locations); |
| 666 | |
| 667 | InvokeRuntimeCallingConvention calling_convention; |
| 668 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 669 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 670 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 671 | instruction_, |
| 672 | instruction_->GetDexPc(), |
| 673 | this); |
| 674 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 675 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 676 | |
| 677 | RestoreLiveRegisters(codegen, locations); |
| 678 | __ b(GetExitLabel()); |
| 679 | } |
| 680 | |
| 681 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 682 | |
| 683 | private: |
| 684 | HInstruction* const instruction_; |
| 685 | const Location out_; |
| 686 | const Location root_; |
| 687 | |
| 688 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 689 | }; |
| 690 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 691 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 692 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 693 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 694 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 695 | switch (cond) { |
| 696 | case kCondEQ: return EQ; |
| 697 | case kCondNE: return NE; |
| 698 | case kCondLT: return LT; |
| 699 | case kCondLE: return LE; |
| 700 | case kCondGT: return GT; |
| 701 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 702 | case kCondB: return LO; |
| 703 | case kCondBE: return LS; |
| 704 | case kCondA: return HI; |
| 705 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 706 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 707 | LOG(FATAL) << "Unreachable"; |
| 708 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 711 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 712 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 713 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 714 | case kCondEQ: return EQ; |
| 715 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 716 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 717 | case kCondLT: return LO; |
| 718 | case kCondLE: return LS; |
| 719 | case kCondGT: return HI; |
| 720 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 721 | // Unsigned remain unchanged. |
| 722 | case kCondB: return LO; |
| 723 | case kCondBE: return LS; |
| 724 | case kCondA: return HI; |
| 725 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 726 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 727 | LOG(FATAL) << "Unreachable"; |
| 728 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 731 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 732 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 736 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 737 | } |
| 738 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 739 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 740 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 741 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 744 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 745 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 746 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 749 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 750 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 751 | return kArmWordSize; |
| 752 | } |
| 753 | |
| 754 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 755 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 756 | return kArmWordSize; |
| 757 | } |
| 758 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 759 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 760 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 761 | const CompilerOptions& compiler_options, |
| 762 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 763 | : CodeGenerator(graph, |
| 764 | kNumberOfCoreRegisters, |
| 765 | kNumberOfSRegisters, |
| 766 | kNumberOfRegisterPairs, |
| 767 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 768 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 769 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 770 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 771 | compiler_options, |
| 772 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 773 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 774 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 775 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 776 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 777 | assembler_(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 778 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 779 | method_patches_(MethodReferenceComparator(), |
| 780 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 781 | call_patches_(MethodReferenceComparator(), |
| 782 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 783 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 784 | dex_cache_arrays_base_labels_(std::less<HArmDexCacheArraysBase*>(), |
| 785 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 786 | // Always save the LR register to mimic Quick. |
| 787 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 788 | } |
| 789 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 790 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 791 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 792 | __ FinalizeCode(); |
| 793 | |
| 794 | // Adjust native pc offsets in stack maps. |
| 795 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 796 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 797 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 798 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 799 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 800 | // Adjust pc offsets for the disassembly information. |
| 801 | if (disasm_info_ != nullptr) { |
| 802 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 803 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 804 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 805 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 806 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 807 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 808 | } |
| 809 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 810 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 811 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 812 | } |
| 813 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 814 | |
| 815 | CodeGenerator::Finalize(allocator); |
| 816 | } |
| 817 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 818 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 819 | switch (type) { |
| 820 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 821 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 822 | ArmManagedRegister pair = |
| 823 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 824 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 825 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 826 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 827 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 828 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 829 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 830 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | case Primitive::kPrimByte: |
| 834 | case Primitive::kPrimBoolean: |
| 835 | case Primitive::kPrimChar: |
| 836 | case Primitive::kPrimShort: |
| 837 | case Primitive::kPrimInt: |
| 838 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 839 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 840 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 841 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 842 | ArmManagedRegister current = |
| 843 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 844 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 845 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 846 | } |
| 847 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 848 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 849 | } |
| 850 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 851 | case Primitive::kPrimFloat: { |
| 852 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 853 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 854 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 855 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 856 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 857 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 858 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 859 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 860 | } |
| 861 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 862 | case Primitive::kPrimVoid: |
| 863 | LOG(FATAL) << "Unreachable type " << type; |
| 864 | } |
| 865 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 866 | return Location::NoLocation(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 867 | } |
| 868 | |
Nicolas Geoffray | a0bb2bd | 2015-01-26 12:49:35 +0000 | [diff] [blame] | 869 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 870 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 871 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 872 | |
| 873 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 874 | blocked_core_registers_[SP] = true; |
| 875 | blocked_core_registers_[LR] = true; |
| 876 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 877 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 878 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 879 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 880 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 881 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 882 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 883 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 884 | if (is_baseline) { |
| 885 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 886 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 887 | } |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 888 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 889 | blocked_core_registers_[kCoreSavedRegisterForBaseline] = false; |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 890 | } |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 891 | |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 892 | if (is_baseline || GetGraph()->IsDebuggable()) { |
| 893 | // Stubs do not save callee-save floating point registers. If the graph |
| 894 | // is debuggable, we need to deal with these registers differently. For |
| 895 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 896 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 897 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 898 | } |
| 899 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 900 | |
| 901 | UpdateBlockedPairRegisters(); |
| 902 | } |
| 903 | |
| 904 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 905 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 906 | ArmManagedRegister current = |
| 907 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 908 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 909 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 910 | blocked_register_pairs_[i] = true; |
| 911 | } |
| 912 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 915 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 916 | : HGraphVisitor(graph), |
| 917 | assembler_(codegen->GetAssembler()), |
| 918 | codegen_(codegen) {} |
| 919 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 920 | void CodeGeneratorARM::ComputeSpillMask() { |
| 921 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 922 | // Save one extra register for baseline. Note that on thumb2, there is no easy |
| 923 | // instruction to restore just the PC, so this actually helps both baseline |
| 924 | // and non-baseline to save and restore at least two registers at entry and exit. |
| 925 | core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 926 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 927 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 928 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 929 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 930 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 931 | // but in the range. |
| 932 | if (fpu_spill_mask_ != 0) { |
| 933 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 934 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 935 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 936 | fpu_spill_mask_ |= (1 << i); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 941 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 942 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 946 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 949 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 950 | bool skip_overflow_check = |
| 951 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 952 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 953 | __ Bind(&frame_entry_label_); |
| 954 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 955 | if (HasEmptyFrame()) { |
| 956 | return; |
| 957 | } |
| 958 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 959 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 960 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 961 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 962 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 965 | __ PushList(core_spill_mask_); |
| 966 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 967 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 968 | if (fpu_spill_mask_ != 0) { |
| 969 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 970 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 971 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 972 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 973 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 974 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 975 | __ AddConstant(SP, -adjust); |
| 976 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 977 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 981 | if (HasEmptyFrame()) { |
| 982 | __ bx(LR); |
| 983 | return; |
| 984 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 985 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 986 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 987 | __ AddConstant(SP, adjust); |
| 988 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 989 | if (fpu_spill_mask_ != 0) { |
| 990 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 991 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 992 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 993 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 994 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 995 | // Pop LR into PC to return. |
| 996 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 997 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 998 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 999 | __ cfi().RestoreState(); |
| 1000 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1003 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1004 | Label* label = GetLabelOf(block); |
| 1005 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1008 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 1009 | switch (load->GetType()) { |
| 1010 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1011 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1012 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1013 | |
| 1014 | case Primitive::kPrimInt: |
| 1015 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1016 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1017 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1018 | |
| 1019 | case Primitive::kPrimBoolean: |
| 1020 | case Primitive::kPrimByte: |
| 1021 | case Primitive::kPrimChar: |
| 1022 | case Primitive::kPrimShort: |
| 1023 | case Primitive::kPrimVoid: |
| 1024 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1025 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1029 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1030 | } |
| 1031 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1032 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1033 | switch (type) { |
| 1034 | case Primitive::kPrimBoolean: |
| 1035 | case Primitive::kPrimByte: |
| 1036 | case Primitive::kPrimChar: |
| 1037 | case Primitive::kPrimShort: |
| 1038 | case Primitive::kPrimInt: |
| 1039 | case Primitive::kPrimNot: { |
| 1040 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1041 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1042 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1043 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1044 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1045 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1046 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1047 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1048 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1049 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1050 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1051 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1052 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1053 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1054 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1055 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1056 | // Skip R1, and use R2_R3 instead. |
| 1057 | gp_index_++; |
| 1058 | index++; |
| 1059 | } |
| 1060 | } |
| 1061 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1062 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1063 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1064 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1065 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1066 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1067 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1068 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | case Primitive::kPrimFloat: { |
| 1073 | uint32_t stack_index = stack_index_++; |
| 1074 | if (float_index_ % 2 == 0) { |
| 1075 | float_index_ = std::max(double_index_, float_index_); |
| 1076 | } |
| 1077 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1078 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1079 | } else { |
| 1080 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | case Primitive::kPrimDouble: { |
| 1085 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1086 | uint32_t stack_index = stack_index_; |
| 1087 | stack_index_ += 2; |
| 1088 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1089 | uint32_t index = double_index_; |
| 1090 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1091 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1092 | calling_convention.GetFpuRegisterAt(index), |
| 1093 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1094 | DCHECK(ExpectedPairLayout(result)); |
| 1095 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1096 | } else { |
| 1097 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1101 | case Primitive::kPrimVoid: |
| 1102 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1103 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1104 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1105 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1106 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1107 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1108 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1109 | switch (type) { |
| 1110 | case Primitive::kPrimBoolean: |
| 1111 | case Primitive::kPrimByte: |
| 1112 | case Primitive::kPrimChar: |
| 1113 | case Primitive::kPrimShort: |
| 1114 | case Primitive::kPrimInt: |
| 1115 | case Primitive::kPrimNot: { |
| 1116 | return Location::RegisterLocation(R0); |
| 1117 | } |
| 1118 | |
| 1119 | case Primitive::kPrimFloat: { |
| 1120 | return Location::FpuRegisterLocation(S0); |
| 1121 | } |
| 1122 | |
| 1123 | case Primitive::kPrimLong: { |
| 1124 | return Location::RegisterPairLocation(R0, R1); |
| 1125 | } |
| 1126 | |
| 1127 | case Primitive::kPrimDouble: { |
| 1128 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1129 | } |
| 1130 | |
| 1131 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1132 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1133 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1134 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1135 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1138 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1139 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1140 | } |
| 1141 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1142 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1143 | if (source.Equals(destination)) { |
| 1144 | return; |
| 1145 | } |
| 1146 | if (destination.IsRegister()) { |
| 1147 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1148 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1149 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1150 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1151 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1152 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1153 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1154 | } else if (destination.IsFpuRegister()) { |
| 1155 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1156 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1157 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1158 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1159 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1160 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1162 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1163 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1164 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1165 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1166 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1167 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1168 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1169 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1170 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1171 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1177 | if (source.Equals(destination)) { |
| 1178 | return; |
| 1179 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1180 | if (destination.IsRegisterPair()) { |
| 1181 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1182 | EmitParallelMoves( |
| 1183 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1184 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1185 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1186 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1187 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1188 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1189 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1190 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1191 | } else if (source.IsFpuRegisterPair()) { |
| 1192 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1193 | destination.AsRegisterPairHigh<Register>(), |
| 1194 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1195 | } else { |
| 1196 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1197 | DCHECK(ExpectedPairLayout(destination)); |
| 1198 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1199 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1200 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1201 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1202 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1203 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1204 | SP, |
| 1205 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1206 | } else if (source.IsRegisterPair()) { |
| 1207 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1208 | source.AsRegisterPairLow<Register>(), |
| 1209 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1210 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1211 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1212 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | } else { |
| 1214 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1215 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1216 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1217 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1218 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1219 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1220 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1221 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1222 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | SP, destination.GetStackIndex()); |
| 1224 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1225 | } else if (source.IsFpuRegisterPair()) { |
| 1226 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1227 | SP, |
| 1228 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1229 | } else { |
| 1230 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1231 | EmitParallelMoves( |
| 1232 | Location::StackSlot(source.GetStackIndex()), |
| 1233 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1234 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1235 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1236 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1237 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1242 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1243 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1244 | if (instruction->IsCurrentMethod()) { |
| 1245 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1246 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1247 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1248 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1249 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1250 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1251 | int32_t value = GetInt32ValueOf(const_to_move); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1252 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1253 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1254 | } else { |
| 1255 | DCHECK(location.IsStackSlot()); |
| 1256 | __ LoadImmediate(IP, value); |
| 1257 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 1258 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1259 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 1260 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1261 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1262 | if (location.IsRegisterPair()) { |
| 1263 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 1264 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 1265 | } else { |
| 1266 | DCHECK(location.IsDoubleStackSlot()); |
| 1267 | __ LoadImmediate(IP, Low32Bits(value)); |
| 1268 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 1269 | __ LoadImmediate(IP, High32Bits(value)); |
| 1270 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 1271 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1272 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1273 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 1275 | switch (instruction->GetType()) { |
| 1276 | case Primitive::kPrimBoolean: |
| 1277 | case Primitive::kPrimByte: |
| 1278 | case Primitive::kPrimChar: |
| 1279 | case Primitive::kPrimShort: |
| 1280 | case Primitive::kPrimInt: |
| 1281 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1282 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1283 | Move32(location, Location::StackSlot(stack_slot)); |
| 1284 | break; |
| 1285 | |
| 1286 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1287 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1288 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 1289 | break; |
| 1290 | |
| 1291 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1292 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1293 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1294 | } else if (instruction->IsTemporary()) { |
| 1295 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1296 | if (temp_location.IsStackSlot()) { |
| 1297 | Move32(location, temp_location); |
| 1298 | } else { |
| 1299 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1300 | Move64(location, temp_location); |
| 1301 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1302 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1303 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1304 | switch (instruction->GetType()) { |
| 1305 | case Primitive::kPrimBoolean: |
| 1306 | case Primitive::kPrimByte: |
| 1307 | case Primitive::kPrimChar: |
| 1308 | case Primitive::kPrimShort: |
| 1309 | case Primitive::kPrimNot: |
| 1310 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1311 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1312 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1313 | break; |
| 1314 | |
| 1315 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1316 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1317 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1318 | break; |
| 1319 | |
| 1320 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1321 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1322 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1326 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1327 | DCHECK(location.IsRegister()); |
| 1328 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1329 | } |
| 1330 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1331 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1332 | if (Primitive::Is64BitType(dst_type)) { |
| 1333 | Move64(dst, src); |
| 1334 | } else { |
| 1335 | Move32(dst, src); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1340 | if (location.IsRegister()) { |
| 1341 | locations->AddTemp(location); |
| 1342 | } else if (location.IsRegisterPair()) { |
| 1343 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1344 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1345 | } else { |
| 1346 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1347 | } |
| 1348 | } |
| 1349 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1350 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1351 | HInstruction* instruction, |
| 1352 | uint32_t dex_pc, |
| 1353 | SlowPathCode* slow_path) { |
| 1354 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1355 | instruction, |
| 1356 | dex_pc, |
| 1357 | slow_path); |
| 1358 | } |
| 1359 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1360 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1361 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1362 | uint32_t dex_pc, |
| 1363 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1364 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1365 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1366 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1367 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1368 | } |
| 1369 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1370 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1371 | DCHECK(!successor->IsExitBlock()); |
| 1372 | |
| 1373 | HBasicBlock* block = got->GetBlock(); |
| 1374 | HInstruction* previous = got->GetPrevious(); |
| 1375 | |
| 1376 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1377 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1378 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1379 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1380 | return; |
| 1381 | } |
| 1382 | |
| 1383 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1384 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1385 | } |
| 1386 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1387 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1388 | } |
| 1389 | } |
| 1390 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1391 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1392 | got->SetLocations(nullptr); |
| 1393 | } |
| 1394 | |
| 1395 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1396 | HandleGoto(got, got->GetSuccessor()); |
| 1397 | } |
| 1398 | |
| 1399 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1400 | try_boundary->SetLocations(nullptr); |
| 1401 | } |
| 1402 | |
| 1403 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1404 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1405 | if (!successor->IsExitBlock()) { |
| 1406 | HandleGoto(try_boundary, successor); |
| 1407 | } |
| 1408 | } |
| 1409 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1410 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1411 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1414 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1417 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1418 | Label* true_label, |
| 1419 | Label* false_label) { |
| 1420 | __ vmstat(); // transfer FP status register to ARM APSR. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1421 | // 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] | 1422 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1423 | __ b(true_label, VS); // VS for unordered. |
| 1424 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1425 | __ b(false_label, VS); // VS for unordered. |
| 1426 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1427 | __ b(true_label, ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1431 | Label* true_label, |
| 1432 | Label* false_label) { |
| 1433 | LocationSummary* locations = cond->GetLocations(); |
| 1434 | Location left = locations->InAt(0); |
| 1435 | Location right = locations->InAt(1); |
| 1436 | IfCondition if_cond = cond->GetCondition(); |
| 1437 | |
| 1438 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1439 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1440 | IfCondition true_high_cond = if_cond; |
| 1441 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1442 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1443 | |
| 1444 | // Set the conditions for the test, remembering that == needs to be |
| 1445 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1446 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1447 | switch (if_cond) { |
| 1448 | case kCondEQ: |
| 1449 | case kCondNE: |
| 1450 | // Nothing to do. |
| 1451 | break; |
| 1452 | case kCondLT: |
| 1453 | false_high_cond = kCondGT; |
| 1454 | break; |
| 1455 | case kCondLE: |
| 1456 | true_high_cond = kCondLT; |
| 1457 | break; |
| 1458 | case kCondGT: |
| 1459 | false_high_cond = kCondLT; |
| 1460 | break; |
| 1461 | case kCondGE: |
| 1462 | true_high_cond = kCondGT; |
| 1463 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1464 | case kCondB: |
| 1465 | false_high_cond = kCondA; |
| 1466 | break; |
| 1467 | case kCondBE: |
| 1468 | true_high_cond = kCondB; |
| 1469 | break; |
| 1470 | case kCondA: |
| 1471 | false_high_cond = kCondB; |
| 1472 | break; |
| 1473 | case kCondAE: |
| 1474 | true_high_cond = kCondA; |
| 1475 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1476 | } |
| 1477 | if (right.IsConstant()) { |
| 1478 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1479 | int32_t val_low = Low32Bits(value); |
| 1480 | int32_t val_high = High32Bits(value); |
| 1481 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1482 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1483 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1484 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1485 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1486 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1487 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1488 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1489 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1490 | } |
| 1491 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1492 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1493 | } else { |
| 1494 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1495 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1496 | |
| 1497 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1498 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1499 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1500 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1501 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1502 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1503 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1504 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1505 | } |
| 1506 | // Must be equal high, so compare the lows. |
| 1507 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1508 | } |
| 1509 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1510 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1511 | __ b(true_label, final_condition); |
| 1512 | } |
| 1513 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1514 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1515 | Label* true_target_in, |
| 1516 | Label* false_target_in) { |
| 1517 | // Generated branching requires both targets to be explicit. If either of the |
| 1518 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1519 | Label fallthrough_target; |
| 1520 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1521 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1522 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1523 | LocationSummary* locations = condition->GetLocations(); |
| 1524 | Location left = locations->InAt(0); |
| 1525 | Location right = locations->InAt(1); |
| 1526 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1527 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1528 | switch (type) { |
| 1529 | case Primitive::kPrimLong: |
| 1530 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1531 | break; |
| 1532 | case Primitive::kPrimFloat: |
| 1533 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1534 | GenerateFPJumps(condition, true_target, false_target); |
| 1535 | break; |
| 1536 | case Primitive::kPrimDouble: |
| 1537 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1538 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1539 | GenerateFPJumps(condition, true_target, false_target); |
| 1540 | break; |
| 1541 | default: |
| 1542 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1543 | } |
| 1544 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1545 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1546 | __ b(false_target); |
| 1547 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1548 | |
| 1549 | if (fallthrough_target.IsLinked()) { |
| 1550 | __ Bind(&fallthrough_target); |
| 1551 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1554 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1555 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1556 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1557 | Label* false_target) { |
| 1558 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1559 | |
| 1560 | if (true_target == nullptr && false_target == nullptr) { |
| 1561 | // Nothing to do. The code always falls through. |
| 1562 | return; |
| 1563 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1564 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1565 | if (cond->AsIntConstant()->IsOne()) { |
| 1566 | if (true_target != nullptr) { |
| 1567 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1568 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1569 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1570 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1571 | if (false_target != nullptr) { |
| 1572 | __ b(false_target); |
| 1573 | } |
| 1574 | } |
| 1575 | return; |
| 1576 | } |
| 1577 | |
| 1578 | // The following code generates these patterns: |
| 1579 | // (1) true_target == nullptr && false_target != nullptr |
| 1580 | // - opposite condition true => branch to false_target |
| 1581 | // (2) true_target != nullptr && false_target == nullptr |
| 1582 | // - condition true => branch to true_target |
| 1583 | // (3) true_target != nullptr && false_target != nullptr |
| 1584 | // - condition true => branch to true_target |
| 1585 | // - branch to false_target |
| 1586 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1587 | // Condition has been materialized, compare the output to 0. |
| 1588 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1589 | DCHECK(cond_val.IsRegister()); |
| 1590 | if (true_target == nullptr) { |
| 1591 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1592 | } else { |
| 1593 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1594 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1595 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1596 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1597 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1598 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1599 | |
| 1600 | // If this is a long or FP comparison that has been folded into |
| 1601 | // the HCondition, generate the comparison directly. |
| 1602 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1603 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1604 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | LocationSummary* locations = cond->GetLocations(); |
| 1609 | DCHECK(locations->InAt(0).IsRegister()); |
| 1610 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1611 | Location right = locations->InAt(1); |
| 1612 | if (right.IsRegister()) { |
| 1613 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1614 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1615 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1616 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1617 | } |
| 1618 | if (true_target == nullptr) { |
| 1619 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1620 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1621 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1622 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1623 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1624 | |
| 1625 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1626 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1627 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1628 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1632 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1633 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1634 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1635 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1640 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1641 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1642 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1643 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1644 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1645 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1646 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1650 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1651 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1652 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1658 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DeoptimizationSlowPathARM(deoptimize); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1659 | codegen_->AddSlowPath(slow_path); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1660 | GenerateTestAndBranch(deoptimize, |
| 1661 | /* condition_input_index */ 0, |
| 1662 | slow_path->GetEntryLabel(), |
| 1663 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1664 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1665 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1666 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1667 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1668 | } |
| 1669 | |
| 1670 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1671 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1672 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1673 | __ nop(); |
| 1674 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1675 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1676 | } |
| 1677 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1678 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1679 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1680 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1681 | // Handle the long/FP comparisons made in instruction simplification. |
| 1682 | switch (cond->InputAt(0)->GetType()) { |
| 1683 | case Primitive::kPrimLong: |
| 1684 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1685 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1686 | if (cond->NeedsMaterialization()) { |
| 1687 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1688 | } |
| 1689 | break; |
| 1690 | |
| 1691 | case Primitive::kPrimFloat: |
| 1692 | case Primitive::kPrimDouble: |
| 1693 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1694 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1695 | if (cond->NeedsMaterialization()) { |
| 1696 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1697 | } |
| 1698 | break; |
| 1699 | |
| 1700 | default: |
| 1701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1702 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1703 | if (cond->NeedsMaterialization()) { |
| 1704 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1705 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1706 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1709 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1710 | if (!cond->NeedsMaterialization()) { |
| 1711 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1712 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1713 | |
| 1714 | LocationSummary* locations = cond->GetLocations(); |
| 1715 | Location left = locations->InAt(0); |
| 1716 | Location right = locations->InAt(1); |
| 1717 | Register out = locations->Out().AsRegister<Register>(); |
| 1718 | Label true_label, false_label; |
| 1719 | |
| 1720 | switch (cond->InputAt(0)->GetType()) { |
| 1721 | default: { |
| 1722 | // Integer case. |
| 1723 | if (right.IsRegister()) { |
| 1724 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1725 | } else { |
| 1726 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1727 | __ CmpConstant(left.AsRegister<Register>(), |
| 1728 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1729 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1730 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1731 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1732 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1733 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1734 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1735 | return; |
| 1736 | } |
| 1737 | case Primitive::kPrimLong: |
| 1738 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1739 | break; |
| 1740 | case Primitive::kPrimFloat: |
| 1741 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1742 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1743 | break; |
| 1744 | case Primitive::kPrimDouble: |
| 1745 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1746 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1747 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1748 | break; |
| 1749 | } |
| 1750 | |
| 1751 | // Convert the jumps into the result. |
| 1752 | Label done_label; |
| 1753 | |
| 1754 | // False case: result = 0. |
| 1755 | __ Bind(&false_label); |
| 1756 | __ LoadImmediate(out, 0); |
| 1757 | __ b(&done_label); |
| 1758 | |
| 1759 | // True case: result = 1. |
| 1760 | __ Bind(&true_label); |
| 1761 | __ LoadImmediate(out, 1); |
| 1762 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1813 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1826 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1830 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1834 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1838 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1842 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1845 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1846 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1849 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1850 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1853 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1854 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1857 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1858 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1862 | LocationSummary* locations = |
| 1863 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1864 | switch (store->InputAt(1)->GetType()) { |
| 1865 | case Primitive::kPrimBoolean: |
| 1866 | case Primitive::kPrimByte: |
| 1867 | case Primitive::kPrimChar: |
| 1868 | case Primitive::kPrimShort: |
| 1869 | case Primitive::kPrimInt: |
| 1870 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1871 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1872 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1873 | break; |
| 1874 | |
| 1875 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1876 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1877 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1878 | break; |
| 1879 | |
| 1880 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1881 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1882 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1885 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1889 | LocationSummary* locations = |
| 1890 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1891 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1894 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1895 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1898 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1899 | LocationSummary* locations = |
| 1900 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1901 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1902 | } |
| 1903 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1904 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1905 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1906 | } |
| 1907 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1908 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1909 | LocationSummary* locations = |
| 1910 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1911 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1912 | } |
| 1913 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1914 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1915 | // Will be generated at use site. |
| 1916 | } |
| 1917 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1918 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1919 | LocationSummary* locations = |
| 1920 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1921 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1922 | } |
| 1923 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1924 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1925 | // Will be generated at use site. |
| 1926 | } |
| 1927 | |
| 1928 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1929 | LocationSummary* locations = |
| 1930 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1931 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1932 | } |
| 1933 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1934 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1935 | // Will be generated at use site. |
| 1936 | } |
| 1937 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1938 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1939 | memory_barrier->SetLocations(nullptr); |
| 1940 | } |
| 1941 | |
| 1942 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1943 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1944 | } |
| 1945 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1946 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1947 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1950 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1951 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1954 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1955 | LocationSummary* locations = |
| 1956 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1957 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1960 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1961 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1964 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1965 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1966 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1967 | // the method_idx. |
| 1968 | HandleInvoke(invoke); |
| 1969 | } |
| 1970 | |
| 1971 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1972 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1973 | } |
| 1974 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1975 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1976 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1977 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1978 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1979 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1980 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1981 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1982 | codegen_->GetInstructionSetFeatures()); |
| 1983 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1984 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1985 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1986 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1987 | return; |
| 1988 | } |
| 1989 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1990 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1991 | |
| 1992 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1993 | if (invoke->HasPcRelativeDexCache()) { |
| 1994 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 1995 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1996 | } |
| 1997 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1998 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1999 | if (invoke->GetLocations()->Intrinsified()) { |
| 2000 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2001 | intrinsic.Dispatch(invoke); |
| 2002 | return true; |
| 2003 | } |
| 2004 | return false; |
| 2005 | } |
| 2006 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2007 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2008 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2009 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2010 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2011 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2012 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2013 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2014 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2015 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2016 | LocationSummary* locations = invoke->GetLocations(); |
| 2017 | codegen_->GenerateStaticOrDirectCall( |
| 2018 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2019 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2020 | } |
| 2021 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2022 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2023 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2024 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2027 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2028 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 2029 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2030 | codegen_->GetInstructionSetFeatures()); |
| 2031 | if (intrinsic.TryDispatch(invoke)) { |
| 2032 | return; |
| 2033 | } |
| 2034 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2035 | HandleInvoke(invoke); |
| 2036 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2037 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2038 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2039 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2040 | return; |
| 2041 | } |
| 2042 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2043 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2044 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2045 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2048 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2049 | HandleInvoke(invoke); |
| 2050 | // Add the hidden argument. |
| 2051 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2052 | } |
| 2053 | |
| 2054 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2055 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2056 | LocationSummary* locations = invoke->GetLocations(); |
| 2057 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2058 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2059 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2060 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2061 | Location receiver = locations->InAt(0); |
| 2062 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2063 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2064 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2065 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2066 | DCHECK_EQ(R12, hidden_reg); |
| 2067 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2068 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2069 | if (receiver.IsStackSlot()) { |
| 2070 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2071 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2072 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2073 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2074 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2075 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2076 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2077 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2078 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2079 | // emit a read barrier for the previous class reference load. |
| 2080 | // However this is not required in practice, as this is an |
| 2081 | // intermediate/temporary reference and because the current |
| 2082 | // concurrent copying collector keeps the from-space memory |
| 2083 | // intact/accessible until the end of the marking phase (the |
| 2084 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2085 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2086 | // temp = temp->GetImtEntryAt(method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2087 | uint32_t entry_point = |
| 2088 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2089 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 2090 | // LR = temp->GetEntryPoint(); |
| 2091 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2092 | // LR(); |
| 2093 | __ blx(LR); |
| 2094 | DCHECK(!codegen_->IsLeafMethod()); |
| 2095 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2096 | } |
| 2097 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2098 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2099 | LocationSummary* locations = |
| 2100 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2101 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2102 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2103 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2104 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2105 | break; |
| 2106 | } |
| 2107 | case Primitive::kPrimLong: { |
| 2108 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2109 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2110 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2111 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2112 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2113 | case Primitive::kPrimFloat: |
| 2114 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2115 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2116 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2117 | break; |
| 2118 | |
| 2119 | default: |
| 2120 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2125 | LocationSummary* locations = neg->GetLocations(); |
| 2126 | Location out = locations->Out(); |
| 2127 | Location in = locations->InAt(0); |
| 2128 | switch (neg->GetResultType()) { |
| 2129 | case Primitive::kPrimInt: |
| 2130 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2131 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2132 | break; |
| 2133 | |
| 2134 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2135 | DCHECK(in.IsRegisterPair()); |
| 2136 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2137 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2138 | in.AsRegisterPairLow<Register>(), |
| 2139 | ShifterOperand(0)); |
| 2140 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2141 | // instruction here, as it does not exist in the Thumb-2 |
| 2142 | // instruction set. We use the following approach |
| 2143 | // using SBC and SUB instead. |
| 2144 | // |
| 2145 | // out.hi = -C |
| 2146 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2147 | out.AsRegisterPairHigh<Register>(), |
| 2148 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2149 | // out.hi = out.hi - in.hi |
| 2150 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2151 | out.AsRegisterPairHigh<Register>(), |
| 2152 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2153 | break; |
| 2154 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2155 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2156 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2157 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2160 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2161 | DCHECK(in.IsFpuRegisterPair()); |
| 2162 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2163 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2164 | break; |
| 2165 | |
| 2166 | default: |
| 2167 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2168 | } |
| 2169 | } |
| 2170 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2171 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2172 | Primitive::Type result_type = conversion->GetResultType(); |
| 2173 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2174 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2175 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2176 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2177 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2178 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2179 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2180 | && result_type == Primitive::kPrimLong) |
| 2181 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2182 | ? LocationSummary::kCall |
| 2183 | : LocationSummary::kNoCall; |
| 2184 | LocationSummary* locations = |
| 2185 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2186 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2187 | // The Java language does not allow treating boolean as an integral type but |
| 2188 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2189 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2190 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2191 | case Primitive::kPrimByte: |
| 2192 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2193 | case Primitive::kPrimBoolean: |
| 2194 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2195 | case Primitive::kPrimShort: |
| 2196 | case Primitive::kPrimInt: |
| 2197 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2198 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2200 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2201 | break; |
| 2202 | |
| 2203 | default: |
| 2204 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2205 | << " to " << result_type; |
| 2206 | } |
| 2207 | break; |
| 2208 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2209 | case Primitive::kPrimShort: |
| 2210 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2211 | case Primitive::kPrimBoolean: |
| 2212 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimByte: |
| 2214 | case Primitive::kPrimInt: |
| 2215 | case Primitive::kPrimChar: |
| 2216 | // Processing a Dex `int-to-short' instruction. |
| 2217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2218 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2219 | break; |
| 2220 | |
| 2221 | default: |
| 2222 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2223 | << " to " << result_type; |
| 2224 | } |
| 2225 | break; |
| 2226 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2227 | case Primitive::kPrimInt: |
| 2228 | switch (input_type) { |
| 2229 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2230 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2231 | locations->SetInAt(0, Location::Any()); |
| 2232 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2233 | break; |
| 2234 | |
| 2235 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2236 | // Processing a Dex `float-to-int' instruction. |
| 2237 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2238 | locations->SetOut(Location::RequiresRegister()); |
| 2239 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2240 | break; |
| 2241 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2242 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2243 | // Processing a Dex `double-to-int' instruction. |
| 2244 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2245 | locations->SetOut(Location::RequiresRegister()); |
| 2246 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2247 | break; |
| 2248 | |
| 2249 | default: |
| 2250 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2251 | << " to " << result_type; |
| 2252 | } |
| 2253 | break; |
| 2254 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2255 | case Primitive::kPrimLong: |
| 2256 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2257 | case Primitive::kPrimBoolean: |
| 2258 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimByte: |
| 2260 | case Primitive::kPrimShort: |
| 2261 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2262 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2263 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2264 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2265 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2266 | break; |
| 2267 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimFloat: { |
| 2269 | // Processing a Dex `float-to-long' instruction. |
| 2270 | InvokeRuntimeCallingConvention calling_convention; |
| 2271 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2272 | calling_convention.GetFpuRegisterAt(0))); |
| 2273 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2274 | break; |
| 2275 | } |
| 2276 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2277 | case Primitive::kPrimDouble: { |
| 2278 | // Processing a Dex `double-to-long' instruction. |
| 2279 | InvokeRuntimeCallingConvention calling_convention; |
| 2280 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2281 | calling_convention.GetFpuRegisterAt(0), |
| 2282 | calling_convention.GetFpuRegisterAt(1))); |
| 2283 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2284 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2285 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2286 | |
| 2287 | default: |
| 2288 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2289 | << " to " << result_type; |
| 2290 | } |
| 2291 | break; |
| 2292 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2293 | case Primitive::kPrimChar: |
| 2294 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2295 | case Primitive::kPrimBoolean: |
| 2296 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2297 | case Primitive::kPrimByte: |
| 2298 | case Primitive::kPrimShort: |
| 2299 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2300 | // Processing a Dex `int-to-char' instruction. |
| 2301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2303 | break; |
| 2304 | |
| 2305 | default: |
| 2306 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2307 | << " to " << result_type; |
| 2308 | } |
| 2309 | break; |
| 2310 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2312 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2313 | case Primitive::kPrimBoolean: |
| 2314 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2315 | case Primitive::kPrimByte: |
| 2316 | case Primitive::kPrimShort: |
| 2317 | case Primitive::kPrimInt: |
| 2318 | case Primitive::kPrimChar: |
| 2319 | // Processing a Dex `int-to-float' instruction. |
| 2320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2321 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2322 | break; |
| 2323 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2324 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2325 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2326 | InvokeRuntimeCallingConvention calling_convention; |
| 2327 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2328 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2329 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2330 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2331 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2332 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2333 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2334 | // Processing a Dex `double-to-float' instruction. |
| 2335 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2336 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2337 | break; |
| 2338 | |
| 2339 | default: |
| 2340 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2341 | << " to " << result_type; |
| 2342 | }; |
| 2343 | break; |
| 2344 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2346 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimBoolean: |
| 2348 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimByte: |
| 2350 | case Primitive::kPrimShort: |
| 2351 | case Primitive::kPrimInt: |
| 2352 | case Primitive::kPrimChar: |
| 2353 | // Processing a Dex `int-to-double' instruction. |
| 2354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2355 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2356 | break; |
| 2357 | |
| 2358 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2359 | // Processing a Dex `long-to-double' instruction. |
| 2360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2361 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2362 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2363 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2364 | break; |
| 2365 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2366 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2367 | // Processing a Dex `float-to-double' instruction. |
| 2368 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2369 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2370 | break; |
| 2371 | |
| 2372 | default: |
| 2373 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2374 | << " to " << result_type; |
| 2375 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2376 | break; |
| 2377 | |
| 2378 | default: |
| 2379 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2380 | << " to " << result_type; |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2385 | LocationSummary* locations = conversion->GetLocations(); |
| 2386 | Location out = locations->Out(); |
| 2387 | Location in = locations->InAt(0); |
| 2388 | Primitive::Type result_type = conversion->GetResultType(); |
| 2389 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2390 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2391 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2392 | case Primitive::kPrimByte: |
| 2393 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2394 | case Primitive::kPrimBoolean: |
| 2395 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2396 | case Primitive::kPrimShort: |
| 2397 | case Primitive::kPrimInt: |
| 2398 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2399 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2400 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | |
| 2403 | default: |
| 2404 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2405 | << " to " << result_type; |
| 2406 | } |
| 2407 | break; |
| 2408 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimShort: |
| 2410 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimBoolean: |
| 2412 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimByte: |
| 2414 | case Primitive::kPrimInt: |
| 2415 | case Primitive::kPrimChar: |
| 2416 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2417 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2418 | break; |
| 2419 | |
| 2420 | default: |
| 2421 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2422 | << " to " << result_type; |
| 2423 | } |
| 2424 | break; |
| 2425 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimInt: |
| 2427 | switch (input_type) { |
| 2428 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2429 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2430 | DCHECK(out.IsRegister()); |
| 2431 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2432 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2433 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2434 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2435 | } else { |
| 2436 | DCHECK(in.IsConstant()); |
| 2437 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2438 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2439 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2440 | } |
| 2441 | break; |
| 2442 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2443 | case Primitive::kPrimFloat: { |
| 2444 | // Processing a Dex `float-to-int' instruction. |
| 2445 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2446 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 2447 | __ vcvtis(temp, temp); |
| 2448 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2449 | break; |
| 2450 | } |
| 2451 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2452 | case Primitive::kPrimDouble: { |
| 2453 | // Processing a Dex `double-to-int' instruction. |
| 2454 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2455 | DRegister temp_d = FromLowSToD(temp_s); |
| 2456 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 2457 | __ vcvtid(temp_s, temp_d); |
| 2458 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2459 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2460 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2461 | |
| 2462 | default: |
| 2463 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2464 | << " to " << result_type; |
| 2465 | } |
| 2466 | break; |
| 2467 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimLong: |
| 2469 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimBoolean: |
| 2471 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimByte: |
| 2473 | case Primitive::kPrimShort: |
| 2474 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2475 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2476 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2477 | DCHECK(out.IsRegisterPair()); |
| 2478 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2479 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2480 | // Sign extension. |
| 2481 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2482 | out.AsRegisterPairLow<Register>(), |
| 2483 | 31); |
| 2484 | break; |
| 2485 | |
| 2486 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2487 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2488 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2489 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2490 | conversion->GetDexPc(), |
| 2491 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2492 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2493 | break; |
| 2494 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2496 | // Processing a Dex `double-to-long' instruction. |
| 2497 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2498 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2499 | conversion->GetDexPc(), |
| 2500 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2501 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2502 | break; |
| 2503 | |
| 2504 | default: |
| 2505 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2506 | << " to " << result_type; |
| 2507 | } |
| 2508 | break; |
| 2509 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2510 | case Primitive::kPrimChar: |
| 2511 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimBoolean: |
| 2513 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimByte: |
| 2515 | case Primitive::kPrimShort: |
| 2516 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2517 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2518 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2519 | break; |
| 2520 | |
| 2521 | default: |
| 2522 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2523 | << " to " << result_type; |
| 2524 | } |
| 2525 | break; |
| 2526 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2527 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2528 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2529 | case Primitive::kPrimBoolean: |
| 2530 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimByte: |
| 2532 | case Primitive::kPrimShort: |
| 2533 | case Primitive::kPrimInt: |
| 2534 | case Primitive::kPrimChar: { |
| 2535 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2536 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2537 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | } |
| 2540 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2541 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2542 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2543 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2544 | conversion, |
| 2545 | conversion->GetDexPc(), |
| 2546 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2547 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2548 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2549 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2551 | // Processing a Dex `double-to-float' instruction. |
| 2552 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2553 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | |
| 2556 | default: |
| 2557 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2558 | << " to " << result_type; |
| 2559 | }; |
| 2560 | break; |
| 2561 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2563 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimBoolean: |
| 2565 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2566 | case Primitive::kPrimByte: |
| 2567 | case Primitive::kPrimShort: |
| 2568 | case Primitive::kPrimInt: |
| 2569 | case Primitive::kPrimChar: { |
| 2570 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2571 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2572 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2573 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2574 | break; |
| 2575 | } |
| 2576 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2577 | case Primitive::kPrimLong: { |
| 2578 | // Processing a Dex `long-to-double' instruction. |
| 2579 | Register low = in.AsRegisterPairLow<Register>(); |
| 2580 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2581 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2582 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2583 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2584 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2585 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2586 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2587 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2588 | // temp_d = int-to-double(high) |
| 2589 | __ vmovsr(temp_s, high); |
| 2590 | __ vcvtdi(temp_d, temp_s); |
| 2591 | // constant_d = k2Pow32EncodingForDouble |
| 2592 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2593 | // out_d = unsigned-to-double(low) |
| 2594 | __ vmovsr(out_s, low); |
| 2595 | __ vcvtdu(out_d, out_s); |
| 2596 | // out_d += temp_d * constant_d |
| 2597 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2598 | break; |
| 2599 | } |
| 2600 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2602 | // Processing a Dex `float-to-double' instruction. |
| 2603 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2604 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2609 | << " to " << result_type; |
| 2610 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2611 | break; |
| 2612 | |
| 2613 | default: |
| 2614 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2615 | << " to " << result_type; |
| 2616 | } |
| 2617 | } |
| 2618 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2619 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2620 | LocationSummary* locations = |
| 2621 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2622 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2623 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2624 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2625 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2626 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2627 | break; |
| 2628 | } |
| 2629 | |
| 2630 | case Primitive::kPrimLong: { |
| 2631 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2632 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2634 | break; |
| 2635 | } |
| 2636 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2637 | case Primitive::kPrimFloat: |
| 2638 | case Primitive::kPrimDouble: { |
| 2639 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2640 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2641 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2642 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2643 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2644 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2645 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2646 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2647 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2651 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2652 | Location out = locations->Out(); |
| 2653 | Location first = locations->InAt(0); |
| 2654 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2655 | switch (add->GetResultType()) { |
| 2656 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2657 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2658 | __ add(out.AsRegister<Register>(), |
| 2659 | first.AsRegister<Register>(), |
| 2660 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2661 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2662 | __ AddConstant(out.AsRegister<Register>(), |
| 2663 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2664 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2665 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2666 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2667 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2668 | case Primitive::kPrimLong: { |
| 2669 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2670 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2671 | first.AsRegisterPairLow<Register>(), |
| 2672 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2673 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2674 | first.AsRegisterPairHigh<Register>(), |
| 2675 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2676 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2677 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2678 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2679 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2680 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2681 | first.AsFpuRegister<SRegister>(), |
| 2682 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2683 | break; |
| 2684 | |
| 2685 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2686 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2687 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2688 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2689 | break; |
| 2690 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2691 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2692 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2696 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2697 | LocationSummary* locations = |
| 2698 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2699 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2700 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2702 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2703 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2704 | break; |
| 2705 | } |
| 2706 | |
| 2707 | case Primitive::kPrimLong: { |
| 2708 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2709 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2710 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2711 | break; |
| 2712 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2713 | case Primitive::kPrimFloat: |
| 2714 | case Primitive::kPrimDouble: { |
| 2715 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2716 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2717 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2718 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2719 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2720 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2721 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2722 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2726 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2727 | Location out = locations->Out(); |
| 2728 | Location first = locations->InAt(0); |
| 2729 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2730 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2731 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2732 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2733 | __ sub(out.AsRegister<Register>(), |
| 2734 | first.AsRegister<Register>(), |
| 2735 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2736 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2737 | __ AddConstant(out.AsRegister<Register>(), |
| 2738 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2739 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2740 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2741 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2742 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2743 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2744 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2745 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2746 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2747 | first.AsRegisterPairLow<Register>(), |
| 2748 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2749 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2750 | first.AsRegisterPairHigh<Register>(), |
| 2751 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2752 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2753 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2754 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2755 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2756 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2757 | first.AsFpuRegister<SRegister>(), |
| 2758 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2759 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2763 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2764 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2765 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2766 | break; |
| 2767 | } |
| 2768 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2769 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2770 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2771 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2772 | } |
| 2773 | } |
| 2774 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2775 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2776 | LocationSummary* locations = |
| 2777 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2778 | switch (mul->GetResultType()) { |
| 2779 | case Primitive::kPrimInt: |
| 2780 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2782 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2784 | break; |
| 2785 | } |
| 2786 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2787 | case Primitive::kPrimFloat: |
| 2788 | case Primitive::kPrimDouble: { |
| 2789 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2790 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2791 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2792 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2793 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2794 | |
| 2795 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2796 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2801 | LocationSummary* locations = mul->GetLocations(); |
| 2802 | Location out = locations->Out(); |
| 2803 | Location first = locations->InAt(0); |
| 2804 | Location second = locations->InAt(1); |
| 2805 | switch (mul->GetResultType()) { |
| 2806 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2807 | __ mul(out.AsRegister<Register>(), |
| 2808 | first.AsRegister<Register>(), |
| 2809 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2810 | break; |
| 2811 | } |
| 2812 | case Primitive::kPrimLong: { |
| 2813 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2814 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2815 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2816 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2817 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2818 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2819 | |
| 2820 | // Extra checks to protect caused by the existence of R1_R2. |
| 2821 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2822 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2823 | DCHECK_NE(out_hi, in1_lo); |
| 2824 | DCHECK_NE(out_hi, in2_lo); |
| 2825 | |
| 2826 | // input: in1 - 64 bits, in2 - 64 bits |
| 2827 | // output: out |
| 2828 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2829 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2830 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2831 | |
| 2832 | // IP <- in1.lo * in2.hi |
| 2833 | __ mul(IP, in1_lo, in2_hi); |
| 2834 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2835 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2836 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2837 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2838 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2839 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2840 | break; |
| 2841 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2842 | |
| 2843 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2844 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2845 | first.AsFpuRegister<SRegister>(), |
| 2846 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2847 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2851 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2852 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2853 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2854 | break; |
| 2855 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2856 | |
| 2857 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2858 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2859 | } |
| 2860 | } |
| 2861 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2862 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2863 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2864 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2865 | |
| 2866 | LocationSummary* locations = instruction->GetLocations(); |
| 2867 | Location second = locations->InAt(1); |
| 2868 | DCHECK(second.IsConstant()); |
| 2869 | |
| 2870 | Register out = locations->Out().AsRegister<Register>(); |
| 2871 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2872 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2873 | DCHECK(imm == 1 || imm == -1); |
| 2874 | |
| 2875 | if (instruction->IsRem()) { |
| 2876 | __ LoadImmediate(out, 0); |
| 2877 | } else { |
| 2878 | if (imm == 1) { |
| 2879 | __ Mov(out, dividend); |
| 2880 | } else { |
| 2881 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2882 | } |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2887 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2888 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2889 | |
| 2890 | LocationSummary* locations = instruction->GetLocations(); |
| 2891 | Location second = locations->InAt(1); |
| 2892 | DCHECK(second.IsConstant()); |
| 2893 | |
| 2894 | Register out = locations->Out().AsRegister<Register>(); |
| 2895 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2896 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2897 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2898 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2899 | int ctz_imm = CTZ(abs_imm); |
| 2900 | |
| 2901 | if (ctz_imm == 1) { |
| 2902 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2903 | } else { |
| 2904 | __ Asr(temp, dividend, 31); |
| 2905 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2906 | } |
| 2907 | __ add(out, temp, ShifterOperand(dividend)); |
| 2908 | |
| 2909 | if (instruction->IsDiv()) { |
| 2910 | __ Asr(out, out, ctz_imm); |
| 2911 | if (imm < 0) { |
| 2912 | __ rsb(out, out, ShifterOperand(0)); |
| 2913 | } |
| 2914 | } else { |
| 2915 | __ ubfx(out, out, 0, ctz_imm); |
| 2916 | __ sub(out, out, ShifterOperand(temp)); |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2921 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2922 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2923 | |
| 2924 | LocationSummary* locations = instruction->GetLocations(); |
| 2925 | Location second = locations->InAt(1); |
| 2926 | DCHECK(second.IsConstant()); |
| 2927 | |
| 2928 | Register out = locations->Out().AsRegister<Register>(); |
| 2929 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2930 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2931 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2932 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2933 | |
| 2934 | int64_t magic; |
| 2935 | int shift; |
| 2936 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2937 | |
| 2938 | __ LoadImmediate(temp1, magic); |
| 2939 | __ smull(temp2, temp1, dividend, temp1); |
| 2940 | |
| 2941 | if (imm > 0 && magic < 0) { |
| 2942 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2943 | } else if (imm < 0 && magic > 0) { |
| 2944 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2945 | } |
| 2946 | |
| 2947 | if (shift != 0) { |
| 2948 | __ Asr(temp1, temp1, shift); |
| 2949 | } |
| 2950 | |
| 2951 | if (instruction->IsDiv()) { |
| 2952 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2953 | } else { |
| 2954 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2955 | // TODO: Strength reduction for mls. |
| 2956 | __ LoadImmediate(temp2, imm); |
| 2957 | __ mls(out, temp1, temp2, dividend); |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2962 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2963 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2964 | |
| 2965 | LocationSummary* locations = instruction->GetLocations(); |
| 2966 | Location second = locations->InAt(1); |
| 2967 | DCHECK(second.IsConstant()); |
| 2968 | |
| 2969 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2970 | if (imm == 0) { |
| 2971 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2972 | } else if (imm == 1 || imm == -1) { |
| 2973 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2974 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2975 | DivRemByPowerOfTwo(instruction); |
| 2976 | } else { |
| 2977 | DCHECK(imm <= -2 || imm >= 2); |
| 2978 | GenerateDivRemWithAnyConstant(instruction); |
| 2979 | } |
| 2980 | } |
| 2981 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2982 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2983 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2984 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2985 | // pLdiv runtime call. |
| 2986 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2987 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2988 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2989 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2990 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2991 | // pIdivmod runtime call. |
| 2992 | call_kind = LocationSummary::kCall; |
| 2993 | } |
| 2994 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2995 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2996 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2997 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2998 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2999 | if (div->InputAt(1)->IsConstant()) { |
| 3000 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3001 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3002 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3003 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3004 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3005 | // No temp register required. |
| 3006 | } else { |
| 3007 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3008 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3009 | locations->AddTemp(Location::RequiresRegister()); |
| 3010 | } |
| 3011 | } |
| 3012 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3013 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3014 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3015 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3016 | } else { |
| 3017 | InvokeRuntimeCallingConvention calling_convention; |
| 3018 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3019 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3020 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3021 | // we only need the former. |
| 3022 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3023 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3024 | break; |
| 3025 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3026 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3027 | InvokeRuntimeCallingConvention calling_convention; |
| 3028 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3029 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3030 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3031 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3032 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3033 | break; |
| 3034 | } |
| 3035 | case Primitive::kPrimFloat: |
| 3036 | case Primitive::kPrimDouble: { |
| 3037 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3038 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3039 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3040 | break; |
| 3041 | } |
| 3042 | |
| 3043 | default: |
| 3044 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3049 | LocationSummary* locations = div->GetLocations(); |
| 3050 | Location out = locations->Out(); |
| 3051 | Location first = locations->InAt(0); |
| 3052 | Location second = locations->InAt(1); |
| 3053 | |
| 3054 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3055 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3056 | if (second.IsConstant()) { |
| 3057 | GenerateDivRemConstantIntegral(div); |
| 3058 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3059 | __ sdiv(out.AsRegister<Register>(), |
| 3060 | first.AsRegister<Register>(), |
| 3061 | second.AsRegister<Register>()); |
| 3062 | } else { |
| 3063 | InvokeRuntimeCallingConvention calling_convention; |
| 3064 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3065 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3066 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3067 | |
| 3068 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3069 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3070 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3071 | break; |
| 3072 | } |
| 3073 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3074 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3075 | InvokeRuntimeCallingConvention calling_convention; |
| 3076 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3077 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3078 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3079 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3080 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3081 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3082 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3083 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3084 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | } |
| 3087 | |
| 3088 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3089 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3090 | first.AsFpuRegister<SRegister>(), |
| 3091 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3092 | break; |
| 3093 | } |
| 3094 | |
| 3095 | case Primitive::kPrimDouble: { |
| 3096 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3097 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3098 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3099 | break; |
| 3100 | } |
| 3101 | |
| 3102 | default: |
| 3103 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3104 | } |
| 3105 | } |
| 3106 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3107 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3108 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3109 | |
| 3110 | // Most remainders are implemented in the runtime. |
| 3111 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3112 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3113 | // sdiv will be replaced by other instruction sequence. |
| 3114 | call_kind = LocationSummary::kNoCall; |
| 3115 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3116 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3117 | // Have hardware divide instruction for int, do it with three instructions. |
| 3118 | call_kind = LocationSummary::kNoCall; |
| 3119 | } |
| 3120 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3121 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3122 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3123 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3124 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3125 | if (rem->InputAt(1)->IsConstant()) { |
| 3126 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3127 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3128 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3129 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3130 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3131 | // No temp register required. |
| 3132 | } else { |
| 3133 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3134 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3135 | locations->AddTemp(Location::RequiresRegister()); |
| 3136 | } |
| 3137 | } |
| 3138 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3140 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3141 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3142 | locations->AddTemp(Location::RequiresRegister()); |
| 3143 | } else { |
| 3144 | InvokeRuntimeCallingConvention calling_convention; |
| 3145 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3146 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3147 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3148 | // we only need the latter. |
| 3149 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3150 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3151 | break; |
| 3152 | } |
| 3153 | case Primitive::kPrimLong: { |
| 3154 | InvokeRuntimeCallingConvention calling_convention; |
| 3155 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3156 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3157 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3158 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3159 | // The runtime helper puts the output in R2,R3. |
| 3160 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3161 | break; |
| 3162 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3163 | case Primitive::kPrimFloat: { |
| 3164 | InvokeRuntimeCallingConvention calling_convention; |
| 3165 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3166 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3167 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3168 | break; |
| 3169 | } |
| 3170 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3171 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3172 | InvokeRuntimeCallingConvention calling_convention; |
| 3173 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3174 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3175 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3176 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3177 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3178 | break; |
| 3179 | } |
| 3180 | |
| 3181 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3182 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3183 | } |
| 3184 | } |
| 3185 | |
| 3186 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3187 | LocationSummary* locations = rem->GetLocations(); |
| 3188 | Location out = locations->Out(); |
| 3189 | Location first = locations->InAt(0); |
| 3190 | Location second = locations->InAt(1); |
| 3191 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3192 | Primitive::Type type = rem->GetResultType(); |
| 3193 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3194 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3195 | if (second.IsConstant()) { |
| 3196 | GenerateDivRemConstantIntegral(rem); |
| 3197 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3198 | Register reg1 = first.AsRegister<Register>(); |
| 3199 | Register reg2 = second.AsRegister<Register>(); |
| 3200 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3201 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3202 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3203 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3204 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3205 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3206 | } else { |
| 3207 | InvokeRuntimeCallingConvention calling_convention; |
| 3208 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3209 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3210 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3211 | |
| 3212 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3213 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3214 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3215 | break; |
| 3216 | } |
| 3217 | |
| 3218 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3219 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3220 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3221 | break; |
| 3222 | } |
| 3223 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3224 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3225 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3226 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3227 | break; |
| 3228 | } |
| 3229 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3230 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3231 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3232 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3233 | break; |
| 3234 | } |
| 3235 | |
| 3236 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3237 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3241 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3242 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3243 | ? LocationSummary::kCallOnSlowPath |
| 3244 | : LocationSummary::kNoCall; |
| 3245 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3246 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3247 | if (instruction->HasUses()) { |
| 3248 | locations->SetOut(Location::SameAsFirstInput()); |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3253 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3254 | codegen_->AddSlowPath(slow_path); |
| 3255 | |
| 3256 | LocationSummary* locations = instruction->GetLocations(); |
| 3257 | Location value = locations->InAt(0); |
| 3258 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3259 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3260 | case Primitive::kPrimByte: |
| 3261 | case Primitive::kPrimChar: |
| 3262 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3263 | case Primitive::kPrimInt: { |
| 3264 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3265 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3266 | } else { |
| 3267 | DCHECK(value.IsConstant()) << value; |
| 3268 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3269 | __ b(slow_path->GetEntryLabel()); |
| 3270 | } |
| 3271 | } |
| 3272 | break; |
| 3273 | } |
| 3274 | case Primitive::kPrimLong: { |
| 3275 | if (value.IsRegisterPair()) { |
| 3276 | __ orrs(IP, |
| 3277 | value.AsRegisterPairLow<Register>(), |
| 3278 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3279 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3280 | } else { |
| 3281 | DCHECK(value.IsConstant()) << value; |
| 3282 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3283 | __ b(slow_path->GetEntryLabel()); |
| 3284 | } |
| 3285 | } |
| 3286 | break; |
| 3287 | default: |
| 3288 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3289 | } |
| 3290 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3293 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3294 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3295 | Location rhs = locations->InAt(1); |
| 3296 | Register out = locations->Out().AsRegister<Register>(); |
| 3297 | |
| 3298 | if (rhs.IsConstant()) { |
| 3299 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3300 | // so map all rotations to a +ve. equivalent in that range. |
| 3301 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3302 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3303 | if (rot) { |
| 3304 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3305 | // (e.g. left by 2 bits == right by 30.) |
| 3306 | __ Ror(out, in, rot); |
| 3307 | } else if (out != in) { |
| 3308 | __ Mov(out, in); |
| 3309 | } |
| 3310 | } else { |
| 3311 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3316 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3317 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3318 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3319 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3320 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3321 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3322 | Location rhs = locations->InAt(1); |
| 3323 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3324 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3325 | |
| 3326 | if (rhs.IsConstant()) { |
| 3327 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3328 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 3329 | rot &= kMaxLongShiftValue; |
| 3330 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3331 | // logic below to a simple pair of binary orr. |
| 3332 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3333 | if (rot >= kArmBitsPerWord) { |
| 3334 | rot -= kArmBitsPerWord; |
| 3335 | std::swap(in_reg_hi, in_reg_lo); |
| 3336 | } |
| 3337 | // Rotate, or mov to out for zero or word size rotations. |
| 3338 | if (rot != 0u) { |
| 3339 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3340 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3341 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3342 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3343 | } else { |
| 3344 | __ Mov(out_reg_lo, in_reg_lo); |
| 3345 | __ Mov(out_reg_hi, in_reg_hi); |
| 3346 | } |
| 3347 | } else { |
| 3348 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3349 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3350 | Label end; |
| 3351 | Label shift_by_32_plus_shift_right; |
| 3352 | |
| 3353 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3354 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3355 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3356 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3357 | |
| 3358 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3359 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3360 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3361 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3362 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3363 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3364 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3365 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3366 | __ b(&end); |
| 3367 | |
| 3368 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3369 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3370 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3371 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3372 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3373 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3374 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3375 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3376 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3377 | |
| 3378 | __ Bind(&end); |
| 3379 | } |
| 3380 | } |
| 3381 | void LocationsBuilderARM::HandleRotate(HRor* ror) { |
| 3382 | LocationSummary* locations = |
| 3383 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3384 | switch (ror->GetResultType()) { |
| 3385 | case Primitive::kPrimInt: { |
| 3386 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3387 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3388 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3389 | break; |
| 3390 | } |
| 3391 | case Primitive::kPrimLong: { |
| 3392 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3393 | if (ror->InputAt(1)->IsConstant()) { |
| 3394 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3395 | } else { |
| 3396 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3397 | locations->AddTemp(Location::RequiresRegister()); |
| 3398 | locations->AddTemp(Location::RequiresRegister()); |
| 3399 | } |
| 3400 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3401 | break; |
| 3402 | } |
| 3403 | default: |
| 3404 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | void InstructionCodeGeneratorARM::HandleRotate(HRor* ror) { |
| 3409 | LocationSummary* locations = ror->GetLocations(); |
| 3410 | Primitive::Type type = ror->GetResultType(); |
| 3411 | switch (type) { |
| 3412 | case Primitive::kPrimInt: { |
| 3413 | HandleIntegerRotate(locations); |
| 3414 | break; |
| 3415 | } |
| 3416 | case Primitive::kPrimLong: { |
| 3417 | HandleLongRotate(locations); |
| 3418 | break; |
| 3419 | } |
| 3420 | default: |
| 3421 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3422 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | void LocationsBuilderARM::VisitRor(HRor* op) { |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3427 | HandleRotate(op); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | void InstructionCodeGeneratorARM::VisitRor(HRor* op) { |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3431 | HandleRotate(op); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3432 | } |
| 3433 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3434 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3435 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3436 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3437 | LocationSummary* locations = |
| 3438 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3439 | |
| 3440 | switch (op->GetResultType()) { |
| 3441 | case Primitive::kPrimInt: { |
| 3442 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3443 | if (op->InputAt(1)->IsConstant()) { |
| 3444 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3445 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3446 | } else { |
| 3447 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3448 | // Make the output overlap, as it will be used to hold the masked |
| 3449 | // second input. |
| 3450 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3451 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3452 | break; |
| 3453 | } |
| 3454 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3455 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3456 | if (op->InputAt(1)->IsConstant()) { |
| 3457 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3458 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3459 | // don't clash with high registers which the register allocator currently guarantees. |
| 3460 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3461 | } else { |
| 3462 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3463 | locations->AddTemp(Location::RequiresRegister()); |
| 3464 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3465 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3466 | break; |
| 3467 | } |
| 3468 | default: |
| 3469 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3474 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3475 | |
| 3476 | LocationSummary* locations = op->GetLocations(); |
| 3477 | Location out = locations->Out(); |
| 3478 | Location first = locations->InAt(0); |
| 3479 | Location second = locations->InAt(1); |
| 3480 | |
| 3481 | Primitive::Type type = op->GetResultType(); |
| 3482 | switch (type) { |
| 3483 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3484 | Register out_reg = out.AsRegister<Register>(); |
| 3485 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3486 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3487 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3488 | // 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] | 3489 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3490 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3491 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3492 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3493 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3494 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3495 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3496 | } |
| 3497 | } else { |
| 3498 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3499 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3500 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3501 | __ Mov(out_reg, first_reg); |
| 3502 | } else if (op->IsShl()) { |
| 3503 | __ Lsl(out_reg, first_reg, shift_value); |
| 3504 | } else if (op->IsShr()) { |
| 3505 | __ Asr(out_reg, first_reg, shift_value); |
| 3506 | } else { |
| 3507 | __ Lsr(out_reg, first_reg, shift_value); |
| 3508 | } |
| 3509 | } |
| 3510 | break; |
| 3511 | } |
| 3512 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3513 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3514 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3515 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3516 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3517 | Register low = first.AsRegisterPairLow<Register>(); |
| 3518 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3519 | if (second.IsRegister()) { |
| 3520 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3521 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3522 | Register second_reg = second.AsRegister<Register>(); |
| 3523 | |
| 3524 | if (op->IsShl()) { |
| 3525 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3526 | // Shift the high part |
| 3527 | __ Lsl(o_h, high, o_l); |
| 3528 | // Shift the low part and `or` what overflew on the high part |
| 3529 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3530 | __ Lsr(temp, low, temp); |
| 3531 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3532 | // If the shift is > 32 bits, override the high part |
| 3533 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3534 | __ it(PL); |
| 3535 | __ Lsl(o_h, low, temp, PL); |
| 3536 | // Shift the low part |
| 3537 | __ Lsl(o_l, low, o_l); |
| 3538 | } else if (op->IsShr()) { |
| 3539 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3540 | // Shift the low part |
| 3541 | __ Lsr(o_l, low, o_h); |
| 3542 | // Shift the high part and `or` what underflew on the low part |
| 3543 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3544 | __ Lsl(temp, high, temp); |
| 3545 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3546 | // If the shift is > 32 bits, override the low part |
| 3547 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3548 | __ it(PL); |
| 3549 | __ Asr(o_l, high, temp, PL); |
| 3550 | // Shift the high part |
| 3551 | __ Asr(o_h, high, o_h); |
| 3552 | } else { |
| 3553 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3554 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3555 | __ Lsr(o_l, low, o_h); |
| 3556 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3557 | __ Lsl(temp, high, temp); |
| 3558 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3559 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3560 | __ it(PL); |
| 3561 | __ Lsr(o_l, high, temp, PL); |
| 3562 | __ Lsr(o_h, high, o_h); |
| 3563 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3564 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3565 | // Register allocator doesn't create partial overlap. |
| 3566 | DCHECK_NE(o_l, high); |
| 3567 | DCHECK_NE(o_h, low); |
| 3568 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3569 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxLongShiftValue); |
| 3570 | if (shift_value > 32) { |
| 3571 | if (op->IsShl()) { |
| 3572 | __ Lsl(o_h, low, shift_value - 32); |
| 3573 | __ LoadImmediate(o_l, 0); |
| 3574 | } else if (op->IsShr()) { |
| 3575 | __ Asr(o_l, high, shift_value - 32); |
| 3576 | __ Asr(o_h, high, 31); |
| 3577 | } else { |
| 3578 | __ Lsr(o_l, high, shift_value - 32); |
| 3579 | __ LoadImmediate(o_h, 0); |
| 3580 | } |
| 3581 | } else if (shift_value == 32) { |
| 3582 | if (op->IsShl()) { |
| 3583 | __ mov(o_h, ShifterOperand(low)); |
| 3584 | __ LoadImmediate(o_l, 0); |
| 3585 | } else if (op->IsShr()) { |
| 3586 | __ mov(o_l, ShifterOperand(high)); |
| 3587 | __ Asr(o_h, high, 31); |
| 3588 | } else { |
| 3589 | __ mov(o_l, ShifterOperand(high)); |
| 3590 | __ LoadImmediate(o_h, 0); |
| 3591 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3592 | } else if (shift_value == 1) { |
| 3593 | if (op->IsShl()) { |
| 3594 | __ Lsls(o_l, low, 1); |
| 3595 | __ adc(o_h, high, ShifterOperand(high)); |
| 3596 | } else if (op->IsShr()) { |
| 3597 | __ Asrs(o_h, high, 1); |
| 3598 | __ Rrx(o_l, low); |
| 3599 | } else { |
| 3600 | __ Lsrs(o_h, high, 1); |
| 3601 | __ Rrx(o_l, low); |
| 3602 | } |
| 3603 | } else { |
| 3604 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3605 | if (op->IsShl()) { |
| 3606 | __ Lsl(o_h, high, shift_value); |
| 3607 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3608 | __ Lsl(o_l, low, shift_value); |
| 3609 | } else if (op->IsShr()) { |
| 3610 | __ Lsr(o_l, low, shift_value); |
| 3611 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3612 | __ Asr(o_h, high, shift_value); |
| 3613 | } else { |
| 3614 | __ Lsr(o_l, low, shift_value); |
| 3615 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3616 | __ Lsr(o_h, high, shift_value); |
| 3617 | } |
| 3618 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3619 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3620 | break; |
| 3621 | } |
| 3622 | default: |
| 3623 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3624 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3629 | HandleShift(shl); |
| 3630 | } |
| 3631 | |
| 3632 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3633 | HandleShift(shl); |
| 3634 | } |
| 3635 | |
| 3636 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3637 | HandleShift(shr); |
| 3638 | } |
| 3639 | |
| 3640 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3641 | HandleShift(shr); |
| 3642 | } |
| 3643 | |
| 3644 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3645 | HandleShift(ushr); |
| 3646 | } |
| 3647 | |
| 3648 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3649 | HandleShift(ushr); |
| 3650 | } |
| 3651 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3652 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3653 | LocationSummary* locations = |
| 3654 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3655 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3656 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3657 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3658 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3662 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3663 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3664 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3665 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3666 | instruction->GetDexPc(), |
| 3667 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3668 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3669 | } |
| 3670 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3671 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3672 | LocationSummary* locations = |
| 3673 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3674 | InvokeRuntimeCallingConvention calling_convention; |
| 3675 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3676 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3677 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3678 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3682 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3683 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3684 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3685 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3686 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3687 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3688 | instruction->GetDexPc(), |
| 3689 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3690 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3691 | } |
| 3692 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3693 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3694 | LocationSummary* locations = |
| 3695 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3696 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3697 | if (location.IsStackSlot()) { |
| 3698 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3699 | } else if (location.IsDoubleStackSlot()) { |
| 3700 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3701 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3702 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3703 | } |
| 3704 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3705 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3706 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3707 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3711 | LocationSummary* locations = |
| 3712 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3713 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3714 | } |
| 3715 | |
| 3716 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3717 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3718 | } |
| 3719 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3720 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3721 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3722 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3724 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3725 | } |
| 3726 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3727 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3728 | LocationSummary* locations = not_->GetLocations(); |
| 3729 | Location out = locations->Out(); |
| 3730 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3731 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3732 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3733 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3734 | break; |
| 3735 | |
| 3736 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3737 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3738 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3739 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3740 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3741 | break; |
| 3742 | |
| 3743 | default: |
| 3744 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3745 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3746 | } |
| 3747 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3748 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3749 | LocationSummary* locations = |
| 3750 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3751 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3752 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3753 | } |
| 3754 | |
| 3755 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3756 | LocationSummary* locations = bool_not->GetLocations(); |
| 3757 | Location out = locations->Out(); |
| 3758 | Location in = locations->InAt(0); |
| 3759 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3760 | } |
| 3761 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3762 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3763 | LocationSummary* locations = |
| 3764 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3765 | switch (compare->InputAt(0)->GetType()) { |
| 3766 | case Primitive::kPrimLong: { |
| 3767 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3768 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3769 | // Output overlaps because it is written before doing the low comparison. |
| 3770 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3771 | break; |
| 3772 | } |
| 3773 | case Primitive::kPrimFloat: |
| 3774 | case Primitive::kPrimDouble: { |
| 3775 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3776 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3777 | locations->SetOut(Location::RequiresRegister()); |
| 3778 | break; |
| 3779 | } |
| 3780 | default: |
| 3781 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3782 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3786 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3787 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3788 | Location left = locations->InAt(0); |
| 3789 | Location right = locations->InAt(1); |
| 3790 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3791 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3792 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 3793 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3794 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3795 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3796 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3797 | __ b(&less, LT); |
| 3798 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3799 | // 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] | 3800 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3801 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3802 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3803 | break; |
| 3804 | } |
| 3805 | case Primitive::kPrimFloat: |
| 3806 | case Primitive::kPrimDouble: { |
| 3807 | __ LoadImmediate(out, 0); |
| 3808 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3809 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3810 | } else { |
| 3811 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3812 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3813 | } |
| 3814 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 3815 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3816 | break; |
| 3817 | } |
| 3818 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3819 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3820 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3821 | __ b(&done, EQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3822 | __ 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] | 3823 | |
| 3824 | __ Bind(&greater); |
| 3825 | __ LoadImmediate(out, 1); |
| 3826 | __ b(&done); |
| 3827 | |
| 3828 | __ Bind(&less); |
| 3829 | __ LoadImmediate(out, -1); |
| 3830 | |
| 3831 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3832 | } |
| 3833 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3834 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3835 | LocationSummary* locations = |
| 3836 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3837 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3838 | locations->SetInAt(i, Location::Any()); |
| 3839 | } |
| 3840 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3841 | } |
| 3842 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3843 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3844 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3845 | } |
| 3846 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3847 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3848 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3849 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3850 | switch (kind) { |
| 3851 | case MemBarrierKind::kAnyStore: |
| 3852 | case MemBarrierKind::kLoadAny: |
| 3853 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3854 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3855 | break; |
| 3856 | } |
| 3857 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3858 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3859 | break; |
| 3860 | } |
| 3861 | default: |
| 3862 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3863 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3864 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3868 | uint32_t offset, |
| 3869 | Register out_lo, |
| 3870 | Register out_hi) { |
| 3871 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3872 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3873 | // `offset` into `out_lo` does not clutter `addr`. |
| 3874 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3875 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3876 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3877 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3878 | } |
| 3879 | __ ldrexd(out_lo, out_hi, addr); |
| 3880 | } |
| 3881 | |
| 3882 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3883 | uint32_t offset, |
| 3884 | Register value_lo, |
| 3885 | Register value_hi, |
| 3886 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3887 | Register temp2, |
| 3888 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3889 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3890 | if (offset != 0) { |
| 3891 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3892 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3893 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3894 | } |
| 3895 | __ Bind(&fail); |
| 3896 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3897 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3898 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3899 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3900 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3901 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3905 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3906 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3907 | LocationSummary* locations = |
| 3908 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3909 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3910 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3911 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3912 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3913 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3914 | } else { |
| 3915 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3916 | } |
| 3917 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3918 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3919 | bool generate_volatile = field_info.IsVolatile() |
| 3920 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3921 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3922 | bool needs_write_barrier = |
| 3923 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3924 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3925 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3926 | if (needs_write_barrier) { |
| 3927 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3928 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3929 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3930 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3931 | // - registers need to be consecutive |
| 3932 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3933 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3934 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3935 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3936 | |
| 3937 | locations->AddTemp(Location::RequiresRegister()); |
| 3938 | locations->AddTemp(Location::RequiresRegister()); |
| 3939 | if (field_type == Primitive::kPrimDouble) { |
| 3940 | // For doubles we need two more registers to copy the value. |
| 3941 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3942 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3943 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3944 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3945 | } |
| 3946 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3947 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3948 | const FieldInfo& field_info, |
| 3949 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3950 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3951 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3952 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3953 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3954 | Location value = locations->InAt(1); |
| 3955 | |
| 3956 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3957 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3958 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3959 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3960 | bool needs_write_barrier = |
| 3961 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3962 | |
| 3963 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3964 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3965 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3966 | |
| 3967 | switch (field_type) { |
| 3968 | case Primitive::kPrimBoolean: |
| 3969 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3970 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3971 | break; |
| 3972 | } |
| 3973 | |
| 3974 | case Primitive::kPrimShort: |
| 3975 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3976 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3977 | break; |
| 3978 | } |
| 3979 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3980 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3981 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3982 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3983 | // Note that in the case where `value` is a null reference, |
| 3984 | // we do not enter this block, as a null reference does not |
| 3985 | // need poisoning. |
| 3986 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3987 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3988 | __ Mov(temp, value.AsRegister<Register>()); |
| 3989 | __ PoisonHeapReference(temp); |
| 3990 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3991 | } else { |
| 3992 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3993 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3994 | break; |
| 3995 | } |
| 3996 | |
| 3997 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3998 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3999 | GenerateWideAtomicStore(base, offset, |
| 4000 | value.AsRegisterPairLow<Register>(), |
| 4001 | value.AsRegisterPairHigh<Register>(), |
| 4002 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4003 | locations->GetTemp(1).AsRegister<Register>(), |
| 4004 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4005 | } else { |
| 4006 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4007 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
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 | break; |
| 4010 | } |
| 4011 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4012 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4013 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4014 | break; |
| 4015 | } |
| 4016 | |
| 4017 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4018 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4019 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4020 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4021 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4022 | |
| 4023 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4024 | |
| 4025 | GenerateWideAtomicStore(base, offset, |
| 4026 | value_reg_lo, |
| 4027 | value_reg_hi, |
| 4028 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4029 | locations->GetTemp(3).AsRegister<Register>(), |
| 4030 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4031 | } else { |
| 4032 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4033 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4034 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4035 | break; |
| 4036 | } |
| 4037 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4038 | case Primitive::kPrimVoid: |
| 4039 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4040 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4041 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4042 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4043 | // Longs and doubles are handled in the switch. |
| 4044 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4045 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4046 | } |
| 4047 | |
| 4048 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4049 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4050 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4051 | codegen_->MarkGCCard( |
| 4052 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4053 | } |
| 4054 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4055 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4056 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4057 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4058 | } |
| 4059 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4060 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4061 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4062 | |
| 4063 | bool object_field_get_with_read_barrier = |
| 4064 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4065 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4066 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4067 | object_field_get_with_read_barrier ? |
| 4068 | LocationSummary::kCallOnSlowPath : |
| 4069 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4070 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4071 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4072 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4073 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4074 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4075 | // The output overlaps in case of volatile long: we don't want the |
| 4076 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4077 | // object's location. Likewise, in the case of an object field get |
| 4078 | // with read barriers enabled, we do not want the load to overwrite |
| 4079 | // the object's location, as we need it to emit the read barrier. |
| 4080 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4081 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4082 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4083 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4084 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4085 | } else { |
| 4086 | locations->SetOut(Location::RequiresRegister(), |
| 4087 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4088 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4089 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4090 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4091 | // - registers need to be consecutive |
| 4092 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4093 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4094 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4095 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4096 | locations->AddTemp(Location::RequiresRegister()); |
| 4097 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4098 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4099 | // We need a temporary register for the read barrier marking slow |
| 4100 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4101 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4102 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4103 | } |
| 4104 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4105 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4106 | Opcode opcode) { |
| 4107 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4108 | if (constant->IsConstant() && |
| 4109 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4110 | return Location::ConstantLocation(constant->AsConstant()); |
| 4111 | } |
| 4112 | return Location::RequiresRegister(); |
| 4113 | } |
| 4114 | |
| 4115 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4116 | Opcode opcode) { |
| 4117 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4118 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 4119 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode) && |
| 4120 | CanEncodeConstantAsImmediate(High32Bits(value), opcode); |
| 4121 | } else { |
| 4122 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode) { |
| 4127 | ShifterOperand so; |
| 4128 | ArmAssembler* assembler = codegen_->GetAssembler(); |
| 4129 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, &so)) { |
| 4130 | return true; |
| 4131 | } |
| 4132 | Opcode neg_opcode = kNoOperand; |
| 4133 | switch (opcode) { |
| 4134 | case AND: |
| 4135 | neg_opcode = BIC; |
| 4136 | break; |
| 4137 | case ORR: |
| 4138 | neg_opcode = ORN; |
| 4139 | break; |
| 4140 | default: |
| 4141 | return false; |
| 4142 | } |
| 4143 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, ~value, &so); |
| 4144 | } |
| 4145 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4146 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4147 | const FieldInfo& field_info) { |
| 4148 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4149 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4150 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4151 | Location base_loc = locations->InAt(0); |
| 4152 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4153 | Location out = locations->Out(); |
| 4154 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4155 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4156 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4157 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4158 | |
| 4159 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4160 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4161 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4162 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4163 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4164 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4165 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4166 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4167 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4168 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4169 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4170 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4171 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4172 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4173 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4174 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4175 | |
| 4176 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4178 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4179 | |
| 4180 | case Primitive::kPrimNot: { |
| 4181 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4182 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4183 | Location temp_loc = locations->GetTemp(0); |
| 4184 | // Note that a potential implicit null check is handled in this |
| 4185 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4186 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4187 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4188 | if (is_volatile) { |
| 4189 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4190 | } |
| 4191 | } else { |
| 4192 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4193 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4194 | if (is_volatile) { |
| 4195 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4196 | } |
| 4197 | // If read barriers are enabled, emit read barriers other than |
| 4198 | // Baker's using a slow path (and also unpoison the loaded |
| 4199 | // reference, if heap poisoning is enabled). |
| 4200 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4201 | } |
| 4202 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4203 | } |
| 4204 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4205 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4206 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4207 | GenerateWideAtomicLoad(base, offset, |
| 4208 | out.AsRegisterPairLow<Register>(), |
| 4209 | out.AsRegisterPairHigh<Register>()); |
| 4210 | } else { |
| 4211 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4212 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4213 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4214 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4215 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4216 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4217 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4218 | |
| 4219 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4220 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4221 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4222 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4223 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4224 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4225 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | __ vmovdrr(out_reg, lo, hi); |
| 4227 | } else { |
| 4228 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4229 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4230 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4234 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4235 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4236 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4237 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4238 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4239 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4240 | // Potential implicit null checks, in the case of reference or |
| 4241 | // double fields, are handled in the previous switch statement. |
| 4242 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4243 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4244 | } |
| 4245 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4246 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4247 | if (field_type == Primitive::kPrimNot) { |
| 4248 | // Memory barriers, in the case of references, are also handled |
| 4249 | // in the previous switch statement. |
| 4250 | } else { |
| 4251 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4252 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4253 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4257 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4258 | } |
| 4259 | |
| 4260 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4261 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4265 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4266 | } |
| 4267 | |
| 4268 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4269 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4270 | } |
| 4271 | |
| 4272 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4273 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4274 | } |
| 4275 | |
| 4276 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4277 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4278 | } |
| 4279 | |
| 4280 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4281 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4282 | } |
| 4283 | |
| 4284 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4285 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4286 | } |
| 4287 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4288 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4289 | HUnresolvedInstanceFieldGet* instruction) { |
| 4290 | FieldAccessCallingConventionARM calling_convention; |
| 4291 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4292 | instruction, instruction->GetFieldType(), calling_convention); |
| 4293 | } |
| 4294 | |
| 4295 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4296 | HUnresolvedInstanceFieldGet* instruction) { |
| 4297 | FieldAccessCallingConventionARM calling_convention; |
| 4298 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4299 | instruction->GetFieldType(), |
| 4300 | instruction->GetFieldIndex(), |
| 4301 | instruction->GetDexPc(), |
| 4302 | calling_convention); |
| 4303 | } |
| 4304 | |
| 4305 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4306 | HUnresolvedInstanceFieldSet* instruction) { |
| 4307 | FieldAccessCallingConventionARM calling_convention; |
| 4308 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4309 | instruction, instruction->GetFieldType(), calling_convention); |
| 4310 | } |
| 4311 | |
| 4312 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4313 | HUnresolvedInstanceFieldSet* instruction) { |
| 4314 | FieldAccessCallingConventionARM calling_convention; |
| 4315 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4316 | instruction->GetFieldType(), |
| 4317 | instruction->GetFieldIndex(), |
| 4318 | instruction->GetDexPc(), |
| 4319 | calling_convention); |
| 4320 | } |
| 4321 | |
| 4322 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4323 | HUnresolvedStaticFieldGet* instruction) { |
| 4324 | FieldAccessCallingConventionARM calling_convention; |
| 4325 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4326 | instruction, instruction->GetFieldType(), calling_convention); |
| 4327 | } |
| 4328 | |
| 4329 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4330 | HUnresolvedStaticFieldGet* instruction) { |
| 4331 | FieldAccessCallingConventionARM calling_convention; |
| 4332 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4333 | instruction->GetFieldType(), |
| 4334 | instruction->GetFieldIndex(), |
| 4335 | instruction->GetDexPc(), |
| 4336 | calling_convention); |
| 4337 | } |
| 4338 | |
| 4339 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4340 | HUnresolvedStaticFieldSet* instruction) { |
| 4341 | FieldAccessCallingConventionARM calling_convention; |
| 4342 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4343 | instruction, instruction->GetFieldType(), calling_convention); |
| 4344 | } |
| 4345 | |
| 4346 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4347 | HUnresolvedStaticFieldSet* instruction) { |
| 4348 | FieldAccessCallingConventionARM calling_convention; |
| 4349 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4350 | instruction->GetFieldType(), |
| 4351 | instruction->GetFieldIndex(), |
| 4352 | instruction->GetDexPc(), |
| 4353 | calling_convention); |
| 4354 | } |
| 4355 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4356 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4357 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4358 | ? LocationSummary::kCallOnSlowPath |
| 4359 | : LocationSummary::kNoCall; |
| 4360 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4361 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4362 | if (instruction->HasUses()) { |
| 4363 | locations->SetOut(Location::SameAsFirstInput()); |
| 4364 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4365 | } |
| 4366 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4367 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4368 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4369 | return; |
| 4370 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4371 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4372 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4373 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 4374 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4375 | } |
| 4376 | |
| 4377 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4378 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4379 | codegen_->AddSlowPath(slow_path); |
| 4380 | |
| 4381 | LocationSummary* locations = instruction->GetLocations(); |
| 4382 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4383 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4384 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4385 | } |
| 4386 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4387 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4388 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4389 | GenerateImplicitNullCheck(instruction); |
| 4390 | } else { |
| 4391 | GenerateExplicitNullCheck(instruction); |
| 4392 | } |
| 4393 | } |
| 4394 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4395 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4396 | bool object_array_get_with_read_barrier = |
| 4397 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4398 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4399 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4400 | object_array_get_with_read_barrier ? |
| 4401 | LocationSummary::kCallOnSlowPath : |
| 4402 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4404 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4405 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4406 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4407 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4408 | // The output overlaps in the case of an object array get with |
| 4409 | // read barriers enabled: we do not want the move to overwrite the |
| 4410 | // array's location, as we need it to emit the read barrier. |
| 4411 | locations->SetOut( |
| 4412 | Location::RequiresRegister(), |
| 4413 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4414 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4415 | // We need a temporary register for the read barrier marking slow |
| 4416 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4417 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4418 | locations->AddTemp(Location::RequiresRegister()); |
| 4419 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4423 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4424 | Location obj_loc = locations->InAt(0); |
| 4425 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4426 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4427 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4428 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4429 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4430 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4431 | case Primitive::kPrimBoolean: { |
| 4432 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4433 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4434 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4435 | size_t offset = |
| 4436 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4437 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 4438 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4439 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4440 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 4441 | } |
| 4442 | break; |
| 4443 | } |
| 4444 | |
| 4445 | case Primitive::kPrimByte: { |
| 4446 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4447 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4448 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4449 | size_t offset = |
| 4450 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4451 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 4452 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4453 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4454 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 4455 | } |
| 4456 | break; |
| 4457 | } |
| 4458 | |
| 4459 | case Primitive::kPrimShort: { |
| 4460 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4461 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4462 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4463 | size_t offset = |
| 4464 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4465 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 4466 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4467 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4468 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 4469 | } |
| 4470 | break; |
| 4471 | } |
| 4472 | |
| 4473 | case Primitive::kPrimChar: { |
| 4474 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4475 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4476 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4477 | size_t offset = |
| 4478 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4479 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 4480 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4481 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4482 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 4483 | } |
| 4484 | break; |
| 4485 | } |
| 4486 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4487 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4488 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4489 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4490 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4491 | size_t offset = |
| 4492 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4493 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4494 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4495 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4496 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4497 | } |
| 4498 | break; |
| 4499 | } |
| 4500 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4501 | case Primitive::kPrimNot: { |
| 4502 | static_assert( |
| 4503 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4504 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4505 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4506 | // /* HeapReference<Object> */ out = |
| 4507 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4508 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4509 | Location temp = locations->GetTemp(0); |
| 4510 | // Note that a potential implicit null check is handled in this |
| 4511 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4512 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4513 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4514 | } else { |
| 4515 | Register out = out_loc.AsRegister<Register>(); |
| 4516 | if (index.IsConstant()) { |
| 4517 | size_t offset = |
| 4518 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4519 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4521 | // If read barriers are enabled, emit read barriers other than |
| 4522 | // Baker's using a slow path (and also unpoison the loaded |
| 4523 | // reference, if heap poisoning is enabled). |
| 4524 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4525 | } else { |
| 4526 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4527 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4528 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4529 | // If read barriers are enabled, emit read barriers other than |
| 4530 | // Baker's using a slow path (and also unpoison the loaded |
| 4531 | // reference, if heap poisoning is enabled). |
| 4532 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4533 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4534 | } |
| 4535 | } |
| 4536 | break; |
| 4537 | } |
| 4538 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4539 | case Primitive::kPrimLong: { |
| 4540 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4541 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4542 | size_t offset = |
| 4543 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4544 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4545 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4546 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4547 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4548 | } |
| 4549 | break; |
| 4550 | } |
| 4551 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4552 | case Primitive::kPrimFloat: { |
| 4553 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4554 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4555 | if (index.IsConstant()) { |
| 4556 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4557 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4558 | } else { |
| 4559 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4560 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4561 | } |
| 4562 | break; |
| 4563 | } |
| 4564 | |
| 4565 | case Primitive::kPrimDouble: { |
| 4566 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4567 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4568 | if (index.IsConstant()) { |
| 4569 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4570 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4571 | } else { |
| 4572 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4573 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4574 | } |
| 4575 | break; |
| 4576 | } |
| 4577 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4578 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4579 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4580 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4581 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4582 | |
| 4583 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4584 | // Potential implicit null checks, in the case of reference |
| 4585 | // arrays, are handled in the previous switch statement. |
| 4586 | } else { |
| 4587 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4588 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4592 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4593 | |
| 4594 | bool needs_write_barrier = |
| 4595 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4596 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 4597 | bool object_array_set_with_read_barrier = |
| 4598 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4599 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4600 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4601 | instruction, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4602 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 4603 | LocationSummary::kCallOnSlowPath : |
| 4604 | LocationSummary::kNoCall); |
| 4605 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4606 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4607 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4608 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4609 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4611 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4612 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4613 | if (needs_write_barrier) { |
| 4614 | // Temporary registers for the write barrier. |
| 4615 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4616 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4617 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4621 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4622 | Location array_loc = locations->InAt(0); |
| 4623 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4624 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4625 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4626 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4627 | bool needs_write_barrier = |
| 4628 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4629 | |
| 4630 | switch (value_type) { |
| 4631 | case Primitive::kPrimBoolean: |
| 4632 | case Primitive::kPrimByte: { |
| 4633 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4634 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4635 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4636 | size_t offset = |
| 4637 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4638 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4639 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4640 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4641 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 4642 | } |
| 4643 | break; |
| 4644 | } |
| 4645 | |
| 4646 | case Primitive::kPrimShort: |
| 4647 | case Primitive::kPrimChar: { |
| 4648 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4649 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4650 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4651 | size_t offset = |
| 4652 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4653 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4654 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4655 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4656 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 4657 | } |
| 4658 | break; |
| 4659 | } |
| 4660 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4661 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4662 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4663 | Location value_loc = locations->InAt(2); |
| 4664 | Register value = value_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4665 | Register source = value; |
| 4666 | |
| 4667 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4668 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4669 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4670 | size_t offset = |
| 4671 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4672 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4673 | } else { |
| 4674 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4675 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4676 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4677 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4678 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4679 | DCHECK(!needs_write_barrier); |
| 4680 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4681 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4682 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4683 | |
| 4684 | DCHECK(needs_write_barrier); |
| 4685 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4686 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4687 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4688 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4689 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4690 | Label done; |
| 4691 | SlowPathCode* slow_path = nullptr; |
| 4692 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4693 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4694 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4695 | codegen_->AddSlowPath(slow_path); |
| 4696 | if (instruction->GetValueCanBeNull()) { |
| 4697 | Label non_zero; |
| 4698 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4699 | if (index.IsConstant()) { |
| 4700 | size_t offset = |
| 4701 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4702 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4703 | } else { |
| 4704 | DCHECK(index.IsRegister()) << index; |
| 4705 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4706 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4707 | } |
| 4708 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4709 | __ b(&done); |
| 4710 | __ Bind(&non_zero); |
| 4711 | } |
| 4712 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4713 | if (kEmitCompilerReadBarrier) { |
| 4714 | // When read barriers are enabled, the type checking |
| 4715 | // instrumentation requires two read barriers: |
| 4716 | // |
| 4717 | // __ Mov(temp2, temp1); |
| 4718 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4719 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4720 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4721 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4722 | // |
| 4723 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4724 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4725 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4726 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4727 | // |
| 4728 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4729 | // |
| 4730 | // However, the second read barrier may trash `temp`, as it |
| 4731 | // is a temporary register, and as such would not be saved |
| 4732 | // along with live registers before calling the runtime (nor |
| 4733 | // restored afterwards). So in this case, we bail out and |
| 4734 | // delegate the work to the array set slow path. |
| 4735 | // |
| 4736 | // TODO: Extend the register allocator to support a new |
| 4737 | // "(locally) live temp" location so as to avoid always |
| 4738 | // going into the slow path when read barriers are enabled. |
| 4739 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4740 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4741 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4742 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4743 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4744 | __ MaybeUnpoisonHeapReference(temp1); |
| 4745 | |
| 4746 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4747 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4748 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4749 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4750 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4751 | // nor `temp2`, as we are comparing two poisoned references. |
| 4752 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4753 | |
| 4754 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4755 | Label do_put; |
| 4756 | __ b(&do_put, EQ); |
| 4757 | // If heap poisoning is enabled, the `temp1` reference has |
| 4758 | // not been unpoisoned yet; unpoison it now. |
| 4759 | __ MaybeUnpoisonHeapReference(temp1); |
| 4760 | |
| 4761 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4762 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4763 | // If heap poisoning is enabled, no need to unpoison |
| 4764 | // `temp1`, as we are comparing against null below. |
| 4765 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4766 | __ Bind(&do_put); |
| 4767 | } else { |
| 4768 | __ b(slow_path->GetEntryLabel(), NE); |
| 4769 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | if (kPoisonHeapReferences) { |
| 4774 | // Note that in the case where `value` is a null reference, |
| 4775 | // we do not enter this block, as a null reference does not |
| 4776 | // need poisoning. |
| 4777 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4778 | __ Mov(temp1, value); |
| 4779 | __ PoisonHeapReference(temp1); |
| 4780 | source = temp1; |
| 4781 | } |
| 4782 | |
| 4783 | if (index.IsConstant()) { |
| 4784 | size_t offset = |
| 4785 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4786 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4787 | } else { |
| 4788 | DCHECK(index.IsRegister()) << index; |
| 4789 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4790 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4791 | } |
| 4792 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4793 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4794 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4795 | } |
| 4796 | |
| 4797 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4798 | |
| 4799 | if (done.IsLinked()) { |
| 4800 | __ Bind(&done); |
| 4801 | } |
| 4802 | |
| 4803 | if (slow_path != nullptr) { |
| 4804 | __ Bind(slow_path->GetExitLabel()); |
| 4805 | } |
| 4806 | |
| 4807 | break; |
| 4808 | } |
| 4809 | |
| 4810 | case Primitive::kPrimInt: { |
| 4811 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4812 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4813 | if (index.IsConstant()) { |
| 4814 | size_t offset = |
| 4815 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4816 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4817 | } else { |
| 4818 | DCHECK(index.IsRegister()) << index; |
| 4819 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4820 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4821 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4822 | break; |
| 4823 | } |
| 4824 | |
| 4825 | case Primitive::kPrimLong: { |
| 4826 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4827 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4828 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4829 | size_t offset = |
| 4830 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4831 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4832 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4833 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4834 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4835 | } |
| 4836 | break; |
| 4837 | } |
| 4838 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4839 | case Primitive::kPrimFloat: { |
| 4840 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4841 | Location value = locations->InAt(2); |
| 4842 | DCHECK(value.IsFpuRegister()); |
| 4843 | if (index.IsConstant()) { |
| 4844 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4845 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4846 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4847 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4848 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4849 | } |
| 4850 | break; |
| 4851 | } |
| 4852 | |
| 4853 | case Primitive::kPrimDouble: { |
| 4854 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4855 | Location value = locations->InAt(2); |
| 4856 | DCHECK(value.IsFpuRegisterPair()); |
| 4857 | if (index.IsConstant()) { |
| 4858 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4859 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4860 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4861 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4862 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4863 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4864 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4865 | break; |
| 4866 | } |
| 4867 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4868 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4869 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4870 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4871 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4872 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 4873 | // Objects are handled in the switch. |
| 4874 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4875 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4876 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4880 | LocationSummary* locations = |
| 4881 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4882 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4883 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4887 | LocationSummary* locations = instruction->GetLocations(); |
| 4888 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4889 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4890 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4891 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4892 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4893 | } |
| 4894 | |
| 4895 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4896 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4897 | ? LocationSummary::kCallOnSlowPath |
| 4898 | : LocationSummary::kNoCall; |
| 4899 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4900 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4901 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4902 | if (instruction->HasUses()) { |
| 4903 | locations->SetOut(Location::SameAsFirstInput()); |
| 4904 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4908 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4909 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4910 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4911 | codegen_->AddSlowPath(slow_path); |
| 4912 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4913 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4914 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4915 | |
| 4916 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4917 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4918 | } |
| 4919 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4920 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4921 | Register card, |
| 4922 | Register object, |
| 4923 | Register value, |
| 4924 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4925 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4926 | if (can_be_null) { |
| 4927 | __ CompareAndBranchIfZero(value, &is_null); |
| 4928 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4929 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4930 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4931 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4932 | if (can_be_null) { |
| 4933 | __ Bind(&is_null); |
| 4934 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4935 | } |
| 4936 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4937 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 4938 | temp->SetLocations(nullptr); |
| 4939 | } |
| 4940 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4941 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4942 | // Nothing to do, this is driven by the code generator. |
| 4943 | } |
| 4944 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4945 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4946 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4950 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4951 | } |
| 4952 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4953 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4954 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4955 | } |
| 4956 | |
| 4957 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4958 | HBasicBlock* block = instruction->GetBlock(); |
| 4959 | if (block->GetLoopInformation() != nullptr) { |
| 4960 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4961 | // The back edge will generate the suspend check. |
| 4962 | return; |
| 4963 | } |
| 4964 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4965 | // The goto will generate the suspend check. |
| 4966 | return; |
| 4967 | } |
| 4968 | GenerateSuspendCheck(instruction, nullptr); |
| 4969 | } |
| 4970 | |
| 4971 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4972 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4973 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4974 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4975 | if (slow_path == nullptr) { |
| 4976 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4977 | instruction->SetSlowPath(slow_path); |
| 4978 | codegen_->AddSlowPath(slow_path); |
| 4979 | if (successor != nullptr) { |
| 4980 | DCHECK(successor->IsLoopHeader()); |
| 4981 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4982 | } |
| 4983 | } else { |
| 4984 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4985 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4986 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4987 | __ LoadFromOffset( |
| 4988 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4989 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4990 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4991 | __ Bind(slow_path->GetReturnLabel()); |
| 4992 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4993 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4994 | __ b(slow_path->GetEntryLabel()); |
| 4995 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4998 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4999 | return codegen_->GetAssembler(); |
| 5000 | } |
| 5001 | |
| 5002 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5003 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5004 | Location source = move->GetSource(); |
| 5005 | Location destination = move->GetDestination(); |
| 5006 | |
| 5007 | if (source.IsRegister()) { |
| 5008 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5009 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5010 | } else { |
| 5011 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5012 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5013 | SP, destination.GetStackIndex()); |
| 5014 | } |
| 5015 | } else if (source.IsStackSlot()) { |
| 5016 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5017 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5018 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5019 | } else if (destination.IsFpuRegister()) { |
| 5020 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5021 | } else { |
| 5022 | DCHECK(destination.IsStackSlot()); |
| 5023 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5024 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5025 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5026 | } else if (source.IsFpuRegister()) { |
| 5027 | if (destination.IsFpuRegister()) { |
| 5028 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5029 | } else { |
| 5030 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5031 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5032 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5033 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5034 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5035 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5036 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5037 | } else if (destination.IsRegisterPair()) { |
| 5038 | DCHECK(ExpectedPairLayout(destination)); |
| 5039 | __ LoadFromOffset( |
| 5040 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5041 | } else { |
| 5042 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5043 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5044 | SP, |
| 5045 | source.GetStackIndex()); |
| 5046 | } |
| 5047 | } else if (source.IsRegisterPair()) { |
| 5048 | if (destination.IsRegisterPair()) { |
| 5049 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5050 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 5051 | } else { |
| 5052 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5053 | DCHECK(ExpectedPairLayout(source)); |
| 5054 | __ StoreToOffset( |
| 5055 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5056 | } |
| 5057 | } else if (source.IsFpuRegisterPair()) { |
| 5058 | if (destination.IsFpuRegisterPair()) { |
| 5059 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5060 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5061 | } else { |
| 5062 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5063 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5064 | SP, |
| 5065 | destination.GetStackIndex()); |
| 5066 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5067 | } else { |
| 5068 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5069 | HConstant* constant = source.GetConstant(); |
| 5070 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5071 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5072 | if (destination.IsRegister()) { |
| 5073 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5074 | } else { |
| 5075 | DCHECK(destination.IsStackSlot()); |
| 5076 | __ LoadImmediate(IP, value); |
| 5077 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5078 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5079 | } else if (constant->IsLongConstant()) { |
| 5080 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5081 | if (destination.IsRegisterPair()) { |
| 5082 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5083 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5084 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5085 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5086 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5087 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5088 | __ LoadImmediate(IP, High32Bits(value)); |
| 5089 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5090 | } |
| 5091 | } else if (constant->IsDoubleConstant()) { |
| 5092 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5093 | if (destination.IsFpuRegisterPair()) { |
| 5094 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5095 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5096 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5097 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5098 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5099 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5100 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5101 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5102 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5103 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5104 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5105 | float value = constant->AsFloatConstant()->GetValue(); |
| 5106 | if (destination.IsFpuRegister()) { |
| 5107 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5108 | } else { |
| 5109 | DCHECK(destination.IsStackSlot()); |
| 5110 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5111 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5112 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5113 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5114 | } |
| 5115 | } |
| 5116 | |
| 5117 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5118 | __ Mov(IP, reg); |
| 5119 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5120 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5121 | } |
| 5122 | |
| 5123 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5124 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5125 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5126 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5127 | SP, mem1 + stack_offset); |
| 5128 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5129 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5130 | SP, mem2 + stack_offset); |
| 5131 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5132 | } |
| 5133 | |
| 5134 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5135 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5136 | Location source = move->GetSource(); |
| 5137 | Location destination = move->GetDestination(); |
| 5138 | |
| 5139 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5140 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5141 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5142 | __ Mov(IP, source.AsRegister<Register>()); |
| 5143 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5144 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5145 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5146 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5147 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5148 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5149 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5150 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5151 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5152 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5153 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5154 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5155 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5156 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5157 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5158 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5159 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5160 | destination.AsRegisterPairHigh<Register>(), |
| 5161 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5162 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5163 | Register low_reg = source.IsRegisterPair() |
| 5164 | ? source.AsRegisterPairLow<Register>() |
| 5165 | : destination.AsRegisterPairLow<Register>(); |
| 5166 | int mem = source.IsRegisterPair() |
| 5167 | ? destination.GetStackIndex() |
| 5168 | : source.GetStackIndex(); |
| 5169 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5170 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5171 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5172 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5173 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5174 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5175 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5176 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5177 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5178 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5179 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5180 | DRegister reg = source.IsFpuRegisterPair() |
| 5181 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5182 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5183 | int mem = source.IsFpuRegisterPair() |
| 5184 | ? destination.GetStackIndex() |
| 5185 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5186 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5187 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5188 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5189 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5190 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5191 | : destination.AsFpuRegister<SRegister>(); |
| 5192 | int mem = source.IsFpuRegister() |
| 5193 | ? destination.GetStackIndex() |
| 5194 | : source.GetStackIndex(); |
| 5195 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5196 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5197 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5198 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5199 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5200 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5201 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5202 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5203 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5208 | __ Push(static_cast<Register>(reg)); |
| 5209 | } |
| 5210 | |
| 5211 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5212 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5213 | } |
| 5214 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5215 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5216 | InvokeRuntimeCallingConvention calling_convention; |
| 5217 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5218 | cls, |
| 5219 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5220 | Location::RegisterLocation(R0), |
| 5221 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5225 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5226 | if (cls->NeedsAccessCheck()) { |
| 5227 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5228 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5229 | cls, |
| 5230 | cls->GetDexPc(), |
| 5231 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5232 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5233 | return; |
| 5234 | } |
| 5235 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5236 | Location out_loc = locations->Out(); |
| 5237 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5238 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5239 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5240 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5241 | DCHECK(!cls->CanCallRuntime()); |
| 5242 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5243 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5244 | GenerateGcRootFieldLoad( |
| 5245 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5246 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5247 | // /* GcRoot<mirror::Class>[] */ out = |
| 5248 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5249 | __ LoadFromOffset(kLoadWord, |
| 5250 | out, |
| 5251 | current_method, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5252 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5253 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5254 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5255 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5256 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5257 | DCHECK(cls->CanCallRuntime()); |
| 5258 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 5259 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5260 | codegen_->AddSlowPath(slow_path); |
| 5261 | if (!cls->IsInDexCache()) { |
| 5262 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5263 | } |
| 5264 | if (cls->MustGenerateClinitCheck()) { |
| 5265 | GenerateClassInitializationCheck(slow_path, out); |
| 5266 | } else { |
| 5267 | __ Bind(slow_path->GetExitLabel()); |
| 5268 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5269 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5270 | } |
| 5271 | } |
| 5272 | |
| 5273 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5274 | LocationSummary* locations = |
| 5275 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5277 | if (check->HasUses()) { |
| 5278 | locations->SetOut(Location::SameAsFirstInput()); |
| 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5283 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5284 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5285 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5286 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5287 | GenerateClassInitializationCheck(slow_path, |
| 5288 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5289 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5290 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5291 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5292 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5293 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5294 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5295 | __ b(slow_path->GetEntryLabel(), LT); |
| 5296 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5297 | // properly. Therefore, we do a memory fence. |
| 5298 | __ dmb(ISH); |
| 5299 | __ Bind(slow_path->GetExitLabel()); |
| 5300 | } |
| 5301 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5302 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5303 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5304 | ? LocationSummary::kCallOnSlowPath |
| 5305 | : LocationSummary::kNoCall; |
| 5306 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5307 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5308 | locations->SetOut(Location::RequiresRegister()); |
| 5309 | } |
| 5310 | |
| 5311 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5312 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5313 | Location out_loc = locations->Out(); |
| 5314 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5315 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5316 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5317 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5318 | GenerateGcRootFieldLoad( |
| 5319 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5320 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5321 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5322 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5323 | GenerateGcRootFieldLoad( |
| 5324 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5325 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5326 | if (!load->IsInDexCache()) { |
| 5327 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5328 | codegen_->AddSlowPath(slow_path); |
| 5329 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5330 | __ Bind(slow_path->GetExitLabel()); |
| 5331 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5332 | } |
| 5333 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5334 | static int32_t GetExceptionTlsOffset() { |
| 5335 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 5336 | } |
| 5337 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5338 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5339 | LocationSummary* locations = |
| 5340 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5341 | locations->SetOut(Location::RequiresRegister()); |
| 5342 | } |
| 5343 | |
| 5344 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5345 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5346 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5347 | } |
| 5348 | |
| 5349 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5350 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5351 | } |
| 5352 | |
| 5353 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5354 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5355 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5359 | LocationSummary* locations = |
| 5360 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5361 | InvokeRuntimeCallingConvention calling_convention; |
| 5362 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5363 | } |
| 5364 | |
| 5365 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 5366 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5367 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5368 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5369 | } |
| 5370 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5371 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5372 | return kEmitCompilerReadBarrier && |
| 5373 | (kUseBakerReadBarrier || |
| 5374 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5375 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5376 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5377 | } |
| 5378 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5379 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5380 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5381 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5382 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5383 | case TypeCheckKind::kExactCheck: |
| 5384 | case TypeCheckKind::kAbstractClassCheck: |
| 5385 | case TypeCheckKind::kClassHierarchyCheck: |
| 5386 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5387 | call_kind = |
| 5388 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5389 | break; |
| 5390 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5391 | case TypeCheckKind::kUnresolvedCheck: |
| 5392 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5393 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5394 | break; |
| 5395 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5396 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5397 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5399 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5400 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5401 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5402 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5403 | // When read barriers are enabled, we need a temporary register for |
| 5404 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5405 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5406 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5407 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5410 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5411 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5412 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5413 | Location obj_loc = locations->InAt(0); |
| 5414 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5415 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5416 | Location out_loc = locations->Out(); |
| 5417 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5418 | Location temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5419 | locations->GetTemp(0) : |
| 5420 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5421 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5422 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5423 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5424 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5425 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5426 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5427 | |
| 5428 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5429 | // avoid null check if we know obj is not null. |
| 5430 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5431 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5432 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5433 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5434 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5435 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5436 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5437 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5438 | case TypeCheckKind::kExactCheck: { |
| 5439 | __ cmp(out, ShifterOperand(cls)); |
| 5440 | // Classes must be equal for the instanceof to succeed. |
| 5441 | __ b(&zero, NE); |
| 5442 | __ LoadImmediate(out, 1); |
| 5443 | __ b(&done); |
| 5444 | break; |
| 5445 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5446 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5447 | case TypeCheckKind::kAbstractClassCheck: { |
| 5448 | // If the class is abstract, we eagerly fetch the super class of the |
| 5449 | // object to avoid doing a comparison we know will fail. |
| 5450 | Label loop; |
| 5451 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5452 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5453 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5454 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5455 | __ CompareAndBranchIfZero(out, &done); |
| 5456 | __ cmp(out, ShifterOperand(cls)); |
| 5457 | __ b(&loop, NE); |
| 5458 | __ LoadImmediate(out, 1); |
| 5459 | if (zero.IsLinked()) { |
| 5460 | __ b(&done); |
| 5461 | } |
| 5462 | break; |
| 5463 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5464 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5465 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5466 | // Walk over the class hierarchy to find a match. |
| 5467 | Label loop, success; |
| 5468 | __ Bind(&loop); |
| 5469 | __ cmp(out, ShifterOperand(cls)); |
| 5470 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5471 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5472 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5473 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5474 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5475 | __ b(&done); |
| 5476 | __ Bind(&success); |
| 5477 | __ LoadImmediate(out, 1); |
| 5478 | if (zero.IsLinked()) { |
| 5479 | __ b(&done); |
| 5480 | } |
| 5481 | break; |
| 5482 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5483 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5484 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5485 | // Do an exact check. |
| 5486 | Label exact_check; |
| 5487 | __ cmp(out, ShifterOperand(cls)); |
| 5488 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5489 | // 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] | 5490 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5491 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5492 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5493 | __ CompareAndBranchIfZero(out, &done); |
| 5494 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5495 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5496 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5497 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5498 | __ LoadImmediate(out, 1); |
| 5499 | __ b(&done); |
| 5500 | break; |
| 5501 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5502 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5503 | case TypeCheckKind::kArrayCheck: { |
| 5504 | __ cmp(out, ShifterOperand(cls)); |
| 5505 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5506 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5507 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5508 | codegen_->AddSlowPath(slow_path); |
| 5509 | __ b(slow_path->GetEntryLabel(), NE); |
| 5510 | __ LoadImmediate(out, 1); |
| 5511 | if (zero.IsLinked()) { |
| 5512 | __ b(&done); |
| 5513 | } |
| 5514 | break; |
| 5515 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5516 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5517 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5518 | case TypeCheckKind::kInterfaceCheck: { |
| 5519 | // Note that we indeed only call on slow path, but we always go |
| 5520 | // into the slow path for the unresolved & interface check |
| 5521 | // cases. |
| 5522 | // |
| 5523 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5524 | // entry point without resorting to a type checking slow path |
| 5525 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5526 | // require to assign fixed registers for the inputs of this |
| 5527 | // HInstanceOf instruction (following the runtime calling |
| 5528 | // convention), which might be cluttered by the potential first |
| 5529 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5530 | // |
| 5531 | // TODO: Introduce a new runtime entry point taking the object |
| 5532 | // to test (instead of its class) as argument, and let it deal |
| 5533 | // with the read barrier issues. This will let us refactor this |
| 5534 | // case of the `switch` code as it was previously (with a direct |
| 5535 | // call to the runtime not using a type checking slow path). |
| 5536 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5537 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5538 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5539 | /* is_fatal */ false); |
| 5540 | codegen_->AddSlowPath(slow_path); |
| 5541 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5542 | if (zero.IsLinked()) { |
| 5543 | __ b(&done); |
| 5544 | } |
| 5545 | break; |
| 5546 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5547 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5548 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5549 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5550 | __ Bind(&zero); |
| 5551 | __ LoadImmediate(out, 0); |
| 5552 | } |
| 5553 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5554 | if (done.IsLinked()) { |
| 5555 | __ Bind(&done); |
| 5556 | } |
| 5557 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5558 | if (slow_path != nullptr) { |
| 5559 | __ Bind(slow_path->GetExitLabel()); |
| 5560 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5563 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5564 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5565 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5566 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5567 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5568 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5569 | case TypeCheckKind::kExactCheck: |
| 5570 | case TypeCheckKind::kAbstractClassCheck: |
| 5571 | case TypeCheckKind::kClassHierarchyCheck: |
| 5572 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5573 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5574 | LocationSummary::kCallOnSlowPath : |
| 5575 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5576 | break; |
| 5577 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5578 | case TypeCheckKind::kUnresolvedCheck: |
| 5579 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5580 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5581 | break; |
| 5582 | } |
| 5583 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5584 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5585 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5586 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5587 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5588 | locations->AddTemp(Location::RequiresRegister()); |
| 5589 | // When read barriers are enabled, we need an additional temporary |
| 5590 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5591 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5592 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5593 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5597 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5598 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5599 | Location obj_loc = locations->InAt(0); |
| 5600 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5601 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5602 | Location temp_loc = locations->GetTemp(0); |
| 5603 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5604 | Location temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5605 | locations->GetTemp(1) : |
| 5606 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5607 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5608 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5609 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5610 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5611 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5612 | bool is_type_check_slow_path_fatal = |
| 5613 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5614 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5615 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5616 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5617 | !instruction->CanThrowIntoCatchBlock(); |
| 5618 | SlowPathCode* type_check_slow_path = |
| 5619 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5620 | is_type_check_slow_path_fatal); |
| 5621 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5622 | |
| 5623 | Label done; |
| 5624 | // Avoid null check if we know obj is not null. |
| 5625 | if (instruction->MustDoNullCheck()) { |
| 5626 | __ CompareAndBranchIfZero(obj, &done); |
| 5627 | } |
| 5628 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5629 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5630 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5631 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5632 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5633 | case TypeCheckKind::kExactCheck: |
| 5634 | case TypeCheckKind::kArrayCheck: { |
| 5635 | __ cmp(temp, ShifterOperand(cls)); |
| 5636 | // Jump to slow path for throwing the exception or doing a |
| 5637 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5638 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5639 | break; |
| 5640 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5641 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5642 | case TypeCheckKind::kAbstractClassCheck: { |
| 5643 | // If the class is abstract, we eagerly fetch the super class of the |
| 5644 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5645 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5646 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5647 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5648 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5649 | |
| 5650 | // If the class reference currently in `temp` is not null, jump |
| 5651 | // to the `compare_classes` label to compare it with the checked |
| 5652 | // class. |
| 5653 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5654 | // Otherwise, jump to the slow path to throw the exception. |
| 5655 | // |
| 5656 | // But before, move back the object's class into `temp` before |
| 5657 | // going into the slow path, as it has been overwritten in the |
| 5658 | // meantime. |
| 5659 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5660 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5661 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5662 | |
| 5663 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5664 | __ cmp(temp, ShifterOperand(cls)); |
| 5665 | __ b(&loop, NE); |
| 5666 | break; |
| 5667 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5668 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5669 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5670 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5671 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5672 | __ Bind(&loop); |
| 5673 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5674 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5675 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5676 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5677 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5678 | |
| 5679 | // If the class reference currently in `temp` is not null, jump |
| 5680 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5681 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5682 | // Otherwise, jump to the slow path to throw the exception. |
| 5683 | // |
| 5684 | // But before, move back the object's class into `temp` before |
| 5685 | // going into the slow path, as it has been overwritten in the |
| 5686 | // meantime. |
| 5687 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5688 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5689 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5690 | break; |
| 5691 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5692 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5693 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5694 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5695 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5696 | __ cmp(temp, ShifterOperand(cls)); |
| 5697 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5698 | |
| 5699 | // 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] | 5700 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5701 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5702 | |
| 5703 | // If the component type is not null (i.e. the object is indeed |
| 5704 | // an array), jump to label `check_non_primitive_component_type` |
| 5705 | // to further check that this component type is not a primitive |
| 5706 | // type. |
| 5707 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 5708 | // Otherwise, jump to the slow path to throw the exception. |
| 5709 | // |
| 5710 | // But before, move back the object's class into `temp` before |
| 5711 | // going into the slow path, as it has been overwritten in the |
| 5712 | // meantime. |
| 5713 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5714 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5715 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5716 | |
| 5717 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5718 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5719 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 5720 | __ CompareAndBranchIfZero(temp, &done); |
| 5721 | // Same comment as above regarding `temp` and the slow path. |
| 5722 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5723 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5724 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5725 | break; |
| 5726 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5727 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5728 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5729 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5730 | // We always go into the type check slow path for the unresolved & |
| 5731 | // interface check cases. |
| 5732 | // |
| 5733 | // We cannot directly call the CheckCast runtime entry point |
| 5734 | // without resorting to a type checking slow path here (i.e. by |
| 5735 | // calling InvokeRuntime directly), as it would require to |
| 5736 | // assign fixed registers for the inputs of this HInstanceOf |
| 5737 | // instruction (following the runtime calling convention), which |
| 5738 | // might be cluttered by the potential first read barrier |
| 5739 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5740 | // |
| 5741 | // TODO: Introduce a new runtime entry point taking the object |
| 5742 | // to test (instead of its class) as argument, and let it deal |
| 5743 | // with the read barrier issues. This will let us refactor this |
| 5744 | // case of the `switch` code as it was previously (with a direct |
| 5745 | // call to the runtime not using a type checking slow path). |
| 5746 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5747 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5748 | break; |
| 5749 | } |
| 5750 | __ Bind(&done); |
| 5751 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5752 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5753 | } |
| 5754 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5755 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5756 | LocationSummary* locations = |
| 5757 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5758 | InvokeRuntimeCallingConvention calling_convention; |
| 5759 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5760 | } |
| 5761 | |
| 5762 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5763 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 5764 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 5765 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5766 | instruction->GetDexPc(), |
| 5767 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5768 | if (instruction->IsEnter()) { |
| 5769 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5770 | } else { |
| 5771 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5772 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5773 | } |
| 5774 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5775 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 5776 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 5777 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5778 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5779 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5780 | LocationSummary* locations = |
| 5781 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5782 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5783 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5784 | // 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] | 5785 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5786 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5787 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 5791 | HandleBitwiseOperation(instruction); |
| 5792 | } |
| 5793 | |
| 5794 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 5795 | HandleBitwiseOperation(instruction); |
| 5796 | } |
| 5797 | |
| 5798 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 5799 | HandleBitwiseOperation(instruction); |
| 5800 | } |
| 5801 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5802 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 5803 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 5804 | if (value == 0xffffffffu) { |
| 5805 | if (out != first) { |
| 5806 | __ mov(out, ShifterOperand(first)); |
| 5807 | } |
| 5808 | return; |
| 5809 | } |
| 5810 | if (value == 0u) { |
| 5811 | __ mov(out, ShifterOperand(0)); |
| 5812 | return; |
| 5813 | } |
| 5814 | ShifterOperand so; |
| 5815 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 5816 | __ and_(out, first, so); |
| 5817 | } else { |
| 5818 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 5819 | __ bic(out, first, ShifterOperand(~value)); |
| 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 5824 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 5825 | if (value == 0u) { |
| 5826 | if (out != first) { |
| 5827 | __ mov(out, ShifterOperand(first)); |
| 5828 | } |
| 5829 | return; |
| 5830 | } |
| 5831 | if (value == 0xffffffffu) { |
| 5832 | __ mvn(out, ShifterOperand(0)); |
| 5833 | return; |
| 5834 | } |
| 5835 | ShifterOperand so; |
| 5836 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 5837 | __ orr(out, first, so); |
| 5838 | } else { |
| 5839 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 5840 | __ orn(out, first, ShifterOperand(~value)); |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 5845 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 5846 | if (value == 0u) { |
| 5847 | if (out != first) { |
| 5848 | __ mov(out, ShifterOperand(first)); |
| 5849 | } |
| 5850 | return; |
| 5851 | } |
| 5852 | __ eor(out, first, ShifterOperand(value)); |
| 5853 | } |
| 5854 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5855 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5856 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5857 | Location first = locations->InAt(0); |
| 5858 | Location second = locations->InAt(1); |
| 5859 | Location out = locations->Out(); |
| 5860 | |
| 5861 | if (second.IsConstant()) { |
| 5862 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 5863 | uint32_t value_low = Low32Bits(value); |
| 5864 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5865 | Register first_reg = first.AsRegister<Register>(); |
| 5866 | Register out_reg = out.AsRegister<Register>(); |
| 5867 | if (instruction->IsAnd()) { |
| 5868 | GenerateAndConst(out_reg, first_reg, value_low); |
| 5869 | } else if (instruction->IsOr()) { |
| 5870 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 5871 | } else { |
| 5872 | DCHECK(instruction->IsXor()); |
| 5873 | GenerateEorConst(out_reg, first_reg, value_low); |
| 5874 | } |
| 5875 | } else { |
| 5876 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5877 | uint32_t value_high = High32Bits(value); |
| 5878 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5879 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5880 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5881 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5882 | if (instruction->IsAnd()) { |
| 5883 | GenerateAndConst(out_low, first_low, value_low); |
| 5884 | GenerateAndConst(out_high, first_high, value_high); |
| 5885 | } else if (instruction->IsOr()) { |
| 5886 | GenerateOrrConst(out_low, first_low, value_low); |
| 5887 | GenerateOrrConst(out_high, first_high, value_high); |
| 5888 | } else { |
| 5889 | DCHECK(instruction->IsXor()); |
| 5890 | GenerateEorConst(out_low, first_low, value_low); |
| 5891 | GenerateEorConst(out_high, first_high, value_high); |
| 5892 | } |
| 5893 | } |
| 5894 | return; |
| 5895 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5896 | |
| 5897 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5898 | Register first_reg = first.AsRegister<Register>(); |
| 5899 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 5900 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5901 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5902 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5903 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5904 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5905 | } else { |
| 5906 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5907 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5908 | } |
| 5909 | } else { |
| 5910 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5911 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5912 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5913 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 5914 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 5915 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5916 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5917 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5918 | __ and_(out_low, first_low, second_low); |
| 5919 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5920 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5921 | __ orr(out_low, first_low, second_low); |
| 5922 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5923 | } else { |
| 5924 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5925 | __ eor(out_low, first_low, second_low); |
| 5926 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | } |
| 5930 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5931 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 5932 | Location out, |
| 5933 | uint32_t offset, |
| 5934 | Location temp) { |
| 5935 | Register out_reg = out.AsRegister<Register>(); |
| 5936 | if (kEmitCompilerReadBarrier) { |
| 5937 | if (kUseBakerReadBarrier) { |
| 5938 | // Load with fast path based Baker's read barrier. |
| 5939 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5940 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5941 | instruction, out, out_reg, offset, temp, /* needs_null_check */ false); |
| 5942 | } else { |
| 5943 | // Load with slow path based read barrier. |
| 5944 | // Save the value of `out` into `temp` before overwriting it |
| 5945 | // in the following move operation, as we will need it for the |
| 5946 | // read barrier below. |
| 5947 | __ Mov(temp.AsRegister<Register>(), out_reg); |
| 5948 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5949 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 5950 | codegen_->GenerateReadBarrierSlow(instruction, out, out, temp, offset); |
| 5951 | } |
| 5952 | } else { |
| 5953 | // Plain load with no read barrier. |
| 5954 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5955 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 5956 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5957 | } |
| 5958 | } |
| 5959 | |
| 5960 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 5961 | Location out, |
| 5962 | Location obj, |
| 5963 | uint32_t offset, |
| 5964 | Location temp) { |
| 5965 | Register out_reg = out.AsRegister<Register>(); |
| 5966 | Register obj_reg = obj.AsRegister<Register>(); |
| 5967 | if (kEmitCompilerReadBarrier) { |
| 5968 | if (kUseBakerReadBarrier) { |
| 5969 | // Load with fast path based Baker's read barrier. |
| 5970 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5971 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5972 | instruction, out, obj_reg, offset, temp, /* needs_null_check */ false); |
| 5973 | } else { |
| 5974 | // Load with slow path based read barrier. |
| 5975 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5976 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 5977 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5978 | } |
| 5979 | } else { |
| 5980 | // Plain load with no read barrier. |
| 5981 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5982 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 5983 | __ MaybeUnpoisonHeapReference(out_reg); |
| 5984 | } |
| 5985 | } |
| 5986 | |
| 5987 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5988 | Location root, |
| 5989 | Register obj, |
| 5990 | uint32_t offset) { |
| 5991 | Register root_reg = root.AsRegister<Register>(); |
| 5992 | if (kEmitCompilerReadBarrier) { |
| 5993 | if (kUseBakerReadBarrier) { |
| 5994 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5995 | // Baker's read barrier are used: |
| 5996 | // |
| 5997 | // root = obj.field; |
| 5998 | // if (Thread::Current()->GetIsGcMarking()) { |
| 5999 | // root = ReadBarrier::Mark(root) |
| 6000 | // } |
| 6001 | |
| 6002 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6003 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6004 | static_assert( |
| 6005 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6006 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6007 | "have different sizes."); |
| 6008 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6009 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6010 | "have different sizes."); |
| 6011 | |
| 6012 | // Slow path used to mark the GC root `root`. |
| 6013 | SlowPathCode* slow_path = |
| 6014 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root, root); |
| 6015 | codegen_->AddSlowPath(slow_path); |
| 6016 | |
| 6017 | __ LoadFromOffset( |
| 6018 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmWordSize>().Int32Value()); |
| 6019 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6020 | __ Bind(slow_path->GetExitLabel()); |
| 6021 | } else { |
| 6022 | // GC root loaded through a slow path for read barriers other |
| 6023 | // than Baker's. |
| 6024 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6025 | __ AddConstant(root_reg, obj, offset); |
| 6026 | // /* mirror::Object* */ root = root->Read() |
| 6027 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6028 | } |
| 6029 | } else { |
| 6030 | // Plain GC root load with no read barrier. |
| 6031 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6032 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6033 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6034 | // do not have to unpoison `root_reg` here. |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6039 | Location ref, |
| 6040 | Register obj, |
| 6041 | uint32_t offset, |
| 6042 | Location temp, |
| 6043 | bool needs_null_check) { |
| 6044 | DCHECK(kEmitCompilerReadBarrier); |
| 6045 | DCHECK(kUseBakerReadBarrier); |
| 6046 | |
| 6047 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6048 | Location no_index = Location::NoLocation(); |
| 6049 | GenerateReferenceLoadWithBakerReadBarrier( |
| 6050 | instruction, ref, obj, offset, no_index, temp, needs_null_check); |
| 6051 | } |
| 6052 | |
| 6053 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6054 | Location ref, |
| 6055 | Register obj, |
| 6056 | uint32_t data_offset, |
| 6057 | Location index, |
| 6058 | Location temp, |
| 6059 | bool needs_null_check) { |
| 6060 | DCHECK(kEmitCompilerReadBarrier); |
| 6061 | DCHECK(kUseBakerReadBarrier); |
| 6062 | |
| 6063 | // /* HeapReference<Object> */ ref = |
| 6064 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6065 | GenerateReferenceLoadWithBakerReadBarrier( |
| 6066 | instruction, ref, obj, data_offset, index, temp, needs_null_check); |
| 6067 | } |
| 6068 | |
| 6069 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6070 | Location ref, |
| 6071 | Register obj, |
| 6072 | uint32_t offset, |
| 6073 | Location index, |
| 6074 | Location temp, |
| 6075 | bool needs_null_check) { |
| 6076 | DCHECK(kEmitCompilerReadBarrier); |
| 6077 | DCHECK(kUseBakerReadBarrier); |
| 6078 | |
| 6079 | // In slow path based read barriers, the read barrier call is |
| 6080 | // inserted after the original load. However, in fast path based |
| 6081 | // Baker's read barriers, we need to perform the load of |
| 6082 | // mirror::Object::monitor_ *before* the original reference load. |
| 6083 | // This load-load ordering is required by the read barrier. |
| 6084 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6085 | // |
| 6086 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6087 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6088 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6089 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6090 | // if (is_gray) { |
| 6091 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6092 | // } |
| 6093 | // |
| 6094 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6095 | // slightly more complex as: |
| 6096 | // - it implements the load-load fence using a data dependency on |
| 6097 | // the high-bits of rb_state, which are expected to be all zeroes; |
| 6098 | // - it performs additional checks that we do not do here for |
| 6099 | // performance reasons. |
| 6100 | |
| 6101 | Register ref_reg = ref.AsRegister<Register>(); |
| 6102 | Register temp_reg = temp.AsRegister<Register>(); |
| 6103 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6104 | |
| 6105 | // /* int32_t */ monitor = obj->monitor_ |
| 6106 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6107 | if (needs_null_check) { |
| 6108 | MaybeRecordImplicitNullCheck(instruction); |
| 6109 | } |
| 6110 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6111 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6112 | "art::LockWord and int32_t have different sizes."); |
| 6113 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6114 | __ Lsr(temp_reg, temp_reg, LockWord::kReadBarrierStateShift); |
| 6115 | __ and_(temp_reg, temp_reg, ShifterOperand(LockWord::kReadBarrierStateMask)); |
| 6116 | static_assert( |
| 6117 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6118 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6119 | |
| 6120 | // Introduce a dependency on the high bits of rb_state, which shall |
| 6121 | // be all zeroes, to prevent load-load reordering, and without using |
| 6122 | // a memory barrier (which would be more expensive). |
| 6123 | // IP = rb_state & ~LockWord::kReadBarrierStateMask = 0 |
| 6124 | __ bic(IP, temp_reg, ShifterOperand(LockWord::kReadBarrierStateMask)); |
| 6125 | // obj is unchanged by this operation, but its value now depends on |
| 6126 | // IP, which depends on temp_reg. |
| 6127 | __ add(obj, obj, ShifterOperand(IP)); |
| 6128 | |
| 6129 | // The actual reference load. |
| 6130 | if (index.IsValid()) { |
| 6131 | static_assert( |
| 6132 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6133 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6134 | // /* HeapReference<Object> */ ref = |
| 6135 | // *(obj + offset + index * sizeof(HeapReference<Object>)) |
| 6136 | if (index.IsConstant()) { |
| 6137 | size_t computed_offset = |
| 6138 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset; |
| 6139 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6140 | } else { |
| 6141 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 6142 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6143 | } |
| 6144 | } else { |
| 6145 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6146 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6147 | } |
| 6148 | |
| 6149 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6150 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6151 | |
| 6152 | // Slow path used to mark the object `ref` when it is gray. |
| 6153 | SlowPathCode* slow_path = |
| 6154 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref, ref); |
| 6155 | AddSlowPath(slow_path); |
| 6156 | |
| 6157 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6158 | // ref = ReadBarrier::Mark(ref); |
| 6159 | __ cmp(temp_reg, ShifterOperand(ReadBarrier::gray_ptr_)); |
| 6160 | __ b(slow_path->GetEntryLabel(), EQ); |
| 6161 | __ Bind(slow_path->GetExitLabel()); |
| 6162 | } |
| 6163 | |
| 6164 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6165 | Location out, |
| 6166 | Location ref, |
| 6167 | Location obj, |
| 6168 | uint32_t offset, |
| 6169 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6170 | DCHECK(kEmitCompilerReadBarrier); |
| 6171 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6172 | // Insert a slow path based read barrier *after* the reference load. |
| 6173 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6174 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6175 | // reference will be carried out by the runtime within the slow |
| 6176 | // path. |
| 6177 | // |
| 6178 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6179 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6180 | // not used by the artReadBarrierSlow entry point. |
| 6181 | // |
| 6182 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6183 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6184 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6185 | AddSlowPath(slow_path); |
| 6186 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6187 | __ b(slow_path->GetEntryLabel()); |
| 6188 | __ Bind(slow_path->GetExitLabel()); |
| 6189 | } |
| 6190 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6191 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6192 | Location out, |
| 6193 | Location ref, |
| 6194 | Location obj, |
| 6195 | uint32_t offset, |
| 6196 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6197 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6198 | // Baker's read barriers shall be handled by the fast path |
| 6199 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6200 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6201 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6202 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6203 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6204 | } else if (kPoisonHeapReferences) { |
| 6205 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6206 | } |
| 6207 | } |
| 6208 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6209 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6210 | Location out, |
| 6211 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6212 | DCHECK(kEmitCompilerReadBarrier); |
| 6213 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6214 | // Insert a slow path based read barrier *after* the GC root load. |
| 6215 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6216 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6217 | // not need to do anything special for this here. |
| 6218 | SlowPathCode* slow_path = |
| 6219 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6220 | AddSlowPath(slow_path); |
| 6221 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6222 | __ b(slow_path->GetEntryLabel()); |
| 6223 | __ Bind(slow_path->GetExitLabel()); |
| 6224 | } |
| 6225 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6226 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6227 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6228 | MethodReference target_method) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6229 | if (desired_dispatch_info.code_ptr_location == |
| 6230 | HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
| 6231 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6232 | if (&outer_dex_file != target_method.dex_file) { |
| 6233 | // Calls across dex files are more likely to exceed the available BL range, |
| 6234 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6235 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6236 | (desired_dispatch_info.method_load_kind == |
| 6237 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6238 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6239 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6240 | return HInvokeStaticOrDirect::DispatchInfo { |
| 6241 | desired_dispatch_info.method_load_kind, |
| 6242 | code_ptr_location, |
| 6243 | desired_dispatch_info.method_load_data, |
| 6244 | 0u |
| 6245 | }; |
| 6246 | } |
| 6247 | } |
| 6248 | return desired_dispatch_info; |
| 6249 | } |
| 6250 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6251 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6252 | Register temp) { |
| 6253 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6254 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6255 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6256 | return location.AsRegister<Register>(); |
| 6257 | } |
| 6258 | // For intrinsics we allow any location, so it may be on the stack. |
| 6259 | if (!location.IsRegister()) { |
| 6260 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6261 | return temp; |
| 6262 | } |
| 6263 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6264 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6265 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6266 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6267 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6268 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6269 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6270 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6271 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6272 | return temp; |
| 6273 | } |
| 6274 | return location.AsRegister<Register>(); |
| 6275 | } |
| 6276 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6277 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6278 | // 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] | 6279 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6280 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6281 | // LR = code address from literal pool with link-time patch. |
| 6282 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6283 | break; |
| 6284 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6285 | // LR = invoke->GetDirectCodePtr(); |
| 6286 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6287 | break; |
| 6288 | default: |
| 6289 | break; |
| 6290 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6291 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6292 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6293 | switch (invoke->GetMethodLoadKind()) { |
| 6294 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6295 | // temp = thread->string_init_entrypoint |
| 6296 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6297 | break; |
| 6298 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6299 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6300 | break; |
| 6301 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6302 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6303 | break; |
| 6304 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6305 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6306 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6307 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6308 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6309 | HArmDexCacheArraysBase* base = |
| 6310 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6311 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6312 | temp.AsRegister<Register>()); |
| 6313 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6314 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6315 | break; |
| 6316 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6317 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6318 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6319 | Register method_reg; |
| 6320 | Register reg = temp.AsRegister<Register>(); |
| 6321 | if (current_method.IsRegister()) { |
| 6322 | method_reg = current_method.AsRegister<Register>(); |
| 6323 | } else { |
| 6324 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6325 | DCHECK(!current_method.IsValid()); |
| 6326 | method_reg = reg; |
| 6327 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6328 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6329 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6330 | __ LoadFromOffset(kLoadWord, |
| 6331 | reg, |
| 6332 | method_reg, |
| 6333 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6334 | // temp = temp[index_in_cache] |
| 6335 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 6336 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6337 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6338 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
| 6341 | switch (invoke->GetCodePtrLocation()) { |
| 6342 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6343 | __ bl(GetFrameEntryLabel()); |
| 6344 | break; |
| 6345 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6346 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6347 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6348 | // Arbitrarily branch to the BL itself, override at link time. |
| 6349 | __ bl(&relative_call_patches_.back().label); |
| 6350 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6351 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6352 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6353 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6354 | // LR() |
| 6355 | __ blx(LR); |
| 6356 | break; |
| 6357 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6358 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6359 | __ LoadFromOffset( |
| 6360 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 6361 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 6362 | // LR() |
| 6363 | __ blx(LR); |
| 6364 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6365 | } |
| 6366 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6367 | DCHECK(!IsLeafMethod()); |
| 6368 | } |
| 6369 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6370 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6371 | Register temp = temp_location.AsRegister<Register>(); |
| 6372 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6373 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6374 | |
| 6375 | // Use the calling convention instead of the location of the receiver, as |
| 6376 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6377 | // slow path, the arguments have been moved to the right place, so here we are |
| 6378 | // guaranteed that the receiver is the first register of the calling convention. |
| 6379 | InvokeDexCallingConvention calling_convention; |
| 6380 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6381 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6382 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6383 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6384 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6385 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6386 | // emit a read barrier for the previous class reference load. |
| 6387 | // However this is not required in practice, as this is an |
| 6388 | // intermediate/temporary reference and because the current |
| 6389 | // concurrent copying collector keeps the from-space memory |
| 6390 | // intact/accessible until the end of the marking phase (the |
| 6391 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6392 | __ MaybeUnpoisonHeapReference(temp); |
| 6393 | // temp = temp->GetMethodAt(method_offset); |
| 6394 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 6395 | kArmWordSize).Int32Value(); |
| 6396 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6397 | // LR = temp->GetEntryPoint(); |
| 6398 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6399 | // LR(); |
| 6400 | __ blx(LR); |
| 6401 | } |
| 6402 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6403 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6404 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6405 | size_t size = |
| 6406 | method_patches_.size() + |
| 6407 | call_patches_.size() + |
| 6408 | relative_call_patches_.size() + |
| 6409 | /* MOVW+MOVT for each base */ 2u * dex_cache_arrays_base_labels_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6410 | linker_patches->reserve(size); |
| 6411 | for (const auto& entry : method_patches_) { |
| 6412 | const MethodReference& target_method = entry.first; |
| 6413 | Literal* literal = entry.second; |
| 6414 | DCHECK(literal->GetLabel()->IsBound()); |
| 6415 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6416 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6417 | target_method.dex_file, |
| 6418 | target_method.dex_method_index)); |
| 6419 | } |
| 6420 | for (const auto& entry : call_patches_) { |
| 6421 | const MethodReference& target_method = entry.first; |
| 6422 | Literal* literal = entry.second; |
| 6423 | DCHECK(literal->GetLabel()->IsBound()); |
| 6424 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6425 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6426 | target_method.dex_file, |
| 6427 | target_method.dex_method_index)); |
| 6428 | } |
| 6429 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6430 | uint32_t literal_offset = info.label.Position(); |
| 6431 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6432 | info.target_method.dex_file, |
| 6433 | info.target_method.dex_method_index)); |
| 6434 | } |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6435 | for (const auto& pair : dex_cache_arrays_base_labels_) { |
| 6436 | HArmDexCacheArraysBase* base = pair.first; |
| 6437 | const DexCacheArraysBaseLabels* labels = &pair.second; |
| 6438 | const DexFile& dex_file = base->GetDexFile(); |
| 6439 | size_t base_element_offset = base->GetElementOffset(); |
| 6440 | DCHECK(labels->add_pc_label.IsBound()); |
| 6441 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(labels->add_pc_label.Position()); |
| 6442 | // Add MOVW patch. |
| 6443 | DCHECK(labels->movw_label.IsBound()); |
| 6444 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(labels->movw_label.Position()); |
| 6445 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6446 | &dex_file, |
| 6447 | add_pc_offset, |
| 6448 | base_element_offset)); |
| 6449 | // Add MOVT patch. |
| 6450 | DCHECK(labels->movt_label.IsBound()); |
| 6451 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(labels->movt_label.Position()); |
| 6452 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6453 | &dex_file, |
| 6454 | add_pc_offset, |
| 6455 | base_element_offset)); |
| 6456 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6457 | } |
| 6458 | |
| 6459 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 6460 | MethodToLiteralMap* map) { |
| 6461 | // Look up the literal for target_method. |
| 6462 | auto lb = map->lower_bound(target_method); |
| 6463 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 6464 | return lb->second; |
| 6465 | } |
| 6466 | // We don't have a literal for this method yet, insert a new one. |
| 6467 | Literal* literal = __ NewLiteral<uint32_t>(0u); |
| 6468 | map->PutBefore(lb, target_method, literal); |
| 6469 | return literal; |
| 6470 | } |
| 6471 | |
| 6472 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 6473 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 6474 | } |
| 6475 | |
| 6476 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 6477 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 6478 | } |
| 6479 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6480 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6481 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6482 | LOG(FATAL) << "Unreachable"; |
| 6483 | } |
| 6484 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6485 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6486 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6487 | LOG(FATAL) << "Unreachable"; |
| 6488 | } |
| 6489 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 6490 | void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) { |
| 6491 | DCHECK(codegen_->IsBaseline()); |
| 6492 | LocationSummary* locations = |
| 6493 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6494 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 6495 | } |
| 6496 | |
| 6497 | void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 6498 | DCHECK(codegen_->IsBaseline()); |
| 6499 | // Will be generated at use site. |
| 6500 | } |
| 6501 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6502 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6503 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6504 | LocationSummary* locations = |
| 6505 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6506 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6507 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6508 | codegen_->GetAssembler()->IsThumb()) { |
| 6509 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 6510 | if (switch_instr->GetStartValue() != 0) { |
| 6511 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 6512 | } |
| 6513 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6514 | } |
| 6515 | |
| 6516 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6517 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6518 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6519 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6520 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6521 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6522 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6523 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6524 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6525 | Register temp_reg = IP; |
| 6526 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 6527 | // the immediate, because IP is used as the destination register. For the other |
| 6528 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 6529 | // and they can be encoded in the instruction without making use of IP register. |
| 6530 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 6531 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6532 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6533 | // Jump to successors[0] if value == lower_bound. |
| 6534 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 6535 | int32_t last_index = 0; |
| 6536 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6537 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 6538 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6539 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 6540 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6541 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 6542 | } |
| 6543 | if (num_entries - last_index == 2) { |
| 6544 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 6545 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6546 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6547 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6548 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6549 | // And the default for any other value. |
| 6550 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6551 | __ b(codegen_->GetLabelOf(default_block)); |
| 6552 | } |
| 6553 | } else { |
| 6554 | // Create a table lookup. |
| 6555 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6556 | |
| 6557 | // Materialize a pointer to the switch table |
| 6558 | std::vector<Label*> labels(num_entries); |
| 6559 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6560 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6561 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6562 | } |
| 6563 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 6564 | |
| 6565 | // Remove the bias. |
| 6566 | Register key_reg; |
| 6567 | if (lower_bound != 0) { |
| 6568 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 6569 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 6570 | } else { |
| 6571 | key_reg = value_reg; |
| 6572 | } |
| 6573 | |
| 6574 | // Check whether the value is in the table, jump to default block if not. |
| 6575 | __ CmpConstant(key_reg, num_entries - 1); |
| 6576 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 6577 | |
| 6578 | // Load the displacement from the table. |
| 6579 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 6580 | |
| 6581 | // Dispatch is a direct add to the PC (for Thumb2). |
| 6582 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6583 | } |
| 6584 | } |
| 6585 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6586 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6587 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6588 | locations->SetOut(Location::RequiresRegister()); |
| 6589 | codegen_->AddDexCacheArraysBase(base); |
| 6590 | } |
| 6591 | |
| 6592 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6593 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
| 6594 | CodeGeneratorARM::DexCacheArraysBaseLabels* labels = codegen_->GetDexCacheArraysBaseLabels(base); |
| 6595 | __ BindTrackedLabel(&labels->movw_label); |
| 6596 | __ movw(base_reg, 0u); |
| 6597 | __ BindTrackedLabel(&labels->movt_label); |
| 6598 | __ movt(base_reg, 0u); |
| 6599 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6600 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 6601 | } |
| 6602 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6603 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6604 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6605 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6606 | return; |
| 6607 | } |
| 6608 | |
| 6609 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6610 | |
| 6611 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 6612 | if (return_loc.Equals(trg)) { |
| 6613 | return; |
| 6614 | } |
| 6615 | |
| 6616 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 6617 | // with the last branch. |
| 6618 | if (type == Primitive::kPrimLong) { |
| 6619 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6620 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 6621 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 6622 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6623 | } else if (type == Primitive::kPrimDouble) { |
| 6624 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6625 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 6626 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 6627 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6628 | } else { |
| 6629 | // Let the parallel move resolver take care of all of this. |
| 6630 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6631 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6632 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6633 | } |
| 6634 | } |
| 6635 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6636 | #undef __ |
| 6637 | #undef QUICK_ENTRY_POINT |
| 6638 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6639 | } // namespace arm |
| 6640 | } // namespace art |