Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 62 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 63 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 65 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 67 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 69 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 70 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 72 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 73 | // Live registers will be restored in the catch block if caught. |
| 74 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 75 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 76 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 77 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 78 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | bool IsFatal() const OVERRIDE { return true; } |
| 82 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 83 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 84 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 87 | }; |
| 88 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 89 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 91 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 93 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 95 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 96 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 97 | // Live registers will be restored in the catch block if caught. |
| 98 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 99 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 101 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 102 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 105 | bool IsFatal() const OVERRIDE { return true; } |
| 106 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 107 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 108 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 111 | }; |
| 112 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 113 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 114 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 115 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 116 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 117 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 118 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 119 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 120 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 121 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 122 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 123 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 124 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 125 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 126 | if (successor_ == nullptr) { |
| 127 | __ b(GetReturnLabel()); |
| 128 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 129 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 130 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 133 | Label* GetReturnLabel() { |
| 134 | DCHECK(successor_ == nullptr); |
| 135 | return &return_label_; |
| 136 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 137 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 138 | HBasicBlock* GetSuccessor() const { |
| 139 | return successor_; |
| 140 | } |
| 141 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 142 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 143 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 145 | // If not null, the block to branch to after the suspend check. |
| 146 | HBasicBlock* const successor_; |
| 147 | |
| 148 | // 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] | 149 | Label return_label_; |
| 150 | |
| 151 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 152 | }; |
| 153 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 154 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 155 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 156 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 157 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 159 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 160 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 161 | LocationSummary* locations = instruction_->GetLocations(); |
| 162 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 163 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 164 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 165 | // Live registers will be restored in the catch block if caught. |
| 166 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 167 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 168 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 169 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 170 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 171 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 172 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 173 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 174 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 175 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 176 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 177 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 178 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 179 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 180 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 183 | bool IsFatal() const OVERRIDE { return true; } |
| 184 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 185 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 186 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 189 | }; |
| 190 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 191 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 192 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 193 | LoadClassSlowPathARM(HLoadClass* cls, |
| 194 | HInstruction* at, |
| 195 | uint32_t dex_pc, |
| 196 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 197 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 198 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 199 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 200 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 201 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 202 | LocationSummary* locations = at_->GetLocations(); |
| 203 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 204 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 205 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 206 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 207 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 208 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 210 | int32_t entry_point_offset = do_clinit_ |
| 211 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 212 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 213 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 214 | if (do_clinit_) { |
| 215 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 216 | } else { |
| 217 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 218 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 219 | |
| 220 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 221 | Location out = locations->Out(); |
| 222 | if (out.IsValid()) { |
| 223 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 225 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 226 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | __ b(GetExitLabel()); |
| 228 | } |
| 229 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 230 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 231 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 233 | // The class this slow path will load. |
| 234 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | // The instruction where this slow path is happening. |
| 237 | // (Might be the load class or an initialization check). |
| 238 | HInstruction* const at_; |
| 239 | |
| 240 | // The dex PC of `at_`. |
| 241 | const uint32_t dex_pc_; |
| 242 | |
| 243 | // Whether to initialize the class. |
| 244 | const bool do_clinit_; |
| 245 | |
| 246 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | }; |
| 248 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 249 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 250 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 251 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 252 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 254 | LocationSummary* locations = instruction_->GetLocations(); |
| 255 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 256 | |
| 257 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 258 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 259 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 260 | |
| 261 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 262 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 263 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 264 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 265 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 266 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 268 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 269 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 270 | __ b(GetExitLabel()); |
| 271 | } |
| 272 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 273 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 274 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 275 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 276 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 277 | }; |
| 278 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 279 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 281 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 282 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 286 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 287 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 288 | DCHECK(instruction_->IsCheckCast() |
| 289 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 290 | |
| 291 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 292 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 293 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 294 | if (!is_fatal_) { |
| 295 | SaveLiveRegisters(codegen, locations); |
| 296 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 297 | |
| 298 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 299 | // move resolver. |
| 300 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 301 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 302 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 303 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 304 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 305 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 306 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 307 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 309 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 310 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 311 | instruction_, |
| 312 | instruction_->GetDexPc(), |
| 313 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 314 | CheckEntrypointTypes< |
| 315 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 316 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 317 | } else { |
| 318 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 319 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 320 | instruction_, |
| 321 | instruction_->GetDexPc(), |
| 322 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 323 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 324 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 326 | if (!is_fatal_) { |
| 327 | RestoreLiveRegisters(codegen, locations); |
| 328 | __ b(GetExitLabel()); |
| 329 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 332 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 333 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 335 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 337 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | |
| 339 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 340 | }; |
| 341 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 342 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 343 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 344 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 345 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 346 | |
| 347 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 348 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 349 | __ Bind(GetEntryLabel()); |
| 350 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 351 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 352 | instruction_, |
| 353 | instruction_->GetDexPc(), |
| 354 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 355 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 358 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 359 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 360 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 362 | }; |
| 363 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 364 | class ArraySetSlowPathARM : public SlowPathCode { |
| 365 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 366 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 367 | |
| 368 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 369 | LocationSummary* locations = instruction_->GetLocations(); |
| 370 | __ Bind(GetEntryLabel()); |
| 371 | SaveLiveRegisters(codegen, locations); |
| 372 | |
| 373 | InvokeRuntimeCallingConvention calling_convention; |
| 374 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 375 | parallel_move.AddMove( |
| 376 | locations->InAt(0), |
| 377 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 378 | Primitive::kPrimNot, |
| 379 | nullptr); |
| 380 | parallel_move.AddMove( |
| 381 | locations->InAt(1), |
| 382 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 383 | Primitive::kPrimInt, |
| 384 | nullptr); |
| 385 | parallel_move.AddMove( |
| 386 | locations->InAt(2), |
| 387 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 388 | Primitive::kPrimNot, |
| 389 | nullptr); |
| 390 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 391 | |
| 392 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 393 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 394 | instruction_, |
| 395 | instruction_->GetDexPc(), |
| 396 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 397 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 398 | RestoreLiveRegisters(codegen, locations); |
| 399 | __ b(GetExitLabel()); |
| 400 | } |
| 401 | |
| 402 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 403 | |
| 404 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 405 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 406 | }; |
| 407 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 408 | // Slow path marking an object during a read barrier. |
| 409 | class ReadBarrierMarkSlowPathARM : public SlowPathCode { |
| 410 | public: |
| 411 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 412 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 413 | DCHECK(kEmitCompilerReadBarrier); |
| 414 | } |
| 415 | |
| 416 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 417 | |
| 418 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 419 | LocationSummary* locations = instruction_->GetLocations(); |
| 420 | Register reg_out = out_.AsRegister<Register>(); |
| 421 | DCHECK(locations->CanCall()); |
| 422 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 423 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 424 | instruction_->IsStaticFieldGet() || |
| 425 | instruction_->IsArrayGet() || |
| 426 | instruction_->IsLoadClass() || |
| 427 | instruction_->IsLoadString() || |
| 428 | instruction_->IsInstanceOf() || |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 429 | instruction_->IsCheckCast() || |
| 430 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
| 431 | instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 432 | << "Unexpected instruction in read barrier marking slow path: " |
| 433 | << instruction_->DebugName(); |
| 434 | |
| 435 | __ Bind(GetEntryLabel()); |
| 436 | SaveLiveRegisters(codegen, locations); |
| 437 | |
| 438 | InvokeRuntimeCallingConvention calling_convention; |
| 439 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 440 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 441 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 442 | instruction_, |
| 443 | instruction_->GetDexPc(), |
| 444 | this); |
| 445 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 446 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 447 | |
| 448 | RestoreLiveRegisters(codegen, locations); |
| 449 | __ b(GetExitLabel()); |
| 450 | } |
| 451 | |
| 452 | private: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 453 | const Location out_; |
| 454 | const Location obj_; |
| 455 | |
| 456 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 457 | }; |
| 458 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 459 | // Slow path generating a read barrier for a heap reference. |
| 460 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 461 | public: |
| 462 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 463 | Location out, |
| 464 | Location ref, |
| 465 | Location obj, |
| 466 | uint32_t offset, |
| 467 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 468 | : SlowPathCode(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 469 | out_(out), |
| 470 | ref_(ref), |
| 471 | obj_(obj), |
| 472 | offset_(offset), |
| 473 | index_(index) { |
| 474 | DCHECK(kEmitCompilerReadBarrier); |
| 475 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 476 | // has been overwritten by (or after) the heap object reference load |
| 477 | // to be instrumented, e.g.: |
| 478 | // |
| 479 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 480 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 481 | // |
| 482 | // In that case, we have lost the information about the original |
| 483 | // object, and the emitted read barrier cannot work properly. |
| 484 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 485 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 486 | } |
| 487 | |
| 488 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 489 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 490 | LocationSummary* locations = instruction_->GetLocations(); |
| 491 | Register reg_out = out_.AsRegister<Register>(); |
| 492 | DCHECK(locations->CanCall()); |
| 493 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 494 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 495 | instruction_->IsStaticFieldGet() || |
| 496 | instruction_->IsArrayGet() || |
| 497 | instruction_->IsInstanceOf() || |
| 498 | instruction_->IsCheckCast() || |
| 499 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 500 | instruction_->GetLocations()->Intrinsified())) |
| 501 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 502 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 503 | |
| 504 | __ Bind(GetEntryLabel()); |
| 505 | SaveLiveRegisters(codegen, locations); |
| 506 | |
| 507 | // We may have to change the index's value, but as `index_` is a |
| 508 | // constant member (like other "inputs" of this slow path), |
| 509 | // introduce a copy of it, `index`. |
| 510 | Location index = index_; |
| 511 | if (index_.IsValid()) { |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 512 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 513 | if (instruction_->IsArrayGet()) { |
| 514 | // Compute the actual memory offset and store it in `index`. |
| 515 | Register index_reg = index_.AsRegister<Register>(); |
| 516 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 517 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 518 | // We are about to change the value of `index_reg` (see the |
| 519 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 520 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 521 | // not been saved by the previous call to |
| 522 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 523 | // callee-save register -- |
| 524 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 525 | // callee-save registers, as it has been designed with the |
| 526 | // assumption that callee-save registers are supposed to be |
| 527 | // handled by the called function. So, as a callee-save |
| 528 | // register, `index_reg` _would_ eventually be saved onto |
| 529 | // the stack, but it would be too late: we would have |
| 530 | // changed its value earlier. Therefore, we manually save |
| 531 | // it here into another freely available register, |
| 532 | // `free_reg`, chosen of course among the caller-save |
| 533 | // registers (as a callee-save `free_reg` register would |
| 534 | // exhibit the same problem). |
| 535 | // |
| 536 | // Note we could have requested a temporary register from |
| 537 | // the register allocator instead; but we prefer not to, as |
| 538 | // this is a slow path, and we know we can find a |
| 539 | // caller-save register that is available. |
| 540 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 541 | __ Mov(free_reg, index_reg); |
| 542 | index_reg = free_reg; |
| 543 | index = Location::RegisterLocation(index_reg); |
| 544 | } else { |
| 545 | // The initial register stored in `index_` has already been |
| 546 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 547 | // (as it is not a callee-save register), so we can freely |
| 548 | // use it. |
| 549 | } |
| 550 | // Shifting the index value contained in `index_reg` by the scale |
| 551 | // factor (2) cannot overflow in practice, as the runtime is |
| 552 | // unable to allocate object arrays with a size larger than |
| 553 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 554 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 555 | static_assert( |
| 556 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 557 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 558 | __ AddConstant(index_reg, index_reg, offset_); |
| 559 | } else { |
Roland Levillain | c0cdb0b | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 560 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 561 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 562 | // (as in the case of ArrayGet), as it is actually an offset |
| 563 | // to an object field within an object. |
| 564 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 565 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 566 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 567 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 568 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 569 | DCHECK_EQ(offset_, 0U); |
| 570 | DCHECK(index_.IsRegisterPair()); |
| 571 | // UnsafeGet's offset location is a register pair, the low |
| 572 | // part contains the correct offset. |
| 573 | index = index_.ToLow(); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | // We're moving two or three locations to locations that could |
| 578 | // overlap, so we need a parallel move resolver. |
| 579 | InvokeRuntimeCallingConvention calling_convention; |
| 580 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 581 | parallel_move.AddMove(ref_, |
| 582 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 583 | Primitive::kPrimNot, |
| 584 | nullptr); |
| 585 | parallel_move.AddMove(obj_, |
| 586 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 587 | Primitive::kPrimNot, |
| 588 | nullptr); |
| 589 | if (index.IsValid()) { |
| 590 | parallel_move.AddMove(index, |
| 591 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 592 | Primitive::kPrimInt, |
| 593 | nullptr); |
| 594 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 595 | } else { |
| 596 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 597 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 598 | } |
| 599 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 600 | instruction_, |
| 601 | instruction_->GetDexPc(), |
| 602 | this); |
| 603 | CheckEntrypointTypes< |
| 604 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 605 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 606 | |
| 607 | RestoreLiveRegisters(codegen, locations); |
| 608 | __ b(GetExitLabel()); |
| 609 | } |
| 610 | |
| 611 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 612 | |
| 613 | private: |
| 614 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 615 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 616 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 617 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 618 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 619 | return static_cast<Register>(i); |
| 620 | } |
| 621 | } |
| 622 | // We shall never fail to find a free caller-save register, as |
| 623 | // there are more than two core caller-save registers on ARM |
| 624 | // (meaning it is possible to find one which is different from |
| 625 | // `ref` and `obj`). |
| 626 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 627 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 628 | UNREACHABLE(); |
| 629 | } |
| 630 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 631 | const Location out_; |
| 632 | const Location ref_; |
| 633 | const Location obj_; |
| 634 | const uint32_t offset_; |
| 635 | // An additional location containing an index to an array. |
| 636 | // Only used for HArrayGet and the UnsafeGetObject & |
| 637 | // UnsafeGetObjectVolatile intrinsics. |
| 638 | const Location index_; |
| 639 | |
| 640 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 641 | }; |
| 642 | |
| 643 | // Slow path generating a read barrier for a GC root. |
| 644 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 645 | public: |
| 646 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 647 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 648 | DCHECK(kEmitCompilerReadBarrier); |
| 649 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 650 | |
| 651 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 652 | LocationSummary* locations = instruction_->GetLocations(); |
| 653 | Register reg_out = out_.AsRegister<Register>(); |
| 654 | DCHECK(locations->CanCall()); |
| 655 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 656 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 657 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 658 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 659 | |
| 660 | __ Bind(GetEntryLabel()); |
| 661 | SaveLiveRegisters(codegen, locations); |
| 662 | |
| 663 | InvokeRuntimeCallingConvention calling_convention; |
| 664 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 665 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 666 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 667 | instruction_, |
| 668 | instruction_->GetDexPc(), |
| 669 | this); |
| 670 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 671 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 672 | |
| 673 | RestoreLiveRegisters(codegen, locations); |
| 674 | __ b(GetExitLabel()); |
| 675 | } |
| 676 | |
| 677 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 678 | |
| 679 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 680 | const Location out_; |
| 681 | const Location root_; |
| 682 | |
| 683 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 684 | }; |
| 685 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 686 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 687 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 688 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 689 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 690 | switch (cond) { |
| 691 | case kCondEQ: return EQ; |
| 692 | case kCondNE: return NE; |
| 693 | case kCondLT: return LT; |
| 694 | case kCondLE: return LE; |
| 695 | case kCondGT: return GT; |
| 696 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 697 | case kCondB: return LO; |
| 698 | case kCondBE: return LS; |
| 699 | case kCondA: return HI; |
| 700 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 701 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 702 | LOG(FATAL) << "Unreachable"; |
| 703 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 706 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 707 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 708 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 709 | case kCondEQ: return EQ; |
| 710 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 711 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 712 | case kCondLT: return LO; |
| 713 | case kCondLE: return LS; |
| 714 | case kCondGT: return HI; |
| 715 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 716 | // Unsigned remain unchanged. |
| 717 | case kCondB: return LO; |
| 718 | case kCondBE: return LS; |
| 719 | case kCondA: return HI; |
| 720 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 721 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 722 | LOG(FATAL) << "Unreachable"; |
| 723 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 726 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 727 | // The ARM condition codes can express all the necessary branches, see the |
| 728 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 729 | // There is no dex instruction or HIR that would need the missing conditions |
| 730 | // "equal or unordered" or "not equal". |
| 731 | switch (cond) { |
| 732 | case kCondEQ: return EQ; |
| 733 | case kCondNE: return NE /* unordered */; |
| 734 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 735 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 736 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 737 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 738 | default: |
| 739 | LOG(FATAL) << "UNREACHABLE"; |
| 740 | UNREACHABLE(); |
| 741 | } |
| 742 | } |
| 743 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 744 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 745 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 749 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 750 | } |
| 751 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 752 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 753 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 754 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 755 | } |
| 756 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 757 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 758 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 759 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 762 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 763 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 764 | return kArmWordSize; |
| 765 | } |
| 766 | |
| 767 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 768 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 769 | return kArmWordSize; |
| 770 | } |
| 771 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 772 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 773 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 774 | const CompilerOptions& compiler_options, |
| 775 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 776 | : CodeGenerator(graph, |
| 777 | kNumberOfCoreRegisters, |
| 778 | kNumberOfSRegisters, |
| 779 | kNumberOfRegisterPairs, |
| 780 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 781 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 782 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 783 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 784 | compiler_options, |
| 785 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 786 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 787 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 788 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 789 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | d1ee809 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 790 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 791 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 792 | uint32_literals_(std::less<uint32_t>(), |
| 793 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 794 | method_patches_(MethodReferenceComparator(), |
| 795 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 796 | call_patches_(MethodReferenceComparator(), |
| 797 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 798 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 799 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 800 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 801 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 802 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 803 | boot_image_address_patches_(std::less<uint32_t>(), |
| 804 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 805 | // Always save the LR register to mimic Quick. |
| 806 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 807 | } |
| 808 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 809 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 810 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 811 | __ FinalizeCode(); |
| 812 | |
| 813 | // Adjust native pc offsets in stack maps. |
| 814 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 815 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 816 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 817 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 818 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 819 | // Adjust pc offsets for the disassembly information. |
| 820 | if (disasm_info_ != nullptr) { |
| 821 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 822 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 823 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 824 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 825 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 826 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 827 | } |
| 828 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 829 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 830 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 831 | } |
| 832 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 833 | |
| 834 | CodeGenerator::Finalize(allocator); |
| 835 | } |
| 836 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 837 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 838 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 839 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 840 | |
| 841 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 842 | blocked_core_registers_[SP] = true; |
| 843 | blocked_core_registers_[LR] = true; |
| 844 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 845 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 846 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 847 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 848 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 849 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 850 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 851 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 852 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 853 | // Stubs do not save callee-save floating point registers. If the graph |
| 854 | // is debuggable, we need to deal with these registers differently. For |
| 855 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 856 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 857 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 858 | } |
| 859 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 860 | |
| 861 | UpdateBlockedPairRegisters(); |
| 862 | } |
| 863 | |
| 864 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 865 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 866 | ArmManagedRegister current = |
| 867 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 868 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 869 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 870 | blocked_register_pairs_[i] = true; |
| 871 | } |
| 872 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 875 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 876 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 877 | assembler_(codegen->GetAssembler()), |
| 878 | codegen_(codegen) {} |
| 879 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 880 | void CodeGeneratorARM::ComputeSpillMask() { |
| 881 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 882 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 883 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 884 | // restore another arbitrary register. |
| 885 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 886 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 887 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 888 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 889 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 890 | // but in the range. |
| 891 | if (fpu_spill_mask_ != 0) { |
| 892 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 893 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 894 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 895 | fpu_spill_mask_ |= (1 << i); |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 900 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 901 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 905 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 906 | } |
| 907 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 908 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 909 | bool skip_overflow_check = |
| 910 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 911 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 912 | __ Bind(&frame_entry_label_); |
| 913 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 914 | if (HasEmptyFrame()) { |
| 915 | return; |
| 916 | } |
| 917 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 918 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 919 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 920 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 921 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 922 | } |
| 923 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 924 | __ PushList(core_spill_mask_); |
| 925 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 926 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 927 | if (fpu_spill_mask_ != 0) { |
| 928 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 929 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 930 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 931 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 932 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 933 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 934 | __ AddConstant(SP, -adjust); |
| 935 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 936 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 940 | if (HasEmptyFrame()) { |
| 941 | __ bx(LR); |
| 942 | return; |
| 943 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 944 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 945 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 946 | __ AddConstant(SP, adjust); |
| 947 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 948 | if (fpu_spill_mask_ != 0) { |
| 949 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 950 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 951 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 952 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 953 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 954 | // Pop LR into PC to return. |
| 955 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 956 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 957 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 958 | __ cfi().RestoreState(); |
| 959 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 962 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 963 | Label* label = GetLabelOf(block); |
| 964 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 967 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 968 | switch (type) { |
| 969 | case Primitive::kPrimBoolean: |
| 970 | case Primitive::kPrimByte: |
| 971 | case Primitive::kPrimChar: |
| 972 | case Primitive::kPrimShort: |
| 973 | case Primitive::kPrimInt: |
| 974 | case Primitive::kPrimNot: { |
| 975 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 976 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 977 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 978 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 979 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 980 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 981 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 982 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 983 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 984 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 985 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 986 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 987 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 988 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 989 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 990 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 991 | // Skip R1, and use R2_R3 instead. |
| 992 | gp_index_++; |
| 993 | index++; |
| 994 | } |
| 995 | } |
| 996 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 997 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 998 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 999 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1000 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1001 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1002 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1003 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | case Primitive::kPrimFloat: { |
| 1008 | uint32_t stack_index = stack_index_++; |
| 1009 | if (float_index_ % 2 == 0) { |
| 1010 | float_index_ = std::max(double_index_, float_index_); |
| 1011 | } |
| 1012 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1013 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1014 | } else { |
| 1015 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | case Primitive::kPrimDouble: { |
| 1020 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1021 | uint32_t stack_index = stack_index_; |
| 1022 | stack_index_ += 2; |
| 1023 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1024 | uint32_t index = double_index_; |
| 1025 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1026 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1027 | calling_convention.GetFpuRegisterAt(index), |
| 1028 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1029 | DCHECK(ExpectedPairLayout(result)); |
| 1030 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1031 | } else { |
| 1032 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1036 | case Primitive::kPrimVoid: |
| 1037 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1038 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1039 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1040 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1041 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1042 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1043 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1044 | switch (type) { |
| 1045 | case Primitive::kPrimBoolean: |
| 1046 | case Primitive::kPrimByte: |
| 1047 | case Primitive::kPrimChar: |
| 1048 | case Primitive::kPrimShort: |
| 1049 | case Primitive::kPrimInt: |
| 1050 | case Primitive::kPrimNot: { |
| 1051 | return Location::RegisterLocation(R0); |
| 1052 | } |
| 1053 | |
| 1054 | case Primitive::kPrimFloat: { |
| 1055 | return Location::FpuRegisterLocation(S0); |
| 1056 | } |
| 1057 | |
| 1058 | case Primitive::kPrimLong: { |
| 1059 | return Location::RegisterPairLocation(R0, R1); |
| 1060 | } |
| 1061 | |
| 1062 | case Primitive::kPrimDouble: { |
| 1063 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1064 | } |
| 1065 | |
| 1066 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1067 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1068 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1069 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1070 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1073 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1074 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1075 | } |
| 1076 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1077 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1078 | if (source.Equals(destination)) { |
| 1079 | return; |
| 1080 | } |
| 1081 | if (destination.IsRegister()) { |
| 1082 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1083 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1084 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1085 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1086 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1087 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1088 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1089 | } else if (destination.IsFpuRegister()) { |
| 1090 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1091 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1092 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1093 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1094 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1095 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1096 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1097 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1098 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1099 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1100 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1101 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1102 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1103 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1104 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1105 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1106 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1112 | if (source.Equals(destination)) { |
| 1113 | return; |
| 1114 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1115 | if (destination.IsRegisterPair()) { |
| 1116 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1117 | EmitParallelMoves( |
| 1118 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1119 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1120 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1121 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1122 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1123 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1124 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1125 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1126 | } else if (source.IsFpuRegisterPair()) { |
| 1127 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1128 | destination.AsRegisterPairHigh<Register>(), |
| 1129 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1130 | } else { |
| 1131 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1132 | DCHECK(ExpectedPairLayout(destination)); |
| 1133 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1134 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1135 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1136 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1137 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1138 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1139 | SP, |
| 1140 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1141 | } else if (source.IsRegisterPair()) { |
| 1142 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1143 | source.AsRegisterPairLow<Register>(), |
| 1144 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1145 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1146 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1147 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1148 | } else { |
| 1149 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1150 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1151 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1152 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1153 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1154 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1155 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1156 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1157 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1158 | SP, destination.GetStackIndex()); |
| 1159 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1160 | } else if (source.IsFpuRegisterPair()) { |
| 1161 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1162 | SP, |
| 1163 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1164 | } else { |
| 1165 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1166 | EmitParallelMoves( |
| 1167 | Location::StackSlot(source.GetStackIndex()), |
| 1168 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1169 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1170 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1171 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1172 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1177 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1178 | DCHECK(location.IsRegister()); |
| 1179 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1180 | } |
| 1181 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1182 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1183 | HParallelMove move(GetGraph()->GetArena()); |
| 1184 | move.AddMove(src, dst, dst_type, nullptr); |
| 1185 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1189 | if (location.IsRegister()) { |
| 1190 | locations->AddTemp(location); |
| 1191 | } else if (location.IsRegisterPair()) { |
| 1192 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1193 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1194 | } else { |
| 1195 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1196 | } |
| 1197 | } |
| 1198 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1199 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1200 | HInstruction* instruction, |
| 1201 | uint32_t dex_pc, |
| 1202 | SlowPathCode* slow_path) { |
| 1203 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1204 | instruction, |
| 1205 | dex_pc, |
| 1206 | slow_path); |
| 1207 | } |
| 1208 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1209 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1210 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1211 | uint32_t dex_pc, |
| 1212 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1213 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1214 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1215 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1216 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1219 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1220 | DCHECK(!successor->IsExitBlock()); |
| 1221 | |
| 1222 | HBasicBlock* block = got->GetBlock(); |
| 1223 | HInstruction* previous = got->GetPrevious(); |
| 1224 | |
| 1225 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1226 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1227 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1228 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1229 | return; |
| 1230 | } |
| 1231 | |
| 1232 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1233 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1234 | } |
| 1235 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1236 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1240 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1241 | got->SetLocations(nullptr); |
| 1242 | } |
| 1243 | |
| 1244 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1245 | HandleGoto(got, got->GetSuccessor()); |
| 1246 | } |
| 1247 | |
| 1248 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1249 | try_boundary->SetLocations(nullptr); |
| 1250 | } |
| 1251 | |
| 1252 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1253 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1254 | if (!successor->IsExitBlock()) { |
| 1255 | HandleGoto(try_boundary, successor); |
| 1256 | } |
| 1257 | } |
| 1258 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1259 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1260 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1263 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1266 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1267 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1268 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1269 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1270 | if (rhs_loc.IsConstant()) { |
| 1271 | // 0.0 is the only immediate that can be encoded directly in |
| 1272 | // a VCMP instruction. |
| 1273 | // |
| 1274 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1275 | // specify that in a floating-point comparison, positive zero |
| 1276 | // and negative zero are considered equal, so we can use the |
| 1277 | // literal 0.0 for both cases here. |
| 1278 | // |
| 1279 | // Note however that some methods (Float.equal, Float.compare, |
| 1280 | // Float.compareTo, Double.equal, Double.compare, |
| 1281 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1282 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1283 | // -0.0. So if we ever translate calls to these methods into a |
| 1284 | // HCompare instruction, we must handle the -0.0 case with |
| 1285 | // care here. |
| 1286 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1287 | if (type == Primitive::kPrimFloat) { |
| 1288 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1289 | } else { |
| 1290 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1291 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1292 | } |
| 1293 | } else { |
| 1294 | if (type == Primitive::kPrimFloat) { |
| 1295 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1296 | } else { |
| 1297 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1298 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1299 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1304 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1305 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1306 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1307 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1308 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1312 | Label* true_label, |
| 1313 | Label* false_label) { |
| 1314 | LocationSummary* locations = cond->GetLocations(); |
| 1315 | Location left = locations->InAt(0); |
| 1316 | Location right = locations->InAt(1); |
| 1317 | IfCondition if_cond = cond->GetCondition(); |
| 1318 | |
| 1319 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1320 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1321 | IfCondition true_high_cond = if_cond; |
| 1322 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1323 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1324 | |
| 1325 | // Set the conditions for the test, remembering that == needs to be |
| 1326 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1327 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1328 | switch (if_cond) { |
| 1329 | case kCondEQ: |
| 1330 | case kCondNE: |
| 1331 | // Nothing to do. |
| 1332 | break; |
| 1333 | case kCondLT: |
| 1334 | false_high_cond = kCondGT; |
| 1335 | break; |
| 1336 | case kCondLE: |
| 1337 | true_high_cond = kCondLT; |
| 1338 | break; |
| 1339 | case kCondGT: |
| 1340 | false_high_cond = kCondLT; |
| 1341 | break; |
| 1342 | case kCondGE: |
| 1343 | true_high_cond = kCondGT; |
| 1344 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1345 | case kCondB: |
| 1346 | false_high_cond = kCondA; |
| 1347 | break; |
| 1348 | case kCondBE: |
| 1349 | true_high_cond = kCondB; |
| 1350 | break; |
| 1351 | case kCondA: |
| 1352 | false_high_cond = kCondB; |
| 1353 | break; |
| 1354 | case kCondAE: |
| 1355 | true_high_cond = kCondA; |
| 1356 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1357 | } |
| 1358 | if (right.IsConstant()) { |
| 1359 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1360 | int32_t val_low = Low32Bits(value); |
| 1361 | int32_t val_high = High32Bits(value); |
| 1362 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1363 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1364 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1365 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1366 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1367 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1368 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1369 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1370 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1371 | } |
| 1372 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1373 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1374 | } else { |
| 1375 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1376 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1377 | |
| 1378 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1379 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1380 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1381 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1382 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1383 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1384 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1385 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1386 | } |
| 1387 | // Must be equal high, so compare the lows. |
| 1388 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1389 | } |
| 1390 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1391 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1392 | __ b(true_label, final_condition); |
| 1393 | } |
| 1394 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1395 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1396 | Label* true_target_in, |
| 1397 | Label* false_target_in) { |
| 1398 | // Generated branching requires both targets to be explicit. If either of the |
| 1399 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1400 | Label fallthrough_target; |
| 1401 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1402 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1403 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1404 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1405 | switch (type) { |
| 1406 | case Primitive::kPrimLong: |
| 1407 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1408 | break; |
| 1409 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1410 | case Primitive::kPrimDouble: |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1411 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | GenerateFPJumps(condition, true_target, false_target); |
| 1413 | break; |
| 1414 | default: |
| 1415 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1416 | } |
| 1417 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1418 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1419 | __ b(false_target); |
| 1420 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1421 | |
| 1422 | if (fallthrough_target.IsLinked()) { |
| 1423 | __ Bind(&fallthrough_target); |
| 1424 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1427 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1428 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1429 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1430 | Label* false_target) { |
| 1431 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1432 | |
| 1433 | if (true_target == nullptr && false_target == nullptr) { |
| 1434 | // Nothing to do. The code always falls through. |
| 1435 | return; |
| 1436 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1437 | // Constant condition, statically compared against "true" (integer value 1). |
| 1438 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1439 | if (true_target != nullptr) { |
| 1440 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1441 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1442 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1443 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1444 | if (false_target != nullptr) { |
| 1445 | __ b(false_target); |
| 1446 | } |
| 1447 | } |
| 1448 | return; |
| 1449 | } |
| 1450 | |
| 1451 | // The following code generates these patterns: |
| 1452 | // (1) true_target == nullptr && false_target != nullptr |
| 1453 | // - opposite condition true => branch to false_target |
| 1454 | // (2) true_target != nullptr && false_target == nullptr |
| 1455 | // - condition true => branch to true_target |
| 1456 | // (3) true_target != nullptr && false_target != nullptr |
| 1457 | // - condition true => branch to true_target |
| 1458 | // - branch to false_target |
| 1459 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1460 | // Condition has been materialized, compare the output to 0. |
| 1461 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1462 | DCHECK(cond_val.IsRegister()); |
| 1463 | if (true_target == nullptr) { |
| 1464 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1465 | } else { |
| 1466 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1467 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1468 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1469 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1470 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1471 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1472 | |
| 1473 | // If this is a long or FP comparison that has been folded into |
| 1474 | // the HCondition, generate the comparison directly. |
| 1475 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1476 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1477 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1478 | return; |
| 1479 | } |
| 1480 | |
| 1481 | LocationSummary* locations = cond->GetLocations(); |
| 1482 | DCHECK(locations->InAt(0).IsRegister()); |
| 1483 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1484 | Location right = locations->InAt(1); |
| 1485 | if (right.IsRegister()) { |
| 1486 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1487 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1488 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1489 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1490 | } |
| 1491 | if (true_target == nullptr) { |
| 1492 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1493 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1494 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1495 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1496 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1497 | |
| 1498 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1499 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1500 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1501 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1505 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1506 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1507 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1513 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1514 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1515 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1516 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1517 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1518 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1519 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1523 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1524 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1525 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1531 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1532 | GenerateTestAndBranch(deoptimize, |
| 1533 | /* condition_input_index */ 0, |
| 1534 | slow_path->GetEntryLabel(), |
| 1535 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1536 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1537 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1538 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1539 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1540 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1541 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1542 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1543 | } else { |
| 1544 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1545 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1546 | } |
| 1547 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1548 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1549 | } |
| 1550 | locations->SetOut(Location::SameAsFirstInput()); |
| 1551 | } |
| 1552 | |
| 1553 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 1554 | LocationSummary* locations = select->GetLocations(); |
| 1555 | Label false_target; |
| 1556 | GenerateTestAndBranch(select, |
| 1557 | /* condition_input_index */ 2, |
| 1558 | /* true_target */ nullptr, |
| 1559 | &false_target); |
| 1560 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1561 | __ Bind(&false_target); |
| 1562 | } |
| 1563 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1564 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1565 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1566 | } |
| 1567 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1568 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1569 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | void CodeGeneratorARM::GenerateNop() { |
| 1573 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1576 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1577 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1578 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1579 | // Handle the long/FP comparisons made in instruction simplification. |
| 1580 | switch (cond->InputAt(0)->GetType()) { |
| 1581 | case Primitive::kPrimLong: |
| 1582 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1583 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1584 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1585 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1586 | } |
| 1587 | break; |
| 1588 | |
| 1589 | case Primitive::kPrimFloat: |
| 1590 | case Primitive::kPrimDouble: |
| 1591 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1592 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1593 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1594 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1595 | } |
| 1596 | break; |
| 1597 | |
| 1598 | default: |
| 1599 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1600 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1601 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1602 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1603 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1604 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1607 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1608 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1609 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1610 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1611 | |
| 1612 | LocationSummary* locations = cond->GetLocations(); |
| 1613 | Location left = locations->InAt(0); |
| 1614 | Location right = locations->InAt(1); |
| 1615 | Register out = locations->Out().AsRegister<Register>(); |
| 1616 | Label true_label, false_label; |
| 1617 | |
| 1618 | switch (cond->InputAt(0)->GetType()) { |
| 1619 | default: { |
| 1620 | // Integer case. |
| 1621 | if (right.IsRegister()) { |
| 1622 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1623 | } else { |
| 1624 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1625 | __ CmpConstant(left.AsRegister<Register>(), |
| 1626 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1627 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1628 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1629 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1630 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1631 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1632 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1633 | return; |
| 1634 | } |
| 1635 | case Primitive::kPrimLong: |
| 1636 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1637 | break; |
| 1638 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1639 | case Primitive::kPrimDouble: |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1640 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1641 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1642 | break; |
| 1643 | } |
| 1644 | |
| 1645 | // Convert the jumps into the result. |
| 1646 | Label done_label; |
| 1647 | |
| 1648 | // False case: result = 0. |
| 1649 | __ Bind(&false_label); |
| 1650 | __ LoadImmediate(out, 0); |
| 1651 | __ b(&done_label); |
| 1652 | |
| 1653 | // True case: result = 1. |
| 1654 | __ Bind(&true_label); |
| 1655 | __ LoadImmediate(out, 1); |
| 1656 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1660 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1664 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1668 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1672 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1676 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1680 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1684 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1688 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1692 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1696 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1700 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1704 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1707 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1708 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1712 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1716 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1720 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1724 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1728 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1732 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1736 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1739 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1740 | LocationSummary* locations = |
| 1741 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1742 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1745 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1746 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1749 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1750 | LocationSummary* locations = |
| 1751 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1752 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1753 | } |
| 1754 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1755 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1756 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1759 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1760 | LocationSummary* locations = |
| 1761 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1762 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1765 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1766 | // Will be generated at use site. |
| 1767 | } |
| 1768 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1769 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1770 | LocationSummary* locations = |
| 1771 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1772 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1773 | } |
| 1774 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1775 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1776 | // Will be generated at use site. |
| 1777 | } |
| 1778 | |
| 1779 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1780 | LocationSummary* locations = |
| 1781 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1782 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1783 | } |
| 1784 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1785 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1786 | // Will be generated at use site. |
| 1787 | } |
| 1788 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1789 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1790 | memory_barrier->SetLocations(nullptr); |
| 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1794 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1797 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1798 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1801 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1802 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1805 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1806 | LocationSummary* locations = |
| 1807 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1808 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1811 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1812 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1815 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1816 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1817 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1818 | // the method_idx. |
| 1819 | HandleInvoke(invoke); |
| 1820 | } |
| 1821 | |
| 1822 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1823 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1824 | } |
| 1825 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1826 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1827 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1828 | // art::PrepareForRegisterAllocation. |
| 1829 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1830 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1831 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1832 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1833 | codegen_->GetInstructionSetFeatures()); |
| 1834 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1835 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 1836 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 1837 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1838 | return; |
| 1839 | } |
| 1840 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1841 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1842 | |
| 1843 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1844 | if (invoke->HasPcRelativeDexCache()) { |
| 1845 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 1846 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1847 | } |
| 1848 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1849 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1850 | if (invoke->GetLocations()->Intrinsified()) { |
| 1851 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1852 | intrinsic.Dispatch(invoke); |
| 1853 | return true; |
| 1854 | } |
| 1855 | return false; |
| 1856 | } |
| 1857 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1858 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1859 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1860 | // art::PrepareForRegisterAllocation. |
| 1861 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1862 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1863 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1864 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1865 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1866 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1867 | LocationSummary* locations = invoke->GetLocations(); |
| 1868 | codegen_->GenerateStaticOrDirectCall( |
| 1869 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1870 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1871 | } |
| 1872 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1873 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1874 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1875 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1878 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1879 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1880 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1881 | codegen_->GetInstructionSetFeatures()); |
| 1882 | if (intrinsic.TryDispatch(invoke)) { |
| 1883 | return; |
| 1884 | } |
| 1885 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1886 | HandleInvoke(invoke); |
| 1887 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1888 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1889 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1890 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1891 | return; |
| 1892 | } |
| 1893 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1894 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1895 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1896 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1899 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1900 | HandleInvoke(invoke); |
| 1901 | // Add the hidden argument. |
| 1902 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1903 | } |
| 1904 | |
| 1905 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1906 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1907 | LocationSummary* locations = invoke->GetLocations(); |
| 1908 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1909 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1910 | Location receiver = locations->InAt(0); |
| 1911 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1912 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1913 | // Set the hidden argument. This is safe to do this here, as R12 |
| 1914 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 1915 | DCHECK_EQ(R12, hidden_reg); |
| 1916 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1917 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1918 | if (receiver.IsStackSlot()) { |
| 1919 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1920 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1921 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1922 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1923 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1924 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1925 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1926 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1927 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1928 | // emit a read barrier for the previous class reference load. |
| 1929 | // However this is not required in practice, as this is an |
| 1930 | // intermediate/temporary reference and because the current |
| 1931 | // concurrent copying collector keeps the from-space memory |
| 1932 | // intact/accessible until the end of the marking phase (the |
| 1933 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1934 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | df2d4f2 | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1935 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 1936 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 1937 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 1938 | invoke->GetImtIndex() % ImTable::kSize, kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1939 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | df2d4f2 | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1940 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1941 | uint32_t entry_point = |
| 1942 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1943 | // LR = temp->GetEntryPoint(); |
| 1944 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1945 | // LR(); |
| 1946 | __ blx(LR); |
| 1947 | DCHECK(!codegen_->IsLeafMethod()); |
| 1948 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1949 | } |
| 1950 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1951 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1952 | LocationSummary* locations = |
| 1953 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1954 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1955 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1956 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 1957 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1958 | break; |
| 1959 | } |
| 1960 | case Primitive::kPrimLong: { |
| 1961 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1962 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1963 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1964 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1965 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1966 | case Primitive::kPrimFloat: |
| 1967 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1968 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1969 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1970 | break; |
| 1971 | |
| 1972 | default: |
| 1973 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1978 | LocationSummary* locations = neg->GetLocations(); |
| 1979 | Location out = locations->Out(); |
| 1980 | Location in = locations->InAt(0); |
| 1981 | switch (neg->GetResultType()) { |
| 1982 | case Primitive::kPrimInt: |
| 1983 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1984 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1985 | break; |
| 1986 | |
| 1987 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1988 | DCHECK(in.IsRegisterPair()); |
| 1989 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1990 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1991 | in.AsRegisterPairLow<Register>(), |
| 1992 | ShifterOperand(0)); |
| 1993 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1994 | // instruction here, as it does not exist in the Thumb-2 |
| 1995 | // instruction set. We use the following approach |
| 1996 | // using SBC and SUB instead. |
| 1997 | // |
| 1998 | // out.hi = -C |
| 1999 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2000 | out.AsRegisterPairHigh<Register>(), |
| 2001 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2002 | // out.hi = out.hi - in.hi |
| 2003 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2004 | out.AsRegisterPairHigh<Register>(), |
| 2005 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2006 | break; |
| 2007 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2008 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2009 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2010 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2011 | break; |
| 2012 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2013 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2014 | DCHECK(in.IsFpuRegisterPair()); |
| 2015 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2016 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2017 | break; |
| 2018 | |
| 2019 | default: |
| 2020 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2021 | } |
| 2022 | } |
| 2023 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2024 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2025 | Primitive::Type result_type = conversion->GetResultType(); |
| 2026 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2027 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2028 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2029 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2030 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2031 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2032 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2033 | && result_type == Primitive::kPrimLong) |
| 2034 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2035 | ? LocationSummary::kCall |
| 2036 | : LocationSummary::kNoCall; |
| 2037 | LocationSummary* locations = |
| 2038 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2039 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2040 | // The Java language does not allow treating boolean as an integral type but |
| 2041 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2042 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2043 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2044 | case Primitive::kPrimByte: |
| 2045 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2046 | case Primitive::kPrimLong: |
| 2047 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimBoolean: |
| 2049 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2050 | case Primitive::kPrimShort: |
| 2051 | case Primitive::kPrimInt: |
| 2052 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2053 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2054 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2055 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2056 | break; |
| 2057 | |
| 2058 | default: |
| 2059 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2060 | << " to " << result_type; |
| 2061 | } |
| 2062 | break; |
| 2063 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2064 | case Primitive::kPrimShort: |
| 2065 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2066 | case Primitive::kPrimLong: |
| 2067 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2068 | case Primitive::kPrimBoolean: |
| 2069 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2070 | case Primitive::kPrimByte: |
| 2071 | case Primitive::kPrimInt: |
| 2072 | case Primitive::kPrimChar: |
| 2073 | // Processing a Dex `int-to-short' instruction. |
| 2074 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2075 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2076 | break; |
| 2077 | |
| 2078 | default: |
| 2079 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2080 | << " to " << result_type; |
| 2081 | } |
| 2082 | break; |
| 2083 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2084 | case Primitive::kPrimInt: |
| 2085 | switch (input_type) { |
| 2086 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2087 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2088 | locations->SetInAt(0, Location::Any()); |
| 2089 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2090 | break; |
| 2091 | |
| 2092 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2093 | // Processing a Dex `float-to-int' instruction. |
| 2094 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2095 | locations->SetOut(Location::RequiresRegister()); |
| 2096 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2097 | break; |
| 2098 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2099 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2100 | // Processing a Dex `double-to-int' instruction. |
| 2101 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2102 | locations->SetOut(Location::RequiresRegister()); |
| 2103 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2104 | break; |
| 2105 | |
| 2106 | default: |
| 2107 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2108 | << " to " << result_type; |
| 2109 | } |
| 2110 | break; |
| 2111 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimLong: |
| 2113 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimBoolean: |
| 2115 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2116 | case Primitive::kPrimByte: |
| 2117 | case Primitive::kPrimShort: |
| 2118 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2119 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2120 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2122 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2123 | break; |
| 2124 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2125 | case Primitive::kPrimFloat: { |
| 2126 | // Processing a Dex `float-to-long' instruction. |
| 2127 | InvokeRuntimeCallingConvention calling_convention; |
| 2128 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2129 | calling_convention.GetFpuRegisterAt(0))); |
| 2130 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2131 | break; |
| 2132 | } |
| 2133 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2134 | case Primitive::kPrimDouble: { |
| 2135 | // Processing a Dex `double-to-long' instruction. |
| 2136 | InvokeRuntimeCallingConvention calling_convention; |
| 2137 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2138 | calling_convention.GetFpuRegisterAt(0), |
| 2139 | calling_convention.GetFpuRegisterAt(1))); |
| 2140 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2141 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2142 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2143 | |
| 2144 | default: |
| 2145 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2146 | << " to " << result_type; |
| 2147 | } |
| 2148 | break; |
| 2149 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2150 | case Primitive::kPrimChar: |
| 2151 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimLong: |
| 2153 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimBoolean: |
| 2155 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimByte: |
| 2157 | case Primitive::kPrimShort: |
| 2158 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2159 | // Processing a Dex `int-to-char' instruction. |
| 2160 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2161 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2162 | break; |
| 2163 | |
| 2164 | default: |
| 2165 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2166 | << " to " << result_type; |
| 2167 | } |
| 2168 | break; |
| 2169 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2170 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2171 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2172 | case Primitive::kPrimBoolean: |
| 2173 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2174 | case Primitive::kPrimByte: |
| 2175 | case Primitive::kPrimShort: |
| 2176 | case Primitive::kPrimInt: |
| 2177 | case Primitive::kPrimChar: |
| 2178 | // Processing a Dex `int-to-float' instruction. |
| 2179 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2180 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2181 | break; |
| 2182 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2183 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2184 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2185 | InvokeRuntimeCallingConvention calling_convention; |
| 2186 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2187 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2188 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2189 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2190 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2191 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2192 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2193 | // Processing a Dex `double-to-float' instruction. |
| 2194 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2195 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2196 | break; |
| 2197 | |
| 2198 | default: |
| 2199 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2200 | << " to " << result_type; |
| 2201 | }; |
| 2202 | break; |
| 2203 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2204 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2205 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2206 | case Primitive::kPrimBoolean: |
| 2207 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2208 | case Primitive::kPrimByte: |
| 2209 | case Primitive::kPrimShort: |
| 2210 | case Primitive::kPrimInt: |
| 2211 | case Primitive::kPrimChar: |
| 2212 | // Processing a Dex `int-to-double' instruction. |
| 2213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2214 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2215 | break; |
| 2216 | |
| 2217 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2218 | // Processing a Dex `long-to-double' instruction. |
| 2219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2220 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2221 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2222 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2223 | break; |
| 2224 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2225 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2226 | // Processing a Dex `float-to-double' instruction. |
| 2227 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2228 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2229 | break; |
| 2230 | |
| 2231 | default: |
| 2232 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2233 | << " to " << result_type; |
| 2234 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2235 | break; |
| 2236 | |
| 2237 | default: |
| 2238 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2239 | << " to " << result_type; |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2244 | LocationSummary* locations = conversion->GetLocations(); |
| 2245 | Location out = locations->Out(); |
| 2246 | Location in = locations->InAt(0); |
| 2247 | Primitive::Type result_type = conversion->GetResultType(); |
| 2248 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2249 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2250 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimByte: |
| 2252 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2253 | case Primitive::kPrimLong: |
| 2254 | // Type conversion from long to byte is a result of code transformations. |
| 2255 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2256 | break; |
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 | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimShort: |
| 2260 | case Primitive::kPrimInt: |
| 2261 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2262 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2263 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2264 | break; |
| 2265 | |
| 2266 | default: |
| 2267 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2268 | << " to " << result_type; |
| 2269 | } |
| 2270 | break; |
| 2271 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimShort: |
| 2273 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2274 | case Primitive::kPrimLong: |
| 2275 | // Type conversion from long to short is a result of code transformations. |
| 2276 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2277 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimBoolean: |
| 2279 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimByte: |
| 2281 | case Primitive::kPrimInt: |
| 2282 | case Primitive::kPrimChar: |
| 2283 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2284 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2285 | break; |
| 2286 | |
| 2287 | default: |
| 2288 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2289 | << " to " << result_type; |
| 2290 | } |
| 2291 | break; |
| 2292 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2293 | case Primitive::kPrimInt: |
| 2294 | switch (input_type) { |
| 2295 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2296 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2297 | DCHECK(out.IsRegister()); |
| 2298 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2299 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2300 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2301 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2302 | } else { |
| 2303 | DCHECK(in.IsConstant()); |
| 2304 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2305 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2306 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2307 | } |
| 2308 | break; |
| 2309 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimFloat: { |
| 2311 | // Processing a Dex `float-to-int' instruction. |
| 2312 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 9cfdcf4 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2313 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2314 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2315 | break; |
| 2316 | } |
| 2317 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimDouble: { |
| 2319 | // Processing a Dex `double-to-int' instruction. |
| 2320 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 9cfdcf4 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2321 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2322 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2323 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2324 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2325 | |
| 2326 | default: |
| 2327 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2328 | << " to " << result_type; |
| 2329 | } |
| 2330 | break; |
| 2331 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimLong: |
| 2333 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2334 | case Primitive::kPrimBoolean: |
| 2335 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2336 | case Primitive::kPrimByte: |
| 2337 | case Primitive::kPrimShort: |
| 2338 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2340 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2341 | DCHECK(out.IsRegisterPair()); |
| 2342 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2343 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2344 | // Sign extension. |
| 2345 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2346 | out.AsRegisterPairLow<Register>(), |
| 2347 | 31); |
| 2348 | break; |
| 2349 | |
| 2350 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2351 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2352 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2353 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2354 | conversion->GetDexPc(), |
| 2355 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2356 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2357 | break; |
| 2358 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2360 | // Processing a Dex `double-to-long' instruction. |
| 2361 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2362 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2363 | conversion->GetDexPc(), |
| 2364 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2365 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2366 | break; |
| 2367 | |
| 2368 | default: |
| 2369 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2370 | << " to " << result_type; |
| 2371 | } |
| 2372 | break; |
| 2373 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimChar: |
| 2375 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimLong: |
| 2377 | // Type conversion from long to char is a result of code transformations. |
| 2378 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2379 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimBoolean: |
| 2381 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimByte: |
| 2383 | case Primitive::kPrimShort: |
| 2384 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2385 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2386 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | |
| 2389 | default: |
| 2390 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2391 | << " to " << result_type; |
| 2392 | } |
| 2393 | break; |
| 2394 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2396 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimBoolean: |
| 2398 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimByte: |
| 2400 | case Primitive::kPrimShort: |
| 2401 | case Primitive::kPrimInt: |
| 2402 | case Primitive::kPrimChar: { |
| 2403 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2404 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2405 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2409 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2410 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2411 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2412 | conversion, |
| 2413 | conversion->GetDexPc(), |
| 2414 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2415 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2416 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2417 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2419 | // Processing a Dex `double-to-float' instruction. |
| 2420 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2421 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2422 | break; |
| 2423 | |
| 2424 | default: |
| 2425 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2426 | << " to " << result_type; |
| 2427 | }; |
| 2428 | break; |
| 2429 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2431 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimBoolean: |
| 2433 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimByte: |
| 2435 | case Primitive::kPrimShort: |
| 2436 | case Primitive::kPrimInt: |
| 2437 | case Primitive::kPrimChar: { |
| 2438 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2439 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2440 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2441 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2442 | break; |
| 2443 | } |
| 2444 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2445 | case Primitive::kPrimLong: { |
| 2446 | // Processing a Dex `long-to-double' instruction. |
| 2447 | Register low = in.AsRegisterPairLow<Register>(); |
| 2448 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2449 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2450 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2451 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2452 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2453 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2454 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2455 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2456 | // temp_d = int-to-double(high) |
| 2457 | __ vmovsr(temp_s, high); |
| 2458 | __ vcvtdi(temp_d, temp_s); |
| 2459 | // constant_d = k2Pow32EncodingForDouble |
| 2460 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2461 | // out_d = unsigned-to-double(low) |
| 2462 | __ vmovsr(out_s, low); |
| 2463 | __ vcvtdu(out_d, out_s); |
| 2464 | // out_d += temp_d * constant_d |
| 2465 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2466 | break; |
| 2467 | } |
| 2468 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2469 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2470 | // Processing a Dex `float-to-double' instruction. |
| 2471 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2472 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2473 | break; |
| 2474 | |
| 2475 | default: |
| 2476 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2477 | << " to " << result_type; |
| 2478 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | |
| 2481 | default: |
| 2482 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2483 | << " to " << result_type; |
| 2484 | } |
| 2485 | } |
| 2486 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2487 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2488 | LocationSummary* locations = |
| 2489 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2490 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2492 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2493 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2494 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2495 | break; |
| 2496 | } |
| 2497 | |
| 2498 | case Primitive::kPrimLong: { |
| 2499 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2500 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2502 | break; |
| 2503 | } |
| 2504 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2505 | case Primitive::kPrimFloat: |
| 2506 | case Primitive::kPrimDouble: { |
| 2507 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2508 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2509 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2510 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2511 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2512 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2513 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2514 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2515 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2519 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2520 | Location out = locations->Out(); |
| 2521 | Location first = locations->InAt(0); |
| 2522 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2523 | switch (add->GetResultType()) { |
| 2524 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2525 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2526 | __ add(out.AsRegister<Register>(), |
| 2527 | first.AsRegister<Register>(), |
| 2528 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2529 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2530 | __ AddConstant(out.AsRegister<Register>(), |
| 2531 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2532 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2533 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2534 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2535 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimLong: { |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2537 | if (second.IsConstant()) { |
| 2538 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2539 | GenerateAddLongConst(out, first, value); |
| 2540 | } else { |
| 2541 | DCHECK(second.IsRegisterPair()); |
| 2542 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2543 | first.AsRegisterPairLow<Register>(), |
| 2544 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2545 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2546 | first.AsRegisterPairHigh<Register>(), |
| 2547 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2548 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2549 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2550 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2551 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2552 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2553 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2554 | first.AsFpuRegister<SRegister>(), |
| 2555 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2556 | break; |
| 2557 | |
| 2558 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2559 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2560 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2561 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2562 | break; |
| 2563 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2564 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2565 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2566 | } |
| 2567 | } |
| 2568 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2569 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2570 | LocationSummary* locations = |
| 2571 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2572 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2573 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2575 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2577 | break; |
| 2578 | } |
| 2579 | |
| 2580 | case Primitive::kPrimLong: { |
| 2581 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2582 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2583 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2584 | break; |
| 2585 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2586 | case Primitive::kPrimFloat: |
| 2587 | case Primitive::kPrimDouble: { |
| 2588 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2589 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2590 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2591 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2592 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2593 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2594 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2595 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2599 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2600 | Location out = locations->Out(); |
| 2601 | Location first = locations->InAt(0); |
| 2602 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2603 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2604 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2605 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2606 | __ sub(out.AsRegister<Register>(), |
| 2607 | first.AsRegister<Register>(), |
| 2608 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2609 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2610 | __ AddConstant(out.AsRegister<Register>(), |
| 2611 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2612 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2613 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2614 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2615 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2616 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2617 | case Primitive::kPrimLong: { |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2618 | if (second.IsConstant()) { |
| 2619 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2620 | GenerateAddLongConst(out, first, -value); |
| 2621 | } else { |
| 2622 | DCHECK(second.IsRegisterPair()); |
| 2623 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2624 | first.AsRegisterPairLow<Register>(), |
| 2625 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2626 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2627 | first.AsRegisterPairHigh<Register>(), |
| 2628 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2629 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2630 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2631 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2632 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2633 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2634 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2635 | first.AsFpuRegister<SRegister>(), |
| 2636 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2637 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2641 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2642 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2643 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2644 | break; |
| 2645 | } |
| 2646 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2647 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2648 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2649 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2653 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2654 | LocationSummary* locations = |
| 2655 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2656 | switch (mul->GetResultType()) { |
| 2657 | case Primitive::kPrimInt: |
| 2658 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2660 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2661 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2662 | break; |
| 2663 | } |
| 2664 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2665 | case Primitive::kPrimFloat: |
| 2666 | case Primitive::kPrimDouble: { |
| 2667 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2668 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2669 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2670 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2671 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2672 | |
| 2673 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2674 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2679 | LocationSummary* locations = mul->GetLocations(); |
| 2680 | Location out = locations->Out(); |
| 2681 | Location first = locations->InAt(0); |
| 2682 | Location second = locations->InAt(1); |
| 2683 | switch (mul->GetResultType()) { |
| 2684 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2685 | __ mul(out.AsRegister<Register>(), |
| 2686 | first.AsRegister<Register>(), |
| 2687 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2688 | break; |
| 2689 | } |
| 2690 | case Primitive::kPrimLong: { |
| 2691 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2692 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2693 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2694 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2695 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2696 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2697 | |
| 2698 | // Extra checks to protect caused by the existence of R1_R2. |
| 2699 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2700 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2701 | DCHECK_NE(out_hi, in1_lo); |
| 2702 | DCHECK_NE(out_hi, in2_lo); |
| 2703 | |
| 2704 | // input: in1 - 64 bits, in2 - 64 bits |
| 2705 | // output: out |
| 2706 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2707 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2708 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2709 | |
| 2710 | // IP <- in1.lo * in2.hi |
| 2711 | __ mul(IP, in1_lo, in2_hi); |
| 2712 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2713 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2714 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2715 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2716 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2717 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2718 | break; |
| 2719 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2720 | |
| 2721 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2722 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2723 | first.AsFpuRegister<SRegister>(), |
| 2724 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2725 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2729 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2730 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2731 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2732 | break; |
| 2733 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2734 | |
| 2735 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2736 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2737 | } |
| 2738 | } |
| 2739 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2740 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2741 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2742 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2743 | |
| 2744 | LocationSummary* locations = instruction->GetLocations(); |
| 2745 | Location second = locations->InAt(1); |
| 2746 | DCHECK(second.IsConstant()); |
| 2747 | |
| 2748 | Register out = locations->Out().AsRegister<Register>(); |
| 2749 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2750 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2751 | DCHECK(imm == 1 || imm == -1); |
| 2752 | |
| 2753 | if (instruction->IsRem()) { |
| 2754 | __ LoadImmediate(out, 0); |
| 2755 | } else { |
| 2756 | if (imm == 1) { |
| 2757 | __ Mov(out, dividend); |
| 2758 | } else { |
| 2759 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2765 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2766 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2767 | |
| 2768 | LocationSummary* locations = instruction->GetLocations(); |
| 2769 | Location second = locations->InAt(1); |
| 2770 | DCHECK(second.IsConstant()); |
| 2771 | |
| 2772 | Register out = locations->Out().AsRegister<Register>(); |
| 2773 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2774 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2775 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2776 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2777 | int ctz_imm = CTZ(abs_imm); |
| 2778 | |
| 2779 | if (ctz_imm == 1) { |
| 2780 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2781 | } else { |
| 2782 | __ Asr(temp, dividend, 31); |
| 2783 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2784 | } |
| 2785 | __ add(out, temp, ShifterOperand(dividend)); |
| 2786 | |
| 2787 | if (instruction->IsDiv()) { |
| 2788 | __ Asr(out, out, ctz_imm); |
| 2789 | if (imm < 0) { |
| 2790 | __ rsb(out, out, ShifterOperand(0)); |
| 2791 | } |
| 2792 | } else { |
| 2793 | __ ubfx(out, out, 0, ctz_imm); |
| 2794 | __ sub(out, out, ShifterOperand(temp)); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2799 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2800 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2801 | |
| 2802 | LocationSummary* locations = instruction->GetLocations(); |
| 2803 | Location second = locations->InAt(1); |
| 2804 | DCHECK(second.IsConstant()); |
| 2805 | |
| 2806 | Register out = locations->Out().AsRegister<Register>(); |
| 2807 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2808 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2809 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2810 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2811 | |
| 2812 | int64_t magic; |
| 2813 | int shift; |
| 2814 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2815 | |
| 2816 | __ LoadImmediate(temp1, magic); |
| 2817 | __ smull(temp2, temp1, dividend, temp1); |
| 2818 | |
| 2819 | if (imm > 0 && magic < 0) { |
| 2820 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2821 | } else if (imm < 0 && magic > 0) { |
| 2822 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2823 | } |
| 2824 | |
| 2825 | if (shift != 0) { |
| 2826 | __ Asr(temp1, temp1, shift); |
| 2827 | } |
| 2828 | |
| 2829 | if (instruction->IsDiv()) { |
| 2830 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2831 | } else { |
| 2832 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2833 | // TODO: Strength reduction for mls. |
| 2834 | __ LoadImmediate(temp2, imm); |
| 2835 | __ mls(out, temp1, temp2, dividend); |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2840 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2841 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2842 | |
| 2843 | LocationSummary* locations = instruction->GetLocations(); |
| 2844 | Location second = locations->InAt(1); |
| 2845 | DCHECK(second.IsConstant()); |
| 2846 | |
| 2847 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2848 | if (imm == 0) { |
| 2849 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2850 | } else if (imm == 1 || imm == -1) { |
| 2851 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2852 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2853 | DivRemByPowerOfTwo(instruction); |
| 2854 | } else { |
| 2855 | DCHECK(imm <= -2 || imm >= 2); |
| 2856 | GenerateDivRemWithAnyConstant(instruction); |
| 2857 | } |
| 2858 | } |
| 2859 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2860 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2861 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2862 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2863 | // pLdiv runtime call. |
| 2864 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2865 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2866 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2867 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2868 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2869 | // pIdivmod runtime call. |
| 2870 | call_kind = LocationSummary::kCall; |
| 2871 | } |
| 2872 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2873 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2874 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2875 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2876 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2877 | if (div->InputAt(1)->IsConstant()) { |
| 2878 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2879 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2880 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2881 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 2882 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2883 | // No temp register required. |
| 2884 | } else { |
| 2885 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2886 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2887 | locations->AddTemp(Location::RequiresRegister()); |
| 2888 | } |
| 2889 | } |
| 2890 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2891 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2892 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2893 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2894 | } else { |
| 2895 | InvokeRuntimeCallingConvention calling_convention; |
| 2896 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2897 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2898 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2899 | // we only need the former. |
| 2900 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2901 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2904 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2905 | InvokeRuntimeCallingConvention calling_convention; |
| 2906 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2907 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2908 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2909 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2910 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2911 | break; |
| 2912 | } |
| 2913 | case Primitive::kPrimFloat: |
| 2914 | case Primitive::kPrimDouble: { |
| 2915 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2916 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2917 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2918 | break; |
| 2919 | } |
| 2920 | |
| 2921 | default: |
| 2922 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2927 | LocationSummary* locations = div->GetLocations(); |
| 2928 | Location out = locations->Out(); |
| 2929 | Location first = locations->InAt(0); |
| 2930 | Location second = locations->InAt(1); |
| 2931 | |
| 2932 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2933 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2934 | if (second.IsConstant()) { |
| 2935 | GenerateDivRemConstantIntegral(div); |
| 2936 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2937 | __ sdiv(out.AsRegister<Register>(), |
| 2938 | first.AsRegister<Register>(), |
| 2939 | second.AsRegister<Register>()); |
| 2940 | } else { |
| 2941 | InvokeRuntimeCallingConvention calling_convention; |
| 2942 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2943 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2944 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2945 | |
| 2946 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2947 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2948 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2949 | break; |
| 2950 | } |
| 2951 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2952 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2953 | InvokeRuntimeCallingConvention calling_convention; |
| 2954 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2955 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2956 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2957 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2958 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2959 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2960 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2961 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2962 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2963 | break; |
| 2964 | } |
| 2965 | |
| 2966 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2967 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2968 | first.AsFpuRegister<SRegister>(), |
| 2969 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2970 | break; |
| 2971 | } |
| 2972 | |
| 2973 | case Primitive::kPrimDouble: { |
| 2974 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2975 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2976 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2977 | break; |
| 2978 | } |
| 2979 | |
| 2980 | default: |
| 2981 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2982 | } |
| 2983 | } |
| 2984 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2985 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2986 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2987 | |
| 2988 | // Most remainders are implemented in the runtime. |
| 2989 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2990 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 2991 | // sdiv will be replaced by other instruction sequence. |
| 2992 | call_kind = LocationSummary::kNoCall; |
| 2993 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 2994 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2995 | // Have hardware divide instruction for int, do it with three instructions. |
| 2996 | call_kind = LocationSummary::kNoCall; |
| 2997 | } |
| 2998 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2999 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3000 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3001 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3002 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3003 | if (rem->InputAt(1)->IsConstant()) { |
| 3004 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3005 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3006 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3007 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3008 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3009 | // No temp register required. |
| 3010 | } else { |
| 3011 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3012 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3013 | locations->AddTemp(Location::RequiresRegister()); |
| 3014 | } |
| 3015 | } |
| 3016 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3017 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3018 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3019 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3020 | locations->AddTemp(Location::RequiresRegister()); |
| 3021 | } else { |
| 3022 | InvokeRuntimeCallingConvention calling_convention; |
| 3023 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3024 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3025 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3026 | // we only need the latter. |
| 3027 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3028 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3029 | break; |
| 3030 | } |
| 3031 | case Primitive::kPrimLong: { |
| 3032 | InvokeRuntimeCallingConvention calling_convention; |
| 3033 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3034 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3035 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3036 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3037 | // The runtime helper puts the output in R2,R3. |
| 3038 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3039 | break; |
| 3040 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3041 | case Primitive::kPrimFloat: { |
| 3042 | InvokeRuntimeCallingConvention calling_convention; |
| 3043 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3044 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3045 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3046 | break; |
| 3047 | } |
| 3048 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3049 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3050 | InvokeRuntimeCallingConvention calling_convention; |
| 3051 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3052 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3053 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3054 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3055 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3056 | break; |
| 3057 | } |
| 3058 | |
| 3059 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3060 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3065 | LocationSummary* locations = rem->GetLocations(); |
| 3066 | Location out = locations->Out(); |
| 3067 | Location first = locations->InAt(0); |
| 3068 | Location second = locations->InAt(1); |
| 3069 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3070 | Primitive::Type type = rem->GetResultType(); |
| 3071 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3072 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3073 | if (second.IsConstant()) { |
| 3074 | GenerateDivRemConstantIntegral(rem); |
| 3075 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3076 | Register reg1 = first.AsRegister<Register>(); |
| 3077 | Register reg2 = second.AsRegister<Register>(); |
| 3078 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3079 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3080 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3081 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3082 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3083 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3084 | } else { |
| 3085 | InvokeRuntimeCallingConvention calling_convention; |
| 3086 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3087 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3088 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3089 | |
| 3090 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3091 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3092 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3093 | break; |
| 3094 | } |
| 3095 | |
| 3096 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3097 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3098 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3099 | break; |
| 3100 | } |
| 3101 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3102 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3103 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3104 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3105 | break; |
| 3106 | } |
| 3107 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3108 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3109 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3110 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3111 | break; |
| 3112 | } |
| 3113 | |
| 3114 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3115 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3119 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3120 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3121 | ? LocationSummary::kCallOnSlowPath |
| 3122 | : LocationSummary::kNoCall; |
| 3123 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3124 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3125 | if (instruction->HasUses()) { |
| 3126 | locations->SetOut(Location::SameAsFirstInput()); |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3131 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3132 | codegen_->AddSlowPath(slow_path); |
| 3133 | |
| 3134 | LocationSummary* locations = instruction->GetLocations(); |
| 3135 | Location value = locations->InAt(0); |
| 3136 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3137 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3138 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3139 | case Primitive::kPrimByte: |
| 3140 | case Primitive::kPrimChar: |
| 3141 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3142 | case Primitive::kPrimInt: { |
| 3143 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3144 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3145 | } else { |
| 3146 | DCHECK(value.IsConstant()) << value; |
| 3147 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3148 | __ b(slow_path->GetEntryLabel()); |
| 3149 | } |
| 3150 | } |
| 3151 | break; |
| 3152 | } |
| 3153 | case Primitive::kPrimLong: { |
| 3154 | if (value.IsRegisterPair()) { |
| 3155 | __ orrs(IP, |
| 3156 | value.AsRegisterPairLow<Register>(), |
| 3157 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3158 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3159 | } else { |
| 3160 | DCHECK(value.IsConstant()) << value; |
| 3161 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3162 | __ b(slow_path->GetEntryLabel()); |
| 3163 | } |
| 3164 | } |
| 3165 | break; |
| 3166 | default: |
| 3167 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3168 | } |
| 3169 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3172 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3173 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3174 | Location rhs = locations->InAt(1); |
| 3175 | Register out = locations->Out().AsRegister<Register>(); |
| 3176 | |
| 3177 | if (rhs.IsConstant()) { |
| 3178 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3179 | // so map all rotations to a +ve. equivalent in that range. |
| 3180 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3181 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3182 | if (rot) { |
| 3183 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3184 | // (e.g. left by 2 bits == right by 30.) |
| 3185 | __ Ror(out, in, rot); |
| 3186 | } else if (out != in) { |
| 3187 | __ Mov(out, in); |
| 3188 | } |
| 3189 | } else { |
| 3190 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3195 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3196 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3197 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3198 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3199 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3200 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3201 | Location rhs = locations->InAt(1); |
| 3202 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3203 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3204 | |
| 3205 | if (rhs.IsConstant()) { |
| 3206 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3207 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3208 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3209 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3210 | // logic below to a simple pair of binary orr. |
| 3211 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3212 | if (rot >= kArmBitsPerWord) { |
| 3213 | rot -= kArmBitsPerWord; |
| 3214 | std::swap(in_reg_hi, in_reg_lo); |
| 3215 | } |
| 3216 | // Rotate, or mov to out for zero or word size rotations. |
| 3217 | if (rot != 0u) { |
| 3218 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3219 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3220 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3221 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3222 | } else { |
| 3223 | __ Mov(out_reg_lo, in_reg_lo); |
| 3224 | __ Mov(out_reg_hi, in_reg_hi); |
| 3225 | } |
| 3226 | } else { |
| 3227 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3228 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3229 | Label end; |
| 3230 | Label shift_by_32_plus_shift_right; |
| 3231 | |
| 3232 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3233 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3234 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3235 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3236 | |
| 3237 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3238 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3239 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3240 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3241 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3242 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3243 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3244 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3245 | __ b(&end); |
| 3246 | |
| 3247 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3248 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3249 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3250 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3251 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3252 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3253 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3254 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3255 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3256 | |
| 3257 | __ Bind(&end); |
| 3258 | } |
| 3259 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3260 | |
| 3261 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3262 | LocationSummary* locations = |
| 3263 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3264 | switch (ror->GetResultType()) { |
| 3265 | case Primitive::kPrimInt: { |
| 3266 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3267 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3268 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3269 | break; |
| 3270 | } |
| 3271 | case Primitive::kPrimLong: { |
| 3272 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3273 | if (ror->InputAt(1)->IsConstant()) { |
| 3274 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3275 | } else { |
| 3276 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3277 | locations->AddTemp(Location::RequiresRegister()); |
| 3278 | locations->AddTemp(Location::RequiresRegister()); |
| 3279 | } |
| 3280 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3281 | break; |
| 3282 | } |
| 3283 | default: |
| 3284 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3285 | } |
| 3286 | } |
| 3287 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3288 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3289 | LocationSummary* locations = ror->GetLocations(); |
| 3290 | Primitive::Type type = ror->GetResultType(); |
| 3291 | switch (type) { |
| 3292 | case Primitive::kPrimInt: { |
| 3293 | HandleIntegerRotate(locations); |
| 3294 | break; |
| 3295 | } |
| 3296 | case Primitive::kPrimLong: { |
| 3297 | HandleLongRotate(locations); |
| 3298 | break; |
| 3299 | } |
| 3300 | default: |
| 3301 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3302 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3303 | } |
| 3304 | } |
| 3305 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3306 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3307 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3308 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3309 | LocationSummary* locations = |
| 3310 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3311 | |
| 3312 | switch (op->GetResultType()) { |
| 3313 | case Primitive::kPrimInt: { |
| 3314 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3315 | if (op->InputAt(1)->IsConstant()) { |
| 3316 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3317 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3318 | } else { |
| 3319 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3320 | // Make the output overlap, as it will be used to hold the masked |
| 3321 | // second input. |
| 3322 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3323 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3324 | break; |
| 3325 | } |
| 3326 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3327 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3328 | if (op->InputAt(1)->IsConstant()) { |
| 3329 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3330 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3331 | // don't clash with high registers which the register allocator currently guarantees. |
| 3332 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3333 | } else { |
| 3334 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3335 | locations->AddTemp(Location::RequiresRegister()); |
| 3336 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3337 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | } |
| 3340 | default: |
| 3341 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3346 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3347 | |
| 3348 | LocationSummary* locations = op->GetLocations(); |
| 3349 | Location out = locations->Out(); |
| 3350 | Location first = locations->InAt(0); |
| 3351 | Location second = locations->InAt(1); |
| 3352 | |
| 3353 | Primitive::Type type = op->GetResultType(); |
| 3354 | switch (type) { |
| 3355 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3356 | Register out_reg = out.AsRegister<Register>(); |
| 3357 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3358 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3359 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3360 | // ARM doesn't mask the shift count so we need to do it ourselves. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3361 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3362 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3363 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3364 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3365 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3366 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3367 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3368 | } |
| 3369 | } else { |
| 3370 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3371 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3372 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3373 | __ Mov(out_reg, first_reg); |
| 3374 | } else if (op->IsShl()) { |
| 3375 | __ Lsl(out_reg, first_reg, shift_value); |
| 3376 | } else if (op->IsShr()) { |
| 3377 | __ Asr(out_reg, first_reg, shift_value); |
| 3378 | } else { |
| 3379 | __ Lsr(out_reg, first_reg, shift_value); |
| 3380 | } |
| 3381 | } |
| 3382 | break; |
| 3383 | } |
| 3384 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3385 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3386 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3387 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3388 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3389 | Register low = first.AsRegisterPairLow<Register>(); |
| 3390 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3391 | if (second.IsRegister()) { |
| 3392 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3393 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3394 | Register second_reg = second.AsRegister<Register>(); |
| 3395 | |
| 3396 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3397 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3398 | // Shift the high part |
| 3399 | __ Lsl(o_h, high, o_l); |
| 3400 | // Shift the low part and `or` what overflew on the high part |
| 3401 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3402 | __ Lsr(temp, low, temp); |
| 3403 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3404 | // If the shift is > 32 bits, override the high part |
| 3405 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3406 | __ it(PL); |
| 3407 | __ Lsl(o_h, low, temp, PL); |
| 3408 | // Shift the low part |
| 3409 | __ Lsl(o_l, low, o_l); |
| 3410 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3411 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3412 | // Shift the low part |
| 3413 | __ Lsr(o_l, low, o_h); |
| 3414 | // Shift the high part and `or` what underflew on the low part |
| 3415 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3416 | __ Lsl(temp, high, temp); |
| 3417 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3418 | // If the shift is > 32 bits, override the low part |
| 3419 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3420 | __ it(PL); |
| 3421 | __ Asr(o_l, high, temp, PL); |
| 3422 | // Shift the high part |
| 3423 | __ Asr(o_h, high, o_h); |
| 3424 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3425 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3426 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3427 | __ Lsr(o_l, low, o_h); |
| 3428 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3429 | __ Lsl(temp, high, temp); |
| 3430 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3431 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3432 | __ it(PL); |
| 3433 | __ Lsr(o_l, high, temp, PL); |
| 3434 | __ Lsr(o_h, high, o_h); |
| 3435 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3436 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3437 | // Register allocator doesn't create partial overlap. |
| 3438 | DCHECK_NE(o_l, high); |
| 3439 | DCHECK_NE(o_h, low); |
| 3440 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3441 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3442 | if (shift_value > 32) { |
| 3443 | if (op->IsShl()) { |
| 3444 | __ Lsl(o_h, low, shift_value - 32); |
| 3445 | __ LoadImmediate(o_l, 0); |
| 3446 | } else if (op->IsShr()) { |
| 3447 | __ Asr(o_l, high, shift_value - 32); |
| 3448 | __ Asr(o_h, high, 31); |
| 3449 | } else { |
| 3450 | __ Lsr(o_l, high, shift_value - 32); |
| 3451 | __ LoadImmediate(o_h, 0); |
| 3452 | } |
| 3453 | } else if (shift_value == 32) { |
| 3454 | if (op->IsShl()) { |
| 3455 | __ mov(o_h, ShifterOperand(low)); |
| 3456 | __ LoadImmediate(o_l, 0); |
| 3457 | } else if (op->IsShr()) { |
| 3458 | __ mov(o_l, ShifterOperand(high)); |
| 3459 | __ Asr(o_h, high, 31); |
| 3460 | } else { |
| 3461 | __ mov(o_l, ShifterOperand(high)); |
| 3462 | __ LoadImmediate(o_h, 0); |
| 3463 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3464 | } else if (shift_value == 1) { |
| 3465 | if (op->IsShl()) { |
| 3466 | __ Lsls(o_l, low, 1); |
| 3467 | __ adc(o_h, high, ShifterOperand(high)); |
| 3468 | } else if (op->IsShr()) { |
| 3469 | __ Asrs(o_h, high, 1); |
| 3470 | __ Rrx(o_l, low); |
| 3471 | } else { |
| 3472 | __ Lsrs(o_h, high, 1); |
| 3473 | __ Rrx(o_l, low); |
| 3474 | } |
| 3475 | } else { |
| 3476 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3477 | if (op->IsShl()) { |
| 3478 | __ Lsl(o_h, high, shift_value); |
| 3479 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3480 | __ Lsl(o_l, low, shift_value); |
| 3481 | } else if (op->IsShr()) { |
| 3482 | __ Lsr(o_l, low, shift_value); |
| 3483 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3484 | __ Asr(o_h, high, shift_value); |
| 3485 | } else { |
| 3486 | __ Lsr(o_l, low, shift_value); |
| 3487 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3488 | __ Lsr(o_h, high, shift_value); |
| 3489 | } |
| 3490 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3491 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3492 | break; |
| 3493 | } |
| 3494 | default: |
| 3495 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3496 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3501 | HandleShift(shl); |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3505 | HandleShift(shl); |
| 3506 | } |
| 3507 | |
| 3508 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3509 | HandleShift(shr); |
| 3510 | } |
| 3511 | |
| 3512 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3513 | HandleShift(shr); |
| 3514 | } |
| 3515 | |
| 3516 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3517 | HandleShift(ushr); |
| 3518 | } |
| 3519 | |
| 3520 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3521 | HandleShift(ushr); |
| 3522 | } |
| 3523 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3524 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3525 | LocationSummary* locations = |
| 3526 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3527 | if (instruction->IsStringAlloc()) { |
| 3528 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3529 | } else { |
| 3530 | InvokeRuntimeCallingConvention calling_convention; |
| 3531 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3532 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3533 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3534 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3538 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3539 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3540 | if (instruction->IsStringAlloc()) { |
| 3541 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3542 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3543 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize); |
| 3544 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3545 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3546 | __ blx(LR); |
| 3547 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3548 | } else { |
| 3549 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3550 | instruction, |
| 3551 | instruction->GetDexPc(), |
| 3552 | nullptr); |
| 3553 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3554 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3555 | } |
| 3556 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3557 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3558 | LocationSummary* locations = |
| 3559 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3560 | InvokeRuntimeCallingConvention calling_convention; |
| 3561 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3562 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3563 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3564 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3568 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3569 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3570 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3571 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3572 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3573 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3574 | instruction->GetDexPc(), |
| 3575 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3576 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3577 | } |
| 3578 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3579 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3580 | LocationSummary* locations = |
| 3581 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3582 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3583 | if (location.IsStackSlot()) { |
| 3584 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3585 | } else if (location.IsDoubleStackSlot()) { |
| 3586 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3587 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3588 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3589 | } |
| 3590 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3591 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3592 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3593 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3597 | LocationSummary* locations = |
| 3598 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3599 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3600 | } |
| 3601 | |
| 3602 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3603 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3604 | } |
| 3605 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3606 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3607 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3608 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3611 | } |
| 3612 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3613 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3614 | LocationSummary* locations = not_->GetLocations(); |
| 3615 | Location out = locations->Out(); |
| 3616 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3617 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3618 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3619 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3620 | break; |
| 3621 | |
| 3622 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3623 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3624 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3625 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3626 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3627 | break; |
| 3628 | |
| 3629 | default: |
| 3630 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3631 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3632 | } |
| 3633 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3634 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3635 | LocationSummary* locations = |
| 3636 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3637 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3638 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3639 | } |
| 3640 | |
| 3641 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3642 | LocationSummary* locations = bool_not->GetLocations(); |
| 3643 | Location out = locations->Out(); |
| 3644 | Location in = locations->InAt(0); |
| 3645 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3646 | } |
| 3647 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3648 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3649 | LocationSummary* locations = |
| 3650 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3651 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3652 | case Primitive::kPrimBoolean: |
| 3653 | case Primitive::kPrimByte: |
| 3654 | case Primitive::kPrimShort: |
| 3655 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3656 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3657 | case Primitive::kPrimLong: { |
| 3658 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3659 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3660 | // Output overlaps because it is written before doing the low comparison. |
| 3661 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | } |
| 3664 | case Primitive::kPrimFloat: |
| 3665 | case Primitive::kPrimDouble: { |
| 3666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3667 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3668 | locations->SetOut(Location::RequiresRegister()); |
| 3669 | break; |
| 3670 | } |
| 3671 | default: |
| 3672 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3673 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3677 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3678 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3679 | Location left = locations->InAt(0); |
| 3680 | Location right = locations->InAt(1); |
| 3681 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3682 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3683 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3684 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3685 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3686 | case Primitive::kPrimBoolean: |
| 3687 | case Primitive::kPrimByte: |
| 3688 | case Primitive::kPrimShort: |
| 3689 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3690 | case Primitive::kPrimInt: { |
| 3691 | __ LoadImmediate(out, 0); |
| 3692 | __ cmp(left.AsRegister<Register>(), |
| 3693 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 3694 | less_cond = LT; |
| 3695 | break; |
| 3696 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3697 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3698 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3699 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3700 | __ b(&less, LT); |
| 3701 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3702 | // 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] | 3703 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3704 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3705 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3706 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3707 | break; |
| 3708 | } |
| 3709 | case Primitive::kPrimFloat: |
| 3710 | case Primitive::kPrimDouble: { |
| 3711 | __ LoadImmediate(out, 0); |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3712 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3713 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3714 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3715 | break; |
| 3716 | } |
| 3717 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3718 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3719 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3720 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3721 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3722 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3723 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3724 | |
| 3725 | __ Bind(&greater); |
| 3726 | __ LoadImmediate(out, 1); |
| 3727 | __ b(&done); |
| 3728 | |
| 3729 | __ Bind(&less); |
| 3730 | __ LoadImmediate(out, -1); |
| 3731 | |
| 3732 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3733 | } |
| 3734 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3735 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3736 | LocationSummary* locations = |
| 3737 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 3925c6e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3738 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3739 | locations->SetInAt(i, Location::Any()); |
| 3740 | } |
| 3741 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3742 | } |
| 3743 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3744 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3745 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3746 | } |
| 3747 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3748 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3749 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 3750 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3751 | switch (kind) { |
| 3752 | case MemBarrierKind::kAnyStore: |
| 3753 | case MemBarrierKind::kLoadAny: |
| 3754 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3755 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3756 | break; |
| 3757 | } |
| 3758 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3759 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | } |
| 3762 | default: |
| 3763 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3764 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3765 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3769 | uint32_t offset, |
| 3770 | Register out_lo, |
| 3771 | Register out_hi) { |
| 3772 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3773 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3774 | // `offset` into `out_lo` does not clutter `addr`. |
| 3775 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3776 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3777 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3778 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3779 | } |
| 3780 | __ ldrexd(out_lo, out_hi, addr); |
| 3781 | } |
| 3782 | |
| 3783 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3784 | uint32_t offset, |
| 3785 | Register value_lo, |
| 3786 | Register value_hi, |
| 3787 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3788 | Register temp2, |
| 3789 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3790 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3791 | if (offset != 0) { |
| 3792 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3793 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3794 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3795 | } |
| 3796 | __ Bind(&fail); |
| 3797 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3798 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3799 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3800 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3801 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3802 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3806 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3807 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3808 | LocationSummary* locations = |
| 3809 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3810 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3811 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3812 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3813 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3814 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3815 | } else { |
| 3816 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3817 | } |
| 3818 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3819 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3820 | bool generate_volatile = field_info.IsVolatile() |
| 3821 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3822 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3823 | bool needs_write_barrier = |
| 3824 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3825 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3826 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3827 | if (needs_write_barrier) { |
| 3828 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3829 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3830 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3831 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3832 | // - registers need to be consecutive |
| 3833 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3834 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3835 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3836 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3837 | |
| 3838 | locations->AddTemp(Location::RequiresRegister()); |
| 3839 | locations->AddTemp(Location::RequiresRegister()); |
| 3840 | if (field_type == Primitive::kPrimDouble) { |
| 3841 | // For doubles we need two more registers to copy the value. |
| 3842 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3843 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3844 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3845 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3846 | } |
| 3847 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3848 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3849 | const FieldInfo& field_info, |
| 3850 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3851 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3852 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3853 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3854 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3855 | Location value = locations->InAt(1); |
| 3856 | |
| 3857 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3858 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3859 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3860 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3861 | bool needs_write_barrier = |
| 3862 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3863 | |
| 3864 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3865 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3866 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3867 | |
| 3868 | switch (field_type) { |
| 3869 | case Primitive::kPrimBoolean: |
| 3870 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3871 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3872 | break; |
| 3873 | } |
| 3874 | |
| 3875 | case Primitive::kPrimShort: |
| 3876 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3877 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3878 | break; |
| 3879 | } |
| 3880 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3881 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3882 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3883 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3884 | // Note that in the case where `value` is a null reference, |
| 3885 | // we do not enter this block, as a null reference does not |
| 3886 | // need poisoning. |
| 3887 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3888 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3889 | __ Mov(temp, value.AsRegister<Register>()); |
| 3890 | __ PoisonHeapReference(temp); |
| 3891 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3892 | } else { |
| 3893 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3894 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3895 | break; |
| 3896 | } |
| 3897 | |
| 3898 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3899 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3900 | GenerateWideAtomicStore(base, offset, |
| 3901 | value.AsRegisterPairLow<Register>(), |
| 3902 | value.AsRegisterPairHigh<Register>(), |
| 3903 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3904 | locations->GetTemp(1).AsRegister<Register>(), |
| 3905 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3906 | } else { |
| 3907 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3908 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3909 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3910 | break; |
| 3911 | } |
| 3912 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3913 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3914 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3915 | break; |
| 3916 | } |
| 3917 | |
| 3918 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3919 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3920 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3921 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3922 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3923 | |
| 3924 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3925 | |
| 3926 | GenerateWideAtomicStore(base, offset, |
| 3927 | value_reg_lo, |
| 3928 | value_reg_hi, |
| 3929 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3930 | locations->GetTemp(3).AsRegister<Register>(), |
| 3931 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3932 | } else { |
| 3933 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3934 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3935 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3936 | break; |
| 3937 | } |
| 3938 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3939 | case Primitive::kPrimVoid: |
| 3940 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3941 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3942 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3943 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3944 | // Longs and doubles are handled in the switch. |
| 3945 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3946 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3947 | } |
| 3948 | |
| 3949 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3950 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3951 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3952 | codegen_->MarkGCCard( |
| 3953 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3954 | } |
| 3955 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3956 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3957 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3958 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3959 | } |
| 3960 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3961 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3962 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3963 | |
| 3964 | bool object_field_get_with_read_barrier = |
| 3965 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3966 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3967 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 3968 | object_field_get_with_read_barrier ? |
| 3969 | LocationSummary::kCallOnSlowPath : |
| 3970 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3971 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3972 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3973 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3974 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3975 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3976 | // The output overlaps in case of volatile long: we don't want the |
| 3977 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 3978 | // object's location. Likewise, in the case of an object field get |
| 3979 | // with read barriers enabled, we do not want the load to overwrite |
| 3980 | // the object's location, as we need it to emit the read barrier. |
| 3981 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 3982 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3983 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3984 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3985 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3986 | } else { |
| 3987 | locations->SetOut(Location::RequiresRegister(), |
| 3988 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3989 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3990 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3991 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3992 | // - registers need to be consecutive |
| 3993 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3994 | // We don't test for ARM yet, and the assertion makes sure that we |
| 3995 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3996 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3997 | locations->AddTemp(Location::RequiresRegister()); |
| 3998 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3999 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4000 | // We need a temporary register for the read barrier marking slow |
| 4001 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4002 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4003 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4004 | } |
| 4005 | |
Vladimir Marko | 2887aa2 | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4006 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4007 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4008 | << input->GetType(); |
| 4009 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4010 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4011 | return Location::ConstantLocation(input->AsConstant()); |
| 4012 | } else { |
| 4013 | return Location::RequiresFpuRegister(); |
| 4014 | } |
| 4015 | } |
| 4016 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4017 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4018 | Opcode opcode) { |
| 4019 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4020 | if (constant->IsConstant() && |
| 4021 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4022 | return Location::ConstantLocation(constant->AsConstant()); |
| 4023 | } |
| 4024 | return Location::RequiresRegister(); |
| 4025 | } |
| 4026 | |
| 4027 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4028 | Opcode opcode) { |
| 4029 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4030 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4031 | Opcode high_opcode = opcode; |
| 4032 | SetCc low_set_cc = kCcDontCare; |
| 4033 | switch (opcode) { |
| 4034 | case SUB: |
| 4035 | // Flip the operation to an ADD. |
| 4036 | value = -value; |
| 4037 | opcode = ADD; |
| 4038 | FALLTHROUGH_INTENDED; |
| 4039 | case ADD: |
| 4040 | if (Low32Bits(value) == 0u) { |
| 4041 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4042 | } |
| 4043 | high_opcode = ADC; |
| 4044 | low_set_cc = kCcSet; |
| 4045 | break; |
| 4046 | default: |
| 4047 | break; |
| 4048 | } |
| 4049 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4050 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4051 | } else { |
| 4052 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4053 | } |
| 4054 | } |
| 4055 | |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4056 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4057 | Opcode opcode, |
| 4058 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4059 | ShifterOperand so; |
| 4060 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4061 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4062 | return true; |
| 4063 | } |
| 4064 | Opcode neg_opcode = kNoOperand; |
| 4065 | switch (opcode) { |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4066 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4067 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4068 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4069 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4070 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4071 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4072 | default: |
| 4073 | return false; |
| 4074 | } |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4075 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4076 | } |
| 4077 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4078 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4079 | const FieldInfo& field_info) { |
| 4080 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4081 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4082 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4083 | Location base_loc = locations->InAt(0); |
| 4084 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4085 | Location out = locations->Out(); |
| 4086 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4087 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4088 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4089 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4090 | |
| 4091 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4092 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4093 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4094 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4095 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4096 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4097 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4098 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4099 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4100 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4101 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4102 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4103 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4104 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4105 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4106 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4107 | |
| 4108 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4109 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4110 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4111 | |
| 4112 | case Primitive::kPrimNot: { |
| 4113 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4114 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4115 | Location temp_loc = locations->GetTemp(0); |
| 4116 | // Note that a potential implicit null check is handled in this |
| 4117 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4118 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4119 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4120 | if (is_volatile) { |
| 4121 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4122 | } |
| 4123 | } else { |
| 4124 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4126 | if (is_volatile) { |
| 4127 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4128 | } |
| 4129 | // If read barriers are enabled, emit read barriers other than |
| 4130 | // Baker's using a slow path (and also unpoison the loaded |
| 4131 | // reference, if heap poisoning is enabled). |
| 4132 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4133 | } |
| 4134 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4135 | } |
| 4136 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4137 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4138 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4139 | GenerateWideAtomicLoad(base, offset, |
| 4140 | out.AsRegisterPairLow<Register>(), |
| 4141 | out.AsRegisterPairHigh<Register>()); |
| 4142 | } else { |
| 4143 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4144 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4145 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4146 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4147 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4148 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4149 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4150 | |
| 4151 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4152 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4153 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4154 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4155 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4156 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4157 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4158 | __ vmovdrr(out_reg, lo, hi); |
| 4159 | } else { |
| 4160 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4161 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4162 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4163 | break; |
| 4164 | } |
| 4165 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4166 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4167 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4168 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4169 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4170 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4171 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4172 | // Potential implicit null checks, in the case of reference or |
| 4173 | // double fields, are handled in the previous switch statement. |
| 4174 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4175 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4176 | } |
| 4177 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4178 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4179 | if (field_type == Primitive::kPrimNot) { |
| 4180 | // Memory barriers, in the case of references, are also handled |
| 4181 | // in the previous switch statement. |
| 4182 | } else { |
| 4183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4184 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4185 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4189 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4190 | } |
| 4191 | |
| 4192 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4193 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4197 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4198 | } |
| 4199 | |
| 4200 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4201 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4202 | } |
| 4203 | |
| 4204 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4205 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4206 | } |
| 4207 | |
| 4208 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4209 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4210 | } |
| 4211 | |
| 4212 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4213 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4214 | } |
| 4215 | |
| 4216 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4217 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4218 | } |
| 4219 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4220 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4221 | HUnresolvedInstanceFieldGet* instruction) { |
| 4222 | FieldAccessCallingConventionARM calling_convention; |
| 4223 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4224 | instruction, instruction->GetFieldType(), calling_convention); |
| 4225 | } |
| 4226 | |
| 4227 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4228 | HUnresolvedInstanceFieldGet* instruction) { |
| 4229 | FieldAccessCallingConventionARM calling_convention; |
| 4230 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4231 | instruction->GetFieldType(), |
| 4232 | instruction->GetFieldIndex(), |
| 4233 | instruction->GetDexPc(), |
| 4234 | calling_convention); |
| 4235 | } |
| 4236 | |
| 4237 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4238 | HUnresolvedInstanceFieldSet* instruction) { |
| 4239 | FieldAccessCallingConventionARM calling_convention; |
| 4240 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4241 | instruction, instruction->GetFieldType(), calling_convention); |
| 4242 | } |
| 4243 | |
| 4244 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4245 | HUnresolvedInstanceFieldSet* instruction) { |
| 4246 | FieldAccessCallingConventionARM calling_convention; |
| 4247 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4248 | instruction->GetFieldType(), |
| 4249 | instruction->GetFieldIndex(), |
| 4250 | instruction->GetDexPc(), |
| 4251 | calling_convention); |
| 4252 | } |
| 4253 | |
| 4254 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4255 | HUnresolvedStaticFieldGet* instruction) { |
| 4256 | FieldAccessCallingConventionARM calling_convention; |
| 4257 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4258 | instruction, instruction->GetFieldType(), calling_convention); |
| 4259 | } |
| 4260 | |
| 4261 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4262 | HUnresolvedStaticFieldGet* instruction) { |
| 4263 | FieldAccessCallingConventionARM calling_convention; |
| 4264 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4265 | instruction->GetFieldType(), |
| 4266 | instruction->GetFieldIndex(), |
| 4267 | instruction->GetDexPc(), |
| 4268 | calling_convention); |
| 4269 | } |
| 4270 | |
| 4271 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4272 | HUnresolvedStaticFieldSet* instruction) { |
| 4273 | FieldAccessCallingConventionARM calling_convention; |
| 4274 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4275 | instruction, instruction->GetFieldType(), calling_convention); |
| 4276 | } |
| 4277 | |
| 4278 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4279 | HUnresolvedStaticFieldSet* instruction) { |
| 4280 | FieldAccessCallingConventionARM calling_convention; |
| 4281 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4282 | instruction->GetFieldType(), |
| 4283 | instruction->GetFieldIndex(), |
| 4284 | instruction->GetDexPc(), |
| 4285 | calling_convention); |
| 4286 | } |
| 4287 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4288 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4289 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4290 | ? LocationSummary::kCallOnSlowPath |
| 4291 | : LocationSummary::kNoCall; |
| 4292 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4293 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4294 | if (instruction->HasUses()) { |
| 4295 | locations->SetOut(Location::SameAsFirstInput()); |
| 4296 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4297 | } |
| 4298 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4299 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4300 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4301 | return; |
| 4302 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4303 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4304 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4305 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4306 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4307 | } |
| 4308 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4309 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4310 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4311 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4312 | |
| 4313 | LocationSummary* locations = instruction->GetLocations(); |
| 4314 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4315 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4316 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4317 | } |
| 4318 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4319 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4320 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4321 | } |
| 4322 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4323 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4324 | bool object_array_get_with_read_barrier = |
| 4325 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4326 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4327 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4328 | object_array_get_with_read_barrier ? |
| 4329 | LocationSummary::kCallOnSlowPath : |
| 4330 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4332 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4333 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4334 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4335 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4336 | // The output overlaps in the case of an object array get with |
| 4337 | // read barriers enabled: we do not want the move to overwrite the |
| 4338 | // array's location, as we need it to emit the read barrier. |
| 4339 | locations->SetOut( |
| 4340 | Location::RequiresRegister(), |
| 4341 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4342 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4343 | // We need a temporary register for the read barrier marking slow |
| 4344 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4345 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4346 | locations->AddTemp(Location::RequiresRegister()); |
| 4347 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4351 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4352 | Location obj_loc = locations->InAt(0); |
| 4353 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4354 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4355 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4356 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4357 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4358 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4359 | case Primitive::kPrimBoolean: { |
| 4360 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4361 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4362 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4363 | size_t offset = |
| 4364 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4365 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 4366 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4367 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4368 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 4369 | } |
| 4370 | break; |
| 4371 | } |
| 4372 | |
| 4373 | case Primitive::kPrimByte: { |
| 4374 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4375 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4376 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4377 | size_t offset = |
| 4378 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4379 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 4380 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4381 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4382 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 4383 | } |
| 4384 | break; |
| 4385 | } |
| 4386 | |
| 4387 | case Primitive::kPrimShort: { |
| 4388 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4389 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4390 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4391 | size_t offset = |
| 4392 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4393 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 4394 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4395 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4396 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 4397 | } |
| 4398 | break; |
| 4399 | } |
| 4400 | |
| 4401 | case Primitive::kPrimChar: { |
| 4402 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4403 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4404 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4405 | size_t offset = |
| 4406 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4407 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 4408 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4409 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4410 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 4411 | } |
| 4412 | break; |
| 4413 | } |
| 4414 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4415 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4416 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4417 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4418 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4419 | size_t offset = |
| 4420 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4421 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4422 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4423 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4424 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4425 | } |
| 4426 | break; |
| 4427 | } |
| 4428 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4429 | case Primitive::kPrimNot: { |
| 4430 | static_assert( |
| 4431 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4432 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4433 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4434 | // /* HeapReference<Object> */ out = |
| 4435 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4436 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4437 | Location temp = locations->GetTemp(0); |
| 4438 | // Note that a potential implicit null check is handled in this |
| 4439 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4440 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4441 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4442 | } else { |
| 4443 | Register out = out_loc.AsRegister<Register>(); |
| 4444 | if (index.IsConstant()) { |
| 4445 | size_t offset = |
| 4446 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4447 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4448 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4449 | // If read barriers are enabled, emit read barriers other than |
| 4450 | // Baker's using a slow path (and also unpoison the loaded |
| 4451 | // reference, if heap poisoning is enabled). |
| 4452 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4453 | } else { |
| 4454 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4455 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4456 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4457 | // If read barriers are enabled, emit read barriers other than |
| 4458 | // Baker's using a slow path (and also unpoison the loaded |
| 4459 | // reference, if heap poisoning is enabled). |
| 4460 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4461 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4462 | } |
| 4463 | } |
| 4464 | break; |
| 4465 | } |
| 4466 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4467 | case Primitive::kPrimLong: { |
| 4468 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4469 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4470 | size_t offset = |
| 4471 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4472 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4473 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4474 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4475 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4476 | } |
| 4477 | break; |
| 4478 | } |
| 4479 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4480 | case Primitive::kPrimFloat: { |
| 4481 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4482 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4483 | if (index.IsConstant()) { |
| 4484 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4485 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4486 | } else { |
| 4487 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4488 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4489 | } |
| 4490 | break; |
| 4491 | } |
| 4492 | |
| 4493 | case Primitive::kPrimDouble: { |
| 4494 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4495 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4496 | if (index.IsConstant()) { |
| 4497 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4498 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4499 | } else { |
| 4500 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4501 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4502 | } |
| 4503 | break; |
| 4504 | } |
| 4505 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4506 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4507 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4508 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4509 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4510 | |
| 4511 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4512 | // Potential implicit null checks, in the case of reference |
| 4513 | // arrays, are handled in the previous switch statement. |
| 4514 | } else { |
| 4515 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4516 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4520 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4521 | |
| 4522 | bool needs_write_barrier = |
| 4523 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4524 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4525 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4526 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4527 | instruction, |
Vladimir Marko | efafb12 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4528 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4529 | LocationSummary::kCallOnSlowPath : |
| 4530 | LocationSummary::kNoCall); |
| 4531 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4532 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4533 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4534 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4535 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4537 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4538 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4539 | if (needs_write_barrier) { |
| 4540 | // Temporary registers for the write barrier. |
| 4541 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4542 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4543 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4547 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4548 | Location array_loc = locations->InAt(0); |
| 4549 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4550 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4551 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4552 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4553 | bool needs_write_barrier = |
| 4554 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4555 | |
| 4556 | switch (value_type) { |
| 4557 | case Primitive::kPrimBoolean: |
| 4558 | case Primitive::kPrimByte: { |
| 4559 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4560 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4561 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4562 | size_t offset = |
| 4563 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4564 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4565 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4566 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4567 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 4568 | } |
| 4569 | break; |
| 4570 | } |
| 4571 | |
| 4572 | case Primitive::kPrimShort: |
| 4573 | case Primitive::kPrimChar: { |
| 4574 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4575 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4576 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4577 | size_t offset = |
| 4578 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4579 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4580 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4581 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4582 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 4583 | } |
| 4584 | break; |
| 4585 | } |
| 4586 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4587 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4588 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4589 | Location value_loc = locations->InAt(2); |
| 4590 | Register value = value_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4591 | Register source = value; |
| 4592 | |
| 4593 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4594 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4595 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4596 | size_t offset = |
| 4597 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4598 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4599 | } else { |
| 4600 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4601 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4602 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4603 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 4604 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4605 | DCHECK(!needs_write_barrier); |
| 4606 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4607 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4608 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4609 | |
| 4610 | DCHECK(needs_write_barrier); |
| 4611 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4612 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4613 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4614 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4615 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4616 | Label done; |
| 4617 | SlowPathCode* slow_path = nullptr; |
| 4618 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4619 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4620 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4621 | codegen_->AddSlowPath(slow_path); |
| 4622 | if (instruction->GetValueCanBeNull()) { |
| 4623 | Label non_zero; |
| 4624 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4625 | if (index.IsConstant()) { |
| 4626 | size_t offset = |
| 4627 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4628 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4629 | } else { |
| 4630 | DCHECK(index.IsRegister()) << index; |
| 4631 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4632 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4633 | } |
| 4634 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4635 | __ b(&done); |
| 4636 | __ Bind(&non_zero); |
| 4637 | } |
| 4638 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4639 | if (kEmitCompilerReadBarrier) { |
| 4640 | // When read barriers are enabled, the type checking |
| 4641 | // instrumentation requires two read barriers: |
| 4642 | // |
| 4643 | // __ Mov(temp2, temp1); |
| 4644 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4645 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4646 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4647 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4648 | // |
| 4649 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4650 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4651 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4652 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4653 | // |
| 4654 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4655 | // |
| 4656 | // However, the second read barrier may trash `temp`, as it |
| 4657 | // is a temporary register, and as such would not be saved |
| 4658 | // along with live registers before calling the runtime (nor |
| 4659 | // restored afterwards). So in this case, we bail out and |
| 4660 | // delegate the work to the array set slow path. |
| 4661 | // |
| 4662 | // TODO: Extend the register allocator to support a new |
| 4663 | // "(locally) live temp" location so as to avoid always |
| 4664 | // going into the slow path when read barriers are enabled. |
| 4665 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4666 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4667 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4668 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4669 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4670 | __ MaybeUnpoisonHeapReference(temp1); |
| 4671 | |
| 4672 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4673 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4674 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4675 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4676 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4677 | // nor `temp2`, as we are comparing two poisoned references. |
| 4678 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4679 | |
| 4680 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4681 | Label do_put; |
| 4682 | __ b(&do_put, EQ); |
| 4683 | // If heap poisoning is enabled, the `temp1` reference has |
| 4684 | // not been unpoisoned yet; unpoison it now. |
| 4685 | __ MaybeUnpoisonHeapReference(temp1); |
| 4686 | |
| 4687 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4688 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4689 | // If heap poisoning is enabled, no need to unpoison |
| 4690 | // `temp1`, as we are comparing against null below. |
| 4691 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4692 | __ Bind(&do_put); |
| 4693 | } else { |
| 4694 | __ b(slow_path->GetEntryLabel(), NE); |
| 4695 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | if (kPoisonHeapReferences) { |
| 4700 | // Note that in the case where `value` is a null reference, |
| 4701 | // we do not enter this block, as a null reference does not |
| 4702 | // need poisoning. |
| 4703 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4704 | __ Mov(temp1, value); |
| 4705 | __ PoisonHeapReference(temp1); |
| 4706 | source = temp1; |
| 4707 | } |
| 4708 | |
| 4709 | if (index.IsConstant()) { |
| 4710 | size_t offset = |
| 4711 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4712 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4713 | } else { |
| 4714 | DCHECK(index.IsRegister()) << index; |
| 4715 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4716 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4717 | } |
| 4718 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4719 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4720 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4721 | } |
| 4722 | |
| 4723 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4724 | |
| 4725 | if (done.IsLinked()) { |
| 4726 | __ Bind(&done); |
| 4727 | } |
| 4728 | |
| 4729 | if (slow_path != nullptr) { |
| 4730 | __ Bind(slow_path->GetExitLabel()); |
| 4731 | } |
| 4732 | |
| 4733 | break; |
| 4734 | } |
| 4735 | |
| 4736 | case Primitive::kPrimInt: { |
| 4737 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4738 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4739 | if (index.IsConstant()) { |
| 4740 | size_t offset = |
| 4741 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4742 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4743 | } else { |
| 4744 | DCHECK(index.IsRegister()) << index; |
| 4745 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4746 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4747 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4748 | break; |
| 4749 | } |
| 4750 | |
| 4751 | case Primitive::kPrimLong: { |
| 4752 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4753 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4754 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4755 | size_t offset = |
| 4756 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4757 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4758 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4760 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4761 | } |
| 4762 | break; |
| 4763 | } |
| 4764 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4765 | case Primitive::kPrimFloat: { |
| 4766 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4767 | Location value = locations->InAt(2); |
| 4768 | DCHECK(value.IsFpuRegister()); |
| 4769 | if (index.IsConstant()) { |
| 4770 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4771 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4772 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4773 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4774 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4775 | } |
| 4776 | break; |
| 4777 | } |
| 4778 | |
| 4779 | case Primitive::kPrimDouble: { |
| 4780 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4781 | Location value = locations->InAt(2); |
| 4782 | DCHECK(value.IsFpuRegisterPair()); |
| 4783 | if (index.IsConstant()) { |
| 4784 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4785 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4786 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4787 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4788 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4789 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4790 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4791 | break; |
| 4792 | } |
| 4793 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4794 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4795 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4796 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4797 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4798 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 4799 | // Objects are handled in the switch. |
| 4800 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4801 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4802 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4806 | LocationSummary* locations = |
| 4807 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4808 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4809 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4813 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 51c103e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4814 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4815 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4816 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4817 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4818 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4822 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4823 | ? LocationSummary::kCallOnSlowPath |
| 4824 | : LocationSummary::kNoCall; |
| 4825 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4827 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4828 | if (instruction->HasUses()) { |
| 4829 | locations->SetOut(Location::SameAsFirstInput()); |
| 4830 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4834 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4835 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4836 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4837 | codegen_->AddSlowPath(slow_path); |
| 4838 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4839 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4840 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4841 | |
| 4842 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4843 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4846 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4847 | Register card, |
| 4848 | Register object, |
| 4849 | Register value, |
| 4850 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4851 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4852 | if (can_be_null) { |
| 4853 | __ CompareAndBranchIfZero(value, &is_null); |
| 4854 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4855 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4856 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4857 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4858 | if (can_be_null) { |
| 4859 | __ Bind(&is_null); |
| 4860 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4861 | } |
| 4862 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4863 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4864 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4868 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4869 | } |
| 4870 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4871 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4872 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4873 | } |
| 4874 | |
| 4875 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4876 | HBasicBlock* block = instruction->GetBlock(); |
| 4877 | if (block->GetLoopInformation() != nullptr) { |
| 4878 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4879 | // The back edge will generate the suspend check. |
| 4880 | return; |
| 4881 | } |
| 4882 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4883 | // The goto will generate the suspend check. |
| 4884 | return; |
| 4885 | } |
| 4886 | GenerateSuspendCheck(instruction, nullptr); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4890 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4891 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4892 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4893 | if (slow_path == nullptr) { |
| 4894 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4895 | instruction->SetSlowPath(slow_path); |
| 4896 | codegen_->AddSlowPath(slow_path); |
| 4897 | if (successor != nullptr) { |
| 4898 | DCHECK(successor->IsLoopHeader()); |
| 4899 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4900 | } |
| 4901 | } else { |
| 4902 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4903 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4904 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4905 | __ LoadFromOffset( |
| 4906 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4907 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4908 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4909 | __ Bind(slow_path->GetReturnLabel()); |
| 4910 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4911 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4912 | __ b(slow_path->GetEntryLabel()); |
| 4913 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4916 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4917 | return codegen_->GetAssembler(); |
| 4918 | } |
| 4919 | |
| 4920 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4921 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4922 | Location source = move->GetSource(); |
| 4923 | Location destination = move->GetDestination(); |
| 4924 | |
| 4925 | if (source.IsRegister()) { |
| 4926 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4927 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4928 | } else if (destination.IsFpuRegister()) { |
| 4929 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4930 | } else { |
| 4931 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4932 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4933 | SP, destination.GetStackIndex()); |
| 4934 | } |
| 4935 | } else if (source.IsStackSlot()) { |
| 4936 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4937 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4938 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4939 | } else if (destination.IsFpuRegister()) { |
| 4940 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4941 | } else { |
| 4942 | DCHECK(destination.IsStackSlot()); |
| 4943 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4944 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4945 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4946 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4947 | if (destination.IsRegister()) { |
| 4948 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 4949 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4950 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4951 | } else { |
| 4952 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4953 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4954 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4955 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4956 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4957 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4958 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4959 | } else if (destination.IsRegisterPair()) { |
| 4960 | DCHECK(ExpectedPairLayout(destination)); |
| 4961 | __ LoadFromOffset( |
| 4962 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4963 | } else { |
| 4964 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4965 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4966 | SP, |
| 4967 | source.GetStackIndex()); |
| 4968 | } |
| 4969 | } else if (source.IsRegisterPair()) { |
| 4970 | if (destination.IsRegisterPair()) { |
| 4971 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 4972 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4973 | } else if (destination.IsFpuRegisterPair()) { |
| 4974 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4975 | source.AsRegisterPairLow<Register>(), |
| 4976 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4977 | } else { |
| 4978 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4979 | DCHECK(ExpectedPairLayout(source)); |
| 4980 | __ StoreToOffset( |
| 4981 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 4982 | } |
| 4983 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 4984 | if (destination.IsRegisterPair()) { |
| 4985 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 4986 | destination.AsRegisterPairHigh<Register>(), |
| 4987 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4988 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4989 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4990 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4991 | } else { |
| 4992 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4993 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 4994 | SP, |
| 4995 | destination.GetStackIndex()); |
| 4996 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4997 | } else { |
| 4998 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4999 | HConstant* constant = source.GetConstant(); |
| 5000 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5001 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5002 | if (destination.IsRegister()) { |
| 5003 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5004 | } else { |
| 5005 | DCHECK(destination.IsStackSlot()); |
| 5006 | __ LoadImmediate(IP, value); |
| 5007 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5008 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5009 | } else if (constant->IsLongConstant()) { |
| 5010 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5011 | if (destination.IsRegisterPair()) { |
| 5012 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5013 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5014 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5015 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5016 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5017 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5018 | __ LoadImmediate(IP, High32Bits(value)); |
| 5019 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5020 | } |
| 5021 | } else if (constant->IsDoubleConstant()) { |
| 5022 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5023 | if (destination.IsFpuRegisterPair()) { |
| 5024 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5025 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5026 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5027 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5028 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5029 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5030 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5031 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5032 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5033 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5034 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5035 | float value = constant->AsFloatConstant()->GetValue(); |
| 5036 | if (destination.IsFpuRegister()) { |
| 5037 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5038 | } else { |
| 5039 | DCHECK(destination.IsStackSlot()); |
| 5040 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5041 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5042 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5043 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5048 | __ Mov(IP, reg); |
| 5049 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5050 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5051 | } |
| 5052 | |
| 5053 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5054 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5055 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5056 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5057 | SP, mem1 + stack_offset); |
| 5058 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5059 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5060 | SP, mem2 + stack_offset); |
| 5061 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5062 | } |
| 5063 | |
| 5064 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5065 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5066 | Location source = move->GetSource(); |
| 5067 | Location destination = move->GetDestination(); |
| 5068 | |
| 5069 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5070 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5071 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5072 | __ Mov(IP, source.AsRegister<Register>()); |
| 5073 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5074 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5075 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5076 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5077 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5078 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5079 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5080 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5081 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5082 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5083 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5084 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5085 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5086 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5087 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5088 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5089 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5090 | destination.AsRegisterPairHigh<Register>(), |
| 5091 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5092 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5093 | Register low_reg = source.IsRegisterPair() |
| 5094 | ? source.AsRegisterPairLow<Register>() |
| 5095 | : destination.AsRegisterPairLow<Register>(); |
| 5096 | int mem = source.IsRegisterPair() |
| 5097 | ? destination.GetStackIndex() |
| 5098 | : source.GetStackIndex(); |
| 5099 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5100 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5101 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5102 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5103 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5104 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5105 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5106 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5107 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5108 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5109 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5110 | DRegister reg = source.IsFpuRegisterPair() |
| 5111 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5112 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5113 | int mem = source.IsFpuRegisterPair() |
| 5114 | ? destination.GetStackIndex() |
| 5115 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5116 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5117 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5118 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5119 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5120 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5121 | : destination.AsFpuRegister<SRegister>(); |
| 5122 | int mem = source.IsFpuRegister() |
| 5123 | ? destination.GetStackIndex() |
| 5124 | : source.GetStackIndex(); |
| 5125 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5126 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5127 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5128 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5129 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5130 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5131 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5132 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5133 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5138 | __ Push(static_cast<Register>(reg)); |
| 5139 | } |
| 5140 | |
| 5141 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5142 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5143 | } |
| 5144 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5145 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5146 | InvokeRuntimeCallingConvention calling_convention; |
| 5147 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5148 | cls, |
| 5149 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5150 | Location::RegisterLocation(R0), |
| 5151 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5155 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5156 | if (cls->NeedsAccessCheck()) { |
| 5157 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5158 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5159 | cls, |
| 5160 | cls->GetDexPc(), |
| 5161 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5162 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5163 | return; |
| 5164 | } |
| 5165 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5166 | Location out_loc = locations->Out(); |
| 5167 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5168 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5169 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5170 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5171 | DCHECK(!cls->CanCallRuntime()); |
| 5172 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5173 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5174 | GenerateGcRootFieldLoad( |
| 5175 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5176 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5177 | // /* GcRoot<mirror::Class>[] */ out = |
| 5178 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5179 | __ LoadFromOffset(kLoadWord, |
| 5180 | out, |
| 5181 | current_method, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5182 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5183 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5184 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5185 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5186 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5187 | DCHECK(cls->CanCallRuntime()); |
| 5188 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 5189 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5190 | codegen_->AddSlowPath(slow_path); |
| 5191 | if (!cls->IsInDexCache()) { |
| 5192 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5193 | } |
| 5194 | if (cls->MustGenerateClinitCheck()) { |
| 5195 | GenerateClassInitializationCheck(slow_path, out); |
| 5196 | } else { |
| 5197 | __ Bind(slow_path->GetExitLabel()); |
| 5198 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5199 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5204 | LocationSummary* locations = |
| 5205 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5206 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5207 | if (check->HasUses()) { |
| 5208 | locations->SetOut(Location::SameAsFirstInput()); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5213 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5214 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5215 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5216 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5217 | GenerateClassInitializationCheck(slow_path, |
| 5218 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5219 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5220 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5221 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5222 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5223 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5224 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5225 | __ b(slow_path->GetEntryLabel(), LT); |
| 5226 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5227 | // properly. Therefore, we do a memory fence. |
| 5228 | __ dmb(ISH); |
| 5229 | __ Bind(slow_path->GetExitLabel()); |
| 5230 | } |
| 5231 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5232 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5233 | HLoadString::LoadKind desired_string_load_kind) { |
| 5234 | if (kEmitCompilerReadBarrier) { |
| 5235 | switch (desired_string_load_kind) { |
| 5236 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5237 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5238 | case HLoadString::LoadKind::kBootImageAddress: |
| 5239 | // TODO: Implement for read barrier. |
| 5240 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5241 | default: |
| 5242 | break; |
| 5243 | } |
| 5244 | } |
| 5245 | switch (desired_string_load_kind) { |
| 5246 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5247 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5248 | break; |
| 5249 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5250 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5251 | break; |
| 5252 | case HLoadString::LoadKind::kBootImageAddress: |
| 5253 | break; |
| 5254 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | e5de54c | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5255 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5256 | break; |
| 5257 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | e5de54c | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5258 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5259 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5260 | // is incompatible with it. |
| 5261 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5262 | // with irreducible loops. |
| 5263 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5264 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5265 | } |
| 5266 | break; |
| 5267 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5268 | break; |
| 5269 | } |
| 5270 | return desired_string_load_kind; |
| 5271 | } |
| 5272 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5273 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5274 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5275 | ? LocationSummary::kCallOnSlowPath |
| 5276 | : LocationSummary::kNoCall; |
| 5277 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5278 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5279 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 5280 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 5281 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5282 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5283 | locations->SetOut(Location::RequiresRegister()); |
| 5284 | } |
| 5285 | |
| 5286 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5287 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5288 | Location out_loc = locations->Out(); |
| 5289 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5290 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5291 | switch (load->GetLoadKind()) { |
| 5292 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 5293 | DCHECK(!kEmitCompilerReadBarrier); |
| 5294 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5295 | load->GetStringIndex())); |
| 5296 | return; // No dex cache slow path. |
| 5297 | } |
| 5298 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5299 | DCHECK(!kEmitCompilerReadBarrier); |
| 5300 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5301 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5302 | __ BindTrackedLabel(&labels->movw_label); |
| 5303 | __ movw(out, /* placeholder */ 0u); |
| 5304 | __ BindTrackedLabel(&labels->movt_label); |
| 5305 | __ movt(out, /* placeholder */ 0u); |
| 5306 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5307 | __ add(out, out, ShifterOperand(PC)); |
| 5308 | return; // No dex cache slow path. |
| 5309 | } |
| 5310 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5311 | DCHECK(!kEmitCompilerReadBarrier); |
| 5312 | DCHECK_NE(load->GetAddress(), 0u); |
| 5313 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5314 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5315 | return; // No dex cache slow path. |
| 5316 | } |
| 5317 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 5318 | DCHECK_NE(load->GetAddress(), 0u); |
| 5319 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5320 | // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives |
| 5321 | // a 128B range. To try and reduce the number of literals if we load multiple strings, |
| 5322 | // simply split the dex cache address to a 128B aligned base loaded from a literal |
| 5323 | // and the remaining offset embedded in the load. |
| 5324 | static_assert(sizeof(GcRoot<mirror::String>) == 4u, "Expected GC root to be 4 bytes."); |
| 5325 | DCHECK_ALIGNED(load->GetAddress(), 4u); |
| 5326 | constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2; |
| 5327 | uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits); |
| 5328 | uint32_t offset = address & MaxInt<uint32_t>(offset_bits); |
| 5329 | __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 5330 | GenerateGcRootFieldLoad(load, out_loc, out, offset); |
| 5331 | break; |
| 5332 | } |
| 5333 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 5334 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5335 | HArmDexCacheArraysBase* base = load->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5336 | int32_t offset = load->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5337 | GenerateGcRootFieldLoad(load, out_loc, base_reg, offset); |
| 5338 | break; |
| 5339 | } |
| 5340 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 5341 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5342 | |
| 5343 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5344 | GenerateGcRootFieldLoad( |
| 5345 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 5346 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5347 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
| 5348 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5349 | GenerateGcRootFieldLoad( |
| 5350 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 5351 | break; |
| 5352 | } |
| 5353 | default: |
| 5354 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 5355 | UNREACHABLE(); |
| 5356 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5357 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5358 | if (!load->IsInDexCache()) { |
| 5359 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 5360 | codegen_->AddSlowPath(slow_path); |
| 5361 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5362 | __ Bind(slow_path->GetExitLabel()); |
| 5363 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5364 | } |
| 5365 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5366 | static int32_t GetExceptionTlsOffset() { |
| 5367 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 5368 | } |
| 5369 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5370 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5371 | LocationSummary* locations = |
| 5372 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5373 | locations->SetOut(Location::RequiresRegister()); |
| 5374 | } |
| 5375 | |
| 5376 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5377 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5378 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5379 | } |
| 5380 | |
| 5381 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5382 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5383 | } |
| 5384 | |
| 5385 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5386 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5387 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5391 | LocationSummary* locations = |
| 5392 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5393 | InvokeRuntimeCallingConvention calling_convention; |
| 5394 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5395 | } |
| 5396 | |
| 5397 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 5398 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5399 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5400 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5401 | } |
| 5402 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5403 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5404 | return kEmitCompilerReadBarrier && |
| 5405 | (kUseBakerReadBarrier || |
| 5406 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5407 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5408 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5409 | } |
| 5410 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5411 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5412 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5413 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5414 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5415 | case TypeCheckKind::kExactCheck: |
| 5416 | case TypeCheckKind::kAbstractClassCheck: |
| 5417 | case TypeCheckKind::kClassHierarchyCheck: |
| 5418 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5419 | call_kind = |
| 5420 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5421 | break; |
| 5422 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5423 | case TypeCheckKind::kUnresolvedCheck: |
| 5424 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5425 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5426 | break; |
| 5427 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5428 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5429 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5431 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5432 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5433 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5434 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5435 | // When read barriers are enabled, we need a temporary register for |
| 5436 | // some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5437 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5438 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5439 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5442 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5443 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5444 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5445 | Location obj_loc = locations->InAt(0); |
| 5446 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5447 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5448 | Location out_loc = locations->Out(); |
| 5449 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5450 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5451 | locations->GetTemp(0) : |
| 5452 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5453 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5454 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5455 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5456 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5457 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5458 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5459 | |
| 5460 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5461 | // avoid null check if we know obj is not null. |
| 5462 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5463 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5464 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5465 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5466 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5467 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5468 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5469 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5470 | case TypeCheckKind::kExactCheck: { |
| 5471 | __ cmp(out, ShifterOperand(cls)); |
| 5472 | // Classes must be equal for the instanceof to succeed. |
| 5473 | __ b(&zero, NE); |
| 5474 | __ LoadImmediate(out, 1); |
| 5475 | __ b(&done); |
| 5476 | break; |
| 5477 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5478 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5479 | case TypeCheckKind::kAbstractClassCheck: { |
| 5480 | // If the class is abstract, we eagerly fetch the super class of the |
| 5481 | // object to avoid doing a comparison we know will fail. |
| 5482 | Label loop; |
| 5483 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5484 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5485 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5486 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5487 | __ CompareAndBranchIfZero(out, &done); |
| 5488 | __ cmp(out, ShifterOperand(cls)); |
| 5489 | __ b(&loop, NE); |
| 5490 | __ LoadImmediate(out, 1); |
| 5491 | if (zero.IsLinked()) { |
| 5492 | __ b(&done); |
| 5493 | } |
| 5494 | break; |
| 5495 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5496 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5497 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5498 | // Walk over the class hierarchy to find a match. |
| 5499 | Label loop, success; |
| 5500 | __ Bind(&loop); |
| 5501 | __ cmp(out, ShifterOperand(cls)); |
| 5502 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5503 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5504 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5505 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5506 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5507 | __ b(&done); |
| 5508 | __ Bind(&success); |
| 5509 | __ LoadImmediate(out, 1); |
| 5510 | if (zero.IsLinked()) { |
| 5511 | __ b(&done); |
| 5512 | } |
| 5513 | break; |
| 5514 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5515 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5516 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5517 | // Do an exact check. |
| 5518 | Label exact_check; |
| 5519 | __ cmp(out, ShifterOperand(cls)); |
| 5520 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5521 | // 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] | 5522 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5523 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5524 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5525 | __ CompareAndBranchIfZero(out, &done); |
| 5526 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5527 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5528 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5529 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5530 | __ LoadImmediate(out, 1); |
| 5531 | __ b(&done); |
| 5532 | break; |
| 5533 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5534 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5535 | case TypeCheckKind::kArrayCheck: { |
| 5536 | __ cmp(out, ShifterOperand(cls)); |
| 5537 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5538 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5539 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5540 | codegen_->AddSlowPath(slow_path); |
| 5541 | __ b(slow_path->GetEntryLabel(), NE); |
| 5542 | __ LoadImmediate(out, 1); |
| 5543 | if (zero.IsLinked()) { |
| 5544 | __ b(&done); |
| 5545 | } |
| 5546 | break; |
| 5547 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5548 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5549 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5550 | case TypeCheckKind::kInterfaceCheck: { |
| 5551 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5552 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5553 | // cases. |
| 5554 | // |
| 5555 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5556 | // entry point without resorting to a type checking slow path |
| 5557 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5558 | // require to assign fixed registers for the inputs of this |
| 5559 | // HInstanceOf instruction (following the runtime calling |
| 5560 | // convention), which might be cluttered by the potential first |
| 5561 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5562 | // |
| 5563 | // TODO: Introduce a new runtime entry point taking the object |
| 5564 | // to test (instead of its class) as argument, and let it deal |
| 5565 | // with the read barrier issues. This will let us refactor this |
| 5566 | // case of the `switch` code as it was previously (with a direct |
| 5567 | // call to the runtime not using a type checking slow path). |
| 5568 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5569 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5570 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5571 | /* is_fatal */ false); |
| 5572 | codegen_->AddSlowPath(slow_path); |
| 5573 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5574 | if (zero.IsLinked()) { |
| 5575 | __ b(&done); |
| 5576 | } |
| 5577 | break; |
| 5578 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5579 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5580 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5581 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5582 | __ Bind(&zero); |
| 5583 | __ LoadImmediate(out, 0); |
| 5584 | } |
| 5585 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5586 | if (done.IsLinked()) { |
| 5587 | __ Bind(&done); |
| 5588 | } |
| 5589 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5590 | if (slow_path != nullptr) { |
| 5591 | __ Bind(slow_path->GetExitLabel()); |
| 5592 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5593 | } |
| 5594 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5595 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5596 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5597 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5598 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5599 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5600 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5601 | case TypeCheckKind::kExactCheck: |
| 5602 | case TypeCheckKind::kAbstractClassCheck: |
| 5603 | case TypeCheckKind::kClassHierarchyCheck: |
| 5604 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5605 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5606 | LocationSummary::kCallOnSlowPath : |
| 5607 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5608 | break; |
| 5609 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5610 | case TypeCheckKind::kUnresolvedCheck: |
| 5611 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5612 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5613 | break; |
| 5614 | } |
| 5615 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5616 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5617 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5618 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5619 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5620 | locations->AddTemp(Location::RequiresRegister()); |
| 5621 | // When read barriers are enabled, we need an additional temporary |
| 5622 | // register for some cases. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5623 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5624 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5625 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5629 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5630 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5631 | Location obj_loc = locations->InAt(0); |
| 5632 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5633 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5634 | Location temp_loc = locations->GetTemp(0); |
| 5635 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5636 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5637 | locations->GetTemp(1) : |
| 5638 | Location::NoLocation(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5639 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5640 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5641 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5642 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5643 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5644 | bool is_type_check_slow_path_fatal = |
| 5645 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5646 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5647 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5648 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5649 | !instruction->CanThrowIntoCatchBlock(); |
| 5650 | SlowPathCode* type_check_slow_path = |
| 5651 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5652 | is_type_check_slow_path_fatal); |
| 5653 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5654 | |
| 5655 | Label done; |
| 5656 | // Avoid null check if we know obj is not null. |
| 5657 | if (instruction->MustDoNullCheck()) { |
| 5658 | __ CompareAndBranchIfZero(obj, &done); |
| 5659 | } |
| 5660 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5661 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5662 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5663 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5664 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5665 | case TypeCheckKind::kExactCheck: |
| 5666 | case TypeCheckKind::kArrayCheck: { |
| 5667 | __ cmp(temp, ShifterOperand(cls)); |
| 5668 | // Jump to slow path for throwing the exception or doing a |
| 5669 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5670 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5671 | break; |
| 5672 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5673 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5674 | case TypeCheckKind::kAbstractClassCheck: { |
| 5675 | // If the class is abstract, we eagerly fetch the super class of the |
| 5676 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5677 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5678 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5679 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5680 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5681 | |
| 5682 | // If the class reference currently in `temp` is not null, jump |
| 5683 | // to the `compare_classes` label to compare it with the checked |
| 5684 | // class. |
| 5685 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5686 | // Otherwise, jump to the slow path to throw the exception. |
| 5687 | // |
| 5688 | // But before, move back the object's class into `temp` before |
| 5689 | // going into the slow path, as it has been overwritten in the |
| 5690 | // meantime. |
| 5691 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5692 | GenerateReferenceLoadTwoRegisters( |
| 5693 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5694 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5695 | |
| 5696 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5697 | __ cmp(temp, ShifterOperand(cls)); |
| 5698 | __ b(&loop, NE); |
| 5699 | break; |
| 5700 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5701 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5702 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5703 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5704 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5705 | __ Bind(&loop); |
| 5706 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5707 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5708 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5709 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5710 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5711 | |
| 5712 | // If the class reference currently in `temp` is not null, jump |
| 5713 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5714 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5715 | // Otherwise, jump to the slow path to throw the exception. |
| 5716 | // |
| 5717 | // But before, move back the object's class into `temp` before |
| 5718 | // going into the slow path, as it has been overwritten in the |
| 5719 | // meantime. |
| 5720 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5721 | GenerateReferenceLoadTwoRegisters( |
| 5722 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5723 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5724 | break; |
| 5725 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5726 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5727 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5728 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5729 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5730 | __ cmp(temp, ShifterOperand(cls)); |
| 5731 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5732 | |
| 5733 | // 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] | 5734 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5735 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5736 | |
| 5737 | // If the component type is not null (i.e. the object is indeed |
| 5738 | // an array), jump to label `check_non_primitive_component_type` |
| 5739 | // to further check that this component type is not a primitive |
| 5740 | // type. |
| 5741 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 5742 | // Otherwise, jump to the slow path to throw the exception. |
| 5743 | // |
| 5744 | // But before, move back the object's class into `temp` before |
| 5745 | // going into the slow path, as it has been overwritten in the |
| 5746 | // meantime. |
| 5747 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5748 | GenerateReferenceLoadTwoRegisters( |
| 5749 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5750 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5751 | |
| 5752 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5753 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5754 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 5755 | __ CompareAndBranchIfZero(temp, &done); |
| 5756 | // Same comment as above regarding `temp` and the slow path. |
| 5757 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5758 | GenerateReferenceLoadTwoRegisters( |
| 5759 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5760 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5761 | break; |
| 5762 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5763 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5764 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5765 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5766 | // We always go into the type check slow path for the unresolved |
| 5767 | // and interface check cases. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5768 | // |
| 5769 | // We cannot directly call the CheckCast runtime entry point |
| 5770 | // without resorting to a type checking slow path here (i.e. by |
| 5771 | // calling InvokeRuntime directly), as it would require to |
| 5772 | // assign fixed registers for the inputs of this HInstanceOf |
| 5773 | // instruction (following the runtime calling convention), which |
| 5774 | // might be cluttered by the potential first read barrier |
| 5775 | // emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5776 | // |
| 5777 | // TODO: Introduce a new runtime entry point taking the object |
| 5778 | // to test (instead of its class) as argument, and let it deal |
| 5779 | // with the read barrier issues. This will let us refactor this |
| 5780 | // case of the `switch` code as it was previously (with a direct |
| 5781 | // call to the runtime not using a type checking slow path). |
| 5782 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5783 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5784 | break; |
| 5785 | } |
| 5786 | __ Bind(&done); |
| 5787 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5788 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5789 | } |
| 5790 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5791 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5792 | LocationSummary* locations = |
| 5793 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5794 | InvokeRuntimeCallingConvention calling_convention; |
| 5795 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5796 | } |
| 5797 | |
| 5798 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5799 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 5800 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 5801 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5802 | instruction->GetDexPc(), |
| 5803 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5804 | if (instruction->IsEnter()) { |
| 5805 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5806 | } else { |
| 5807 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5808 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5809 | } |
| 5810 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5811 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 5812 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 5813 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5814 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5815 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5816 | LocationSummary* locations = |
| 5817 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5818 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5819 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5820 | // 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] | 5821 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5822 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5823 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 5827 | HandleBitwiseOperation(instruction); |
| 5828 | } |
| 5829 | |
| 5830 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 5831 | HandleBitwiseOperation(instruction); |
| 5832 | } |
| 5833 | |
| 5834 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 5835 | HandleBitwiseOperation(instruction); |
| 5836 | } |
| 5837 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 5838 | |
| 5839 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 5840 | LocationSummary* locations = |
| 5841 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5842 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5843 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5844 | |
| 5845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5846 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5847 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5848 | } |
| 5849 | |
| 5850 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 5851 | LocationSummary* locations = instruction->GetLocations(); |
| 5852 | Location first = locations->InAt(0); |
| 5853 | Location second = locations->InAt(1); |
| 5854 | Location out = locations->Out(); |
| 5855 | |
| 5856 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5857 | Register first_reg = first.AsRegister<Register>(); |
| 5858 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 5859 | Register out_reg = out.AsRegister<Register>(); |
| 5860 | |
| 5861 | switch (instruction->GetOpKind()) { |
| 5862 | case HInstruction::kAnd: |
| 5863 | __ bic(out_reg, first_reg, second_reg); |
| 5864 | break; |
| 5865 | case HInstruction::kOr: |
| 5866 | __ orn(out_reg, first_reg, second_reg); |
| 5867 | break; |
| 5868 | // There is no EON on arm. |
| 5869 | case HInstruction::kXor: |
| 5870 | default: |
| 5871 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 5872 | UNREACHABLE(); |
| 5873 | } |
| 5874 | return; |
| 5875 | |
| 5876 | } else { |
| 5877 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5878 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5879 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5880 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 5881 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 5882 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5883 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5884 | |
| 5885 | switch (instruction->GetOpKind()) { |
| 5886 | case HInstruction::kAnd: |
| 5887 | __ bic(out_low, first_low, second_low); |
| 5888 | __ bic(out_high, first_high, second_high); |
| 5889 | break; |
| 5890 | case HInstruction::kOr: |
| 5891 | __ orn(out_low, first_low, second_low); |
| 5892 | __ orn(out_high, first_high, second_high); |
| 5893 | break; |
| 5894 | // There is no EON on arm. |
| 5895 | case HInstruction::kXor: |
| 5896 | default: |
| 5897 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 5898 | UNREACHABLE(); |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5903 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 5904 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 5905 | if (value == 0xffffffffu) { |
| 5906 | if (out != first) { |
| 5907 | __ mov(out, ShifterOperand(first)); |
| 5908 | } |
| 5909 | return; |
| 5910 | } |
| 5911 | if (value == 0u) { |
| 5912 | __ mov(out, ShifterOperand(0)); |
| 5913 | return; |
| 5914 | } |
| 5915 | ShifterOperand so; |
| 5916 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 5917 | __ and_(out, first, so); |
| 5918 | } else { |
| 5919 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 5920 | __ bic(out, first, ShifterOperand(~value)); |
| 5921 | } |
| 5922 | } |
| 5923 | |
| 5924 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 5925 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 5926 | if (value == 0u) { |
| 5927 | if (out != first) { |
| 5928 | __ mov(out, ShifterOperand(first)); |
| 5929 | } |
| 5930 | return; |
| 5931 | } |
| 5932 | if (value == 0xffffffffu) { |
| 5933 | __ mvn(out, ShifterOperand(0)); |
| 5934 | return; |
| 5935 | } |
| 5936 | ShifterOperand so; |
| 5937 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 5938 | __ orr(out, first, so); |
| 5939 | } else { |
| 5940 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 5941 | __ orn(out, first, ShifterOperand(~value)); |
| 5942 | } |
| 5943 | } |
| 5944 | |
| 5945 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 5946 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 5947 | if (value == 0u) { |
| 5948 | if (out != first) { |
| 5949 | __ mov(out, ShifterOperand(first)); |
| 5950 | } |
| 5951 | return; |
| 5952 | } |
| 5953 | __ eor(out, first, ShifterOperand(value)); |
| 5954 | } |
| 5955 | |
Vladimir Marko | 966901f | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5956 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 5957 | Location first, |
| 5958 | uint64_t value) { |
| 5959 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5960 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5961 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5962 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5963 | uint32_t value_low = Low32Bits(value); |
| 5964 | uint32_t value_high = High32Bits(value); |
| 5965 | if (value_low == 0u) { |
| 5966 | if (out_low != first_low) { |
| 5967 | __ mov(out_low, ShifterOperand(first_low)); |
| 5968 | } |
| 5969 | __ AddConstant(out_high, first_high, value_high); |
| 5970 | return; |
| 5971 | } |
| 5972 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 5973 | ShifterOperand so; |
| 5974 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 5975 | __ adc(out_high, first_high, so); |
| 5976 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 5977 | __ sbc(out_high, first_high, so); |
| 5978 | } else { |
| 5979 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 5980 | UNREACHABLE(); |
| 5981 | } |
| 5982 | } |
| 5983 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5984 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5985 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5986 | Location first = locations->InAt(0); |
| 5987 | Location second = locations->InAt(1); |
| 5988 | Location out = locations->Out(); |
| 5989 | |
| 5990 | if (second.IsConstant()) { |
| 5991 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 5992 | uint32_t value_low = Low32Bits(value); |
| 5993 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5994 | Register first_reg = first.AsRegister<Register>(); |
| 5995 | Register out_reg = out.AsRegister<Register>(); |
| 5996 | if (instruction->IsAnd()) { |
| 5997 | GenerateAndConst(out_reg, first_reg, value_low); |
| 5998 | } else if (instruction->IsOr()) { |
| 5999 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6000 | } else { |
| 6001 | DCHECK(instruction->IsXor()); |
| 6002 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6003 | } |
| 6004 | } else { |
| 6005 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6006 | uint32_t value_high = High32Bits(value); |
| 6007 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6008 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6009 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6010 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6011 | if (instruction->IsAnd()) { |
| 6012 | GenerateAndConst(out_low, first_low, value_low); |
| 6013 | GenerateAndConst(out_high, first_high, value_high); |
| 6014 | } else if (instruction->IsOr()) { |
| 6015 | GenerateOrrConst(out_low, first_low, value_low); |
| 6016 | GenerateOrrConst(out_high, first_high, value_high); |
| 6017 | } else { |
| 6018 | DCHECK(instruction->IsXor()); |
| 6019 | GenerateEorConst(out_low, first_low, value_low); |
| 6020 | GenerateEorConst(out_high, first_high, value_high); |
| 6021 | } |
| 6022 | } |
| 6023 | return; |
| 6024 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6025 | |
| 6026 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6027 | Register first_reg = first.AsRegister<Register>(); |
| 6028 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6029 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6030 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6031 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6032 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6033 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6034 | } else { |
| 6035 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6036 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6037 | } |
| 6038 | } else { |
| 6039 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6040 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6041 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6042 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6043 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6044 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6045 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6046 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6047 | __ and_(out_low, first_low, second_low); |
| 6048 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6049 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6050 | __ orr(out_low, first_low, second_low); |
| 6051 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6052 | } else { |
| 6053 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6054 | __ eor(out_low, first_low, second_low); |
| 6055 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6056 | } |
| 6057 | } |
| 6058 | } |
| 6059 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6060 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6061 | Location out, |
| 6062 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6063 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6064 | Register out_reg = out.AsRegister<Register>(); |
| 6065 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6066 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6067 | if (kUseBakerReadBarrier) { |
| 6068 | // Load with fast path based Baker's read barrier. |
| 6069 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6070 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6071 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6072 | } else { |
| 6073 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6074 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6075 | // in the following move operation, as we will need it for the |
| 6076 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6077 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6078 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6079 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6080 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6081 | } |
| 6082 | } else { |
| 6083 | // Plain load with no read barrier. |
| 6084 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6085 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6086 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6091 | Location out, |
| 6092 | Location obj, |
| 6093 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6094 | Location maybe_temp) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6095 | Register out_reg = out.AsRegister<Register>(); |
| 6096 | Register obj_reg = obj.AsRegister<Register>(); |
| 6097 | if (kEmitCompilerReadBarrier) { |
| 6098 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6099 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6100 | // Load with fast path based Baker's read barrier. |
| 6101 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6102 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6103 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6104 | } else { |
| 6105 | // Load with slow path based read barrier. |
| 6106 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6107 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6108 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6109 | } |
| 6110 | } else { |
| 6111 | // Plain load with no read barrier. |
| 6112 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6113 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6114 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6119 | Location root, |
| 6120 | Register obj, |
| 6121 | uint32_t offset) { |
| 6122 | Register root_reg = root.AsRegister<Register>(); |
| 6123 | if (kEmitCompilerReadBarrier) { |
| 6124 | if (kUseBakerReadBarrier) { |
| 6125 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6126 | // Baker's read barrier are used: |
| 6127 | // |
| 6128 | // root = obj.field; |
| 6129 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6130 | // root = ReadBarrier::Mark(root) |
| 6131 | // } |
| 6132 | |
| 6133 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6134 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6135 | static_assert( |
| 6136 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6137 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6138 | "have different sizes."); |
| 6139 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6140 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6141 | "have different sizes."); |
| 6142 | |
| 6143 | // Slow path used to mark the GC root `root`. |
| 6144 | SlowPathCode* slow_path = |
| 6145 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root, root); |
| 6146 | codegen_->AddSlowPath(slow_path); |
| 6147 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6148 | // IP = Thread::Current()->GetIsGcMarking() |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6149 | __ LoadFromOffset( |
| 6150 | kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmWordSize>().Int32Value()); |
| 6151 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
| 6152 | __ Bind(slow_path->GetExitLabel()); |
| 6153 | } else { |
| 6154 | // GC root loaded through a slow path for read barriers other |
| 6155 | // than Baker's. |
| 6156 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6157 | __ AddConstant(root_reg, obj, offset); |
| 6158 | // /* mirror::Object* */ root = root->Read() |
| 6159 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6160 | } |
| 6161 | } else { |
| 6162 | // Plain GC root load with no read barrier. |
| 6163 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6164 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6165 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6166 | // do not have to unpoison `root_reg` here. |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6171 | Location ref, |
| 6172 | Register obj, |
| 6173 | uint32_t offset, |
| 6174 | Location temp, |
| 6175 | bool needs_null_check) { |
| 6176 | DCHECK(kEmitCompilerReadBarrier); |
| 6177 | DCHECK(kUseBakerReadBarrier); |
| 6178 | |
| 6179 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6180 | Location no_index = Location::NoLocation(); |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6181 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6182 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6183 | instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6187 | Location ref, |
| 6188 | Register obj, |
| 6189 | uint32_t data_offset, |
| 6190 | Location index, |
| 6191 | Location temp, |
| 6192 | bool needs_null_check) { |
| 6193 | DCHECK(kEmitCompilerReadBarrier); |
| 6194 | DCHECK(kUseBakerReadBarrier); |
| 6195 | |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6196 | static_assert( |
| 6197 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6198 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6199 | // /* HeapReference<Object> */ ref = |
| 6200 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6201 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6202 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6203 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6207 | Location ref, |
| 6208 | Register obj, |
| 6209 | uint32_t offset, |
| 6210 | Location index, |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6211 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6212 | Location temp, |
| 6213 | bool needs_null_check) { |
| 6214 | DCHECK(kEmitCompilerReadBarrier); |
| 6215 | DCHECK(kUseBakerReadBarrier); |
| 6216 | |
| 6217 | // In slow path based read barriers, the read barrier call is |
| 6218 | // inserted after the original load. However, in fast path based |
| 6219 | // Baker's read barriers, we need to perform the load of |
| 6220 | // mirror::Object::monitor_ *before* the original reference load. |
| 6221 | // This load-load ordering is required by the read barrier. |
| 6222 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6223 | // |
| 6224 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6225 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6226 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6227 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6228 | // if (is_gray) { |
| 6229 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6230 | // } |
| 6231 | // |
| 6232 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6233 | // slightly more complex as it performs additional checks that we do |
| 6234 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6235 | |
| 6236 | Register ref_reg = ref.AsRegister<Register>(); |
| 6237 | Register temp_reg = temp.AsRegister<Register>(); |
| 6238 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6239 | |
| 6240 | // /* int32_t */ monitor = obj->monitor_ |
| 6241 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 6242 | if (needs_null_check) { |
| 6243 | MaybeRecordImplicitNullCheck(instruction); |
| 6244 | } |
| 6245 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6246 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6247 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6248 | |
Vladimir Marko | b7d10aa | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6249 | // Introduce a dependency on the lock_word including the rb_state, |
| 6250 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6251 | // a memory barrier (which would be more expensive). |
Vladimir Marko | b7d10aa | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6252 | // obj is unchanged by this operation, but its value now depends on temp_reg. |
| 6253 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6254 | |
| 6255 | // The actual reference load. |
| 6256 | if (index.IsValid()) { |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6257 | // Load types involving an "index": ArrayGet and |
| 6258 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 6259 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6260 | if (index.IsConstant()) { |
| 6261 | size_t computed_offset = |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6262 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6263 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 6264 | } else { |
Roland Levillain | b6a9441 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6265 | // Handle the special case of the |
| 6266 | // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use |
| 6267 | // a register pair as index ("long offset"), of which only the low |
| 6268 | // part contains data. |
| 6269 | Register index_reg = index.IsRegisterPair() |
| 6270 | ? index.AsRegisterPairLow<Register>() |
| 6271 | : index.AsRegister<Register>(); |
| 6272 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6273 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 6274 | } |
| 6275 | } else { |
| 6276 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6277 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 6278 | } |
| 6279 | |
| 6280 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6281 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6282 | |
| 6283 | // Slow path used to mark the object `ref` when it is gray. |
| 6284 | SlowPathCode* slow_path = |
| 6285 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref, ref); |
| 6286 | AddSlowPath(slow_path); |
| 6287 | |
| 6288 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6289 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | b7d10aa | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 6290 | // Given the numeric representation, it's enough to check the low bit of the |
| 6291 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 6292 | // which can be a 16-bit instruction unlike the TST immediate. |
| 6293 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6294 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6295 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6296 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 6297 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6298 | __ Bind(slow_path->GetExitLabel()); |
| 6299 | } |
| 6300 | |
| 6301 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6302 | Location out, |
| 6303 | Location ref, |
| 6304 | Location obj, |
| 6305 | uint32_t offset, |
| 6306 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6307 | DCHECK(kEmitCompilerReadBarrier); |
| 6308 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6309 | // Insert a slow path based read barrier *after* the reference load. |
| 6310 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6311 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6312 | // reference will be carried out by the runtime within the slow |
| 6313 | // path. |
| 6314 | // |
| 6315 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6316 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6317 | // not used by the artReadBarrierSlow entry point. |
| 6318 | // |
| 6319 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6320 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6321 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 6322 | AddSlowPath(slow_path); |
| 6323 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6324 | __ b(slow_path->GetEntryLabel()); |
| 6325 | __ Bind(slow_path->GetExitLabel()); |
| 6326 | } |
| 6327 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6328 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6329 | Location out, |
| 6330 | Location ref, |
| 6331 | Location obj, |
| 6332 | uint32_t offset, |
| 6333 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6334 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6335 | // Baker's read barriers shall be handled by the fast path |
| 6336 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 6337 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6338 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6339 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6340 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6341 | } else if (kPoisonHeapReferences) { |
| 6342 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6343 | } |
| 6344 | } |
| 6345 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6346 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6347 | Location out, |
| 6348 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6349 | DCHECK(kEmitCompilerReadBarrier); |
| 6350 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6351 | // Insert a slow path based read barrier *after* the GC root load. |
| 6352 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6353 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6354 | // not need to do anything special for this here. |
| 6355 | SlowPathCode* slow_path = |
| 6356 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 6357 | AddSlowPath(slow_path); |
| 6358 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6359 | __ b(slow_path->GetEntryLabel()); |
| 6360 | __ Bind(slow_path->GetExitLabel()); |
| 6361 | } |
| 6362 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6363 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 6364 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 6365 | MethodReference target_method) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6366 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 6367 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6368 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6369 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 6370 | // with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6371 | if (GetGraph()->HasIrreducibleLoops() && |
| 6372 | (dispatch_info.method_load_kind == |
| 6373 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 6374 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 6375 | } |
| 6376 | |
| 6377 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6378 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 6379 | if (&outer_dex_file != target_method.dex_file) { |
| 6380 | // Calls across dex files are more likely to exceed the available BL range, |
| 6381 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 6382 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 6383 | (desired_dispatch_info.method_load_kind == |
| 6384 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 6385 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 6386 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 6387 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6388 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6389 | code_ptr_location, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6390 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6391 | 0u |
| 6392 | }; |
| 6393 | } |
| 6394 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 6395 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6396 | } |
| 6397 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6398 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 6399 | Register temp) { |
| 6400 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 6401 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 6402 | if (!invoke->GetLocations()->Intrinsified()) { |
| 6403 | return location.AsRegister<Register>(); |
| 6404 | } |
| 6405 | // For intrinsics we allow any location, so it may be on the stack. |
| 6406 | if (!location.IsRegister()) { |
| 6407 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 6408 | return temp; |
| 6409 | } |
| 6410 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 6411 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 6412 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 6413 | // simple and more robust approach rather that trying to determine if that's the case. |
| 6414 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 6415 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 6416 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 6417 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 6418 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 6419 | return temp; |
| 6420 | } |
| 6421 | return location.AsRegister<Register>(); |
| 6422 | } |
| 6423 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 6424 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6425 | // 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] | 6426 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6427 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6428 | // LR = code address from literal pool with link-time patch. |
| 6429 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6430 | break; |
| 6431 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6432 | // LR = invoke->GetDirectCodePtr(); |
| 6433 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6434 | break; |
| 6435 | default: |
| 6436 | break; |
| 6437 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6438 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6439 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 6440 | switch (invoke->GetMethodLoadKind()) { |
| 6441 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 6442 | // temp = thread->string_init_entrypoint |
| 6443 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 6444 | break; |
| 6445 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6446 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6447 | break; |
| 6448 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 6449 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 6450 | break; |
| 6451 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 6452 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 6453 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 6454 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6455 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 6456 | HArmDexCacheArraysBase* base = |
| 6457 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 6458 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 6459 | temp.AsRegister<Register>()); |
| 6460 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 6461 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 6462 | break; |
| 6463 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6464 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 6465 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6466 | Register method_reg; |
| 6467 | Register reg = temp.AsRegister<Register>(); |
| 6468 | if (current_method.IsRegister()) { |
| 6469 | method_reg = current_method.AsRegister<Register>(); |
| 6470 | } else { |
| 6471 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 6472 | DCHECK(!current_method.IsValid()); |
| 6473 | method_reg = reg; |
| 6474 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 6475 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6476 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 6477 | __ LoadFromOffset(kLoadWord, |
| 6478 | reg, |
| 6479 | method_reg, |
| 6480 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 6481 | // temp = temp[index_in_cache]; |
| 6482 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 6483 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6484 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 6485 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 6486 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | switch (invoke->GetCodePtrLocation()) { |
| 6490 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 6491 | __ bl(GetFrameEntryLabel()); |
| 6492 | break; |
| 6493 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6494 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6495 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 6496 | // Arbitrarily branch to the BL itself, override at link time. |
| 6497 | __ bl(&relative_call_patches_.back().label); |
| 6498 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6499 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 6500 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 6501 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6502 | // LR() |
| 6503 | __ blx(LR); |
| 6504 | break; |
| 6505 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 6506 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 6507 | __ LoadFromOffset( |
| 6508 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 6509 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 6510 | // LR() |
| 6511 | __ blx(LR); |
| 6512 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6513 | } |
| 6514 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 6515 | DCHECK(!IsLeafMethod()); |
| 6516 | } |
| 6517 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6518 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 6519 | Register temp = temp_location.AsRegister<Register>(); |
| 6520 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 6521 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6522 | |
| 6523 | // Use the calling convention instead of the location of the receiver, as |
| 6524 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 6525 | // slow path, the arguments have been moved to the right place, so here we are |
| 6526 | // guaranteed that the receiver is the first register of the calling convention. |
| 6527 | InvokeDexCallingConvention calling_convention; |
| 6528 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6529 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6530 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 6531 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6532 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6533 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 6534 | // emit a read barrier for the previous class reference load. |
| 6535 | // However this is not required in practice, as this is an |
| 6536 | // intermediate/temporary reference and because the current |
| 6537 | // concurrent copying collector keeps the from-space memory |
| 6538 | // intact/accessible until the end of the marking phase (the |
| 6539 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 6540 | __ MaybeUnpoisonHeapReference(temp); |
| 6541 | // temp = temp->GetMethodAt(method_offset); |
| 6542 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 6543 | kArmWordSize).Int32Value(); |
| 6544 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 6545 | // LR = temp->GetEntryPoint(); |
| 6546 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 6547 | // LR(); |
| 6548 | __ blx(LR); |
| 6549 | } |
| 6550 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6551 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 6552 | const DexFile& dex_file, uint32_t string_index) { |
| 6553 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 6554 | } |
| 6555 | |
| 6556 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 6557 | const DexFile& dex_file, uint32_t element_offset) { |
| 6558 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 6559 | } |
| 6560 | |
| 6561 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 6562 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 6563 | patches->emplace_back(dex_file, offset_or_index); |
| 6564 | return &patches->back(); |
| 6565 | } |
| 6566 | |
| 6567 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 6568 | uint32_t string_index) { |
| 6569 | return boot_image_string_patches_.GetOrCreate( |
| 6570 | StringReference(&dex_file, string_index), |
| 6571 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 6572 | } |
| 6573 | |
| 6574 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 6575 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 6576 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 6577 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 6578 | } |
| 6579 | |
| 6580 | Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 6581 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 6582 | } |
| 6583 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6584 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 6585 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6586 | size_t size = |
| 6587 | method_patches_.size() + |
| 6588 | call_patches_.size() + |
| 6589 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6590 | /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() + |
| 6591 | boot_image_string_patches_.size() + |
| 6592 | /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() + |
| 6593 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6594 | linker_patches->reserve(size); |
| 6595 | for (const auto& entry : method_patches_) { |
| 6596 | const MethodReference& target_method = entry.first; |
| 6597 | Literal* literal = entry.second; |
| 6598 | DCHECK(literal->GetLabel()->IsBound()); |
| 6599 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6600 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 6601 | target_method.dex_file, |
| 6602 | target_method.dex_method_index)); |
| 6603 | } |
| 6604 | for (const auto& entry : call_patches_) { |
| 6605 | const MethodReference& target_method = entry.first; |
| 6606 | Literal* literal = entry.second; |
| 6607 | DCHECK(literal->GetLabel()->IsBound()); |
| 6608 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6609 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 6610 | target_method.dex_file, |
| 6611 | target_method.dex_method_index)); |
| 6612 | } |
| 6613 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 6614 | uint32_t literal_offset = info.label.Position(); |
| 6615 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 6616 | info.target_method.dex_file, |
| 6617 | info.target_method.dex_method_index)); |
| 6618 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6619 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
| 6620 | const DexFile& dex_file = info.target_dex_file; |
| 6621 | size_t base_element_offset = info.offset_or_index; |
| 6622 | DCHECK(info.add_pc_label.IsBound()); |
| 6623 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6624 | // Add MOVW patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6625 | DCHECK(info.movw_label.IsBound()); |
| 6626 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6627 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset, |
| 6628 | &dex_file, |
| 6629 | add_pc_offset, |
| 6630 | base_element_offset)); |
| 6631 | // Add MOVT patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6632 | DCHECK(info.movt_label.IsBound()); |
| 6633 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6634 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset, |
| 6635 | &dex_file, |
| 6636 | add_pc_offset, |
| 6637 | base_element_offset)); |
| 6638 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6639 | for (const auto& entry : boot_image_string_patches_) { |
| 6640 | const StringReference& target_string = entry.first; |
| 6641 | Literal* literal = entry.second; |
| 6642 | DCHECK(literal->GetLabel()->IsBound()); |
| 6643 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6644 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 6645 | target_string.dex_file, |
| 6646 | target_string.string_index)); |
| 6647 | } |
| 6648 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 6649 | const DexFile& dex_file = info.target_dex_file; |
| 6650 | uint32_t string_index = info.offset_or_index; |
| 6651 | DCHECK(info.add_pc_label.IsBound()); |
| 6652 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 6653 | // Add MOVW patch. |
| 6654 | DCHECK(info.movw_label.IsBound()); |
| 6655 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 6656 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset, |
| 6657 | &dex_file, |
| 6658 | add_pc_offset, |
| 6659 | string_index)); |
| 6660 | // Add MOVT patch. |
| 6661 | DCHECK(info.movt_label.IsBound()); |
| 6662 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 6663 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset, |
| 6664 | &dex_file, |
| 6665 | add_pc_offset, |
| 6666 | string_index)); |
| 6667 | } |
| 6668 | for (const auto& entry : boot_image_address_patches_) { |
| 6669 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 6670 | Literal* literal = entry.second; |
| 6671 | DCHECK(literal->GetLabel()->IsBound()); |
| 6672 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 6673 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 6678 | return map->GetOrCreate( |
| 6679 | value, |
| 6680 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6681 | } |
| 6682 | |
| 6683 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 6684 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6685 | return map->GetOrCreate( |
| 6686 | target_method, |
| 6687 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 6691 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 6692 | } |
| 6693 | |
| 6694 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 6695 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 6696 | } |
| 6697 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6698 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 6699 | LocationSummary* locations = |
| 6700 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 6701 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 6702 | Location::RequiresRegister()); |
| 6703 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 6704 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 6705 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6706 | } |
| 6707 | |
| 6708 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 6709 | LocationSummary* locations = instr->GetLocations(); |
| 6710 | Register res = locations->Out().AsRegister<Register>(); |
| 6711 | Register accumulator = |
| 6712 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 6713 | Register mul_left = |
| 6714 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 6715 | Register mul_right = |
| 6716 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 6717 | |
| 6718 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 6719 | __ mla(res, mul_left, mul_right, accumulator); |
| 6720 | } else { |
| 6721 | __ mls(res, mul_left, mul_right, accumulator); |
| 6722 | } |
| 6723 | } |
| 6724 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6725 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6726 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6727 | LOG(FATAL) << "Unreachable"; |
| 6728 | } |
| 6729 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6730 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6731 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6732 | LOG(FATAL) << "Unreachable"; |
| 6733 | } |
| 6734 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6735 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6736 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6737 | LocationSummary* locations = |
| 6738 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6739 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6740 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6741 | codegen_->GetAssembler()->IsThumb()) { |
| 6742 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 6743 | if (switch_instr->GetStartValue() != 0) { |
| 6744 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 6745 | } |
| 6746 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6750 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6751 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6752 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6753 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6754 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6755 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6756 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6757 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6758 | Register temp_reg = IP; |
| 6759 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 6760 | // the immediate, because IP is used as the destination register. For the other |
| 6761 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 6762 | // and they can be encoded in the instruction without making use of IP register. |
| 6763 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 6764 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6765 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6766 | // Jump to successors[0] if value == lower_bound. |
| 6767 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 6768 | int32_t last_index = 0; |
| 6769 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6770 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 6771 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6772 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 6773 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6774 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 6775 | } |
| 6776 | if (num_entries - last_index == 2) { |
| 6777 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 6778 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6779 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6780 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6781 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6782 | // And the default for any other value. |
| 6783 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6784 | __ b(codegen_->GetLabelOf(default_block)); |
| 6785 | } |
| 6786 | } else { |
| 6787 | // Create a table lookup. |
| 6788 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6789 | |
| 6790 | // Materialize a pointer to the switch table |
| 6791 | std::vector<Label*> labels(num_entries); |
| 6792 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6793 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6794 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6795 | } |
| 6796 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 6797 | |
| 6798 | // Remove the bias. |
| 6799 | Register key_reg; |
| 6800 | if (lower_bound != 0) { |
| 6801 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 6802 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 6803 | } else { |
| 6804 | key_reg = value_reg; |
| 6805 | } |
| 6806 | |
| 6807 | // Check whether the value is in the table, jump to default block if not. |
| 6808 | __ CmpConstant(key_reg, num_entries - 1); |
| 6809 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 6810 | |
| 6811 | // Load the displacement from the table. |
| 6812 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 6813 | |
| 6814 | // Dispatch is a direct add to the PC (for Thumb2). |
| 6815 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6816 | } |
| 6817 | } |
| 6818 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6819 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6820 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 6821 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6822 | } |
| 6823 | |
| 6824 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 6825 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6826 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6827 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6828 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6829 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6830 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6831 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6832 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6833 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 6834 | } |
| 6835 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6836 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6837 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6838 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6839 | return; |
| 6840 | } |
| 6841 | |
| 6842 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6843 | |
| 6844 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 6845 | if (return_loc.Equals(trg)) { |
| 6846 | return; |
| 6847 | } |
| 6848 | |
| 6849 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 6850 | // with the last branch. |
| 6851 | if (type == Primitive::kPrimLong) { |
| 6852 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6853 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 6854 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 6855 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6856 | } else if (type == Primitive::kPrimDouble) { |
| 6857 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6858 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 6859 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 6860 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6861 | } else { |
| 6862 | // Let the parallel move resolver take care of all of this. |
| 6863 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6864 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6865 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6866 | } |
| 6867 | } |
| 6868 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6869 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 6870 | LocationSummary* locations = |
| 6871 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6873 | locations->SetOut(Location::RequiresRegister()); |
| 6874 | } |
| 6875 | |
| 6876 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 6877 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6878 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6879 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6880 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6881 | __ LoadFromOffset(kLoadWord, |
| 6882 | locations->Out().AsRegister<Register>(), |
| 6883 | locations->InAt(0).AsRegister<Register>(), |
| 6884 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6885 | } else { |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6886 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Artem Udovichenko | df2d4f2 | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6887 | instruction->GetIndex() % ImTable::kSize, kArmPointerSize)); |
Nicolas Geoffray | b3cd84a | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6888 | __ LoadFromOffset(kLoadWord, |
| 6889 | locations->Out().AsRegister<Register>(), |
| 6890 | locations->InAt(0).AsRegister<Register>(), |
| 6891 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 6892 | __ LoadFromOffset(kLoadWord, |
| 6893 | locations->Out().AsRegister<Register>(), |
| 6894 | locations->Out().AsRegister<Register>(), |
| 6895 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6896 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6897 | } |
| 6898 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6899 | #undef __ |
| 6900 | #undef QUICK_ENTRY_POINT |
| 6901 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6902 | } // namespace arm |
| 6903 | } // namespace art |