Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 50 | // We unconditionally allocate R5 to ensure we can do long operations |
| 51 | // with baseline. |
| 52 | static constexpr Register kCoreSavedRegisterForBaseline = R5; |
| 53 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 54 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 55 | static constexpr SRegister kFpuCalleeSaves[] = |
| 56 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 57 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 58 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 59 | // S registers. Therefore there is no need to block it. |
| 60 | static constexpr DRegister DTMP = D31; |
| 61 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 62 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6; |
| 63 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 64 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 65 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 67 | class NullCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 69 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 71 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 72 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 74 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 75 | // Live registers will be restored in the catch block if caught. |
| 76 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 77 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 78 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 79 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | bool IsFatal() const OVERRIDE { return true; } |
| 83 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 84 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 85 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 87 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 89 | }; |
| 90 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 91 | class DivZeroCheckSlowPathARM : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | public: |
| 93 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 94 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 95 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 97 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 98 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 99 | // Live registers will be restored in the catch block if caught. |
| 100 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 101 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 103 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 106 | bool IsFatal() const OVERRIDE { return true; } |
| 107 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 108 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 109 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | private: |
| 111 | HDivZeroCheck* const instruction_; |
| 112 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 113 | }; |
| 114 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 115 | class SuspendCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 116 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 117 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 118 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 119 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 120 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 121 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 122 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 123 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 124 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 125 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 126 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 127 | if (successor_ == nullptr) { |
| 128 | __ b(GetReturnLabel()); |
| 129 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 130 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 131 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | Label* GetReturnLabel() { |
| 135 | DCHECK(successor_ == nullptr); |
| 136 | return &return_label_; |
| 137 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 139 | HBasicBlock* GetSuccessor() const { |
| 140 | return successor_; |
| 141 | } |
| 142 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 143 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 144 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | private: |
| 146 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 147 | // If not null, the block to branch to after the suspend check. |
| 148 | HBasicBlock* const successor_; |
| 149 | |
| 150 | // 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] | 151 | Label return_label_; |
| 152 | |
| 153 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 154 | }; |
| 155 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 156 | class BoundsCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 158 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
| 159 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 161 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 162 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 163 | LocationSummary* locations = instruction_->GetLocations(); |
| 164 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 165 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 166 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 167 | // Live registers will be restored in the catch block if caught. |
| 168 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 169 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 170 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 171 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 172 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 173 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 174 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 175 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 176 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 177 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 178 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 179 | Primitive::kPrimInt); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 180 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 181 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 184 | bool IsFatal() const OVERRIDE { return true; } |
| 185 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 186 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 187 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 189 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | |
| 191 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 192 | }; |
| 193 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 194 | class LoadClassSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 195 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 196 | LoadClassSlowPathARM(HLoadClass* cls, |
| 197 | HInstruction* at, |
| 198 | uint32_t dex_pc, |
| 199 | bool do_clinit) |
| 200 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 201 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 202 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 203 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 204 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 205 | LocationSummary* locations = at_->GetLocations(); |
| 206 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 207 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 208 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 209 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 210 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 211 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 212 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 213 | int32_t entry_point_offset = do_clinit_ |
| 214 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 215 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 216 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 217 | |
| 218 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 219 | Location out = locations->Out(); |
| 220 | if (out.IsValid()) { |
| 221 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 222 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 223 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 224 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | __ b(GetExitLabel()); |
| 226 | } |
| 227 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 229 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | // The class this slow path will load. |
| 232 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 233 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 234 | // The instruction where this slow path is happening. |
| 235 | // (Might be the load class or an initialization check). |
| 236 | HInstruction* const at_; |
| 237 | |
| 238 | // The dex PC of `at_`. |
| 239 | const uint32_t dex_pc_; |
| 240 | |
| 241 | // Whether to initialize the class. |
| 242 | const bool do_clinit_; |
| 243 | |
| 244 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | }; |
| 246 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 247 | class LoadStringSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 248 | public: |
| 249 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 250 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 251 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 252 | LocationSummary* locations = instruction_->GetLocations(); |
| 253 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 254 | |
| 255 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 256 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 257 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 258 | |
| 259 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 260 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 261 | arm_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 262 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 263 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 264 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 266 | __ b(GetExitLabel()); |
| 267 | } |
| 268 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 269 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 270 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 271 | private: |
| 272 | HLoadString* const instruction_; |
| 273 | |
| 274 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 275 | }; |
| 276 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 277 | class TypeCheckSlowPathARM : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 278 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 279 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
| 280 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 281 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 282 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 284 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 285 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 286 | DCHECK(instruction_->IsCheckCast() |
| 287 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | |
| 289 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 290 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 291 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 292 | if (!is_fatal_) { |
| 293 | SaveLiveRegisters(codegen, locations); |
| 294 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 | |
| 296 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 297 | // move resolver. |
| 298 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 299 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 300 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 301 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 302 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 303 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 304 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 305 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 307 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 308 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 309 | instruction_, |
| 310 | instruction_->GetDexPc(), |
| 311 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 312 | CheckEntrypointTypes< |
| 313 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 314 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 315 | } else { |
| 316 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 317 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 318 | instruction_, |
| 319 | instruction_->GetDexPc(), |
| 320 | this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 321 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 322 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 324 | if (!is_fatal_) { |
| 325 | RestoreLiveRegisters(codegen, locations); |
| 326 | __ b(GetExitLabel()); |
| 327 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 330 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 331 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 333 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 335 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 336 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | |
| 338 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 339 | }; |
| 340 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 341 | class DeoptimizationSlowPathARM : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 342 | public: |
| 343 | explicit DeoptimizationSlowPathARM(HInstruction* instruction) |
| 344 | : instruction_(instruction) {} |
| 345 | |
| 346 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 347 | __ Bind(GetEntryLabel()); |
| 348 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 349 | DCHECK(instruction_->IsDeoptimize()); |
| 350 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 351 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 352 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 353 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 354 | } |
| 355 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 356 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 357 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | private: |
| 359 | HInstruction* const instruction_; |
| 360 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 361 | }; |
| 362 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 363 | class ArraySetSlowPathARM : public SlowPathCode { |
| 364 | public: |
| 365 | explicit ArraySetSlowPathARM(HInstruction* instruction) : instruction_(instruction) {} |
| 366 | |
| 367 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 368 | LocationSummary* locations = instruction_->GetLocations(); |
| 369 | __ Bind(GetEntryLabel()); |
| 370 | SaveLiveRegisters(codegen, locations); |
| 371 | |
| 372 | InvokeRuntimeCallingConvention calling_convention; |
| 373 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 374 | parallel_move.AddMove( |
| 375 | locations->InAt(0), |
| 376 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 377 | Primitive::kPrimNot, |
| 378 | nullptr); |
| 379 | parallel_move.AddMove( |
| 380 | locations->InAt(1), |
| 381 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 382 | Primitive::kPrimInt, |
| 383 | nullptr); |
| 384 | parallel_move.AddMove( |
| 385 | locations->InAt(2), |
| 386 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 387 | Primitive::kPrimNot, |
| 388 | nullptr); |
| 389 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 390 | |
| 391 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 392 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 393 | instruction_, |
| 394 | instruction_->GetDexPc(), |
| 395 | this); |
| 396 | RestoreLiveRegisters(codegen, locations); |
| 397 | __ b(GetExitLabel()); |
| 398 | } |
| 399 | |
| 400 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 401 | |
| 402 | private: |
| 403 | HInstruction* const instruction_; |
| 404 | |
| 405 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 406 | }; |
| 407 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 408 | // Slow path generating a read barrier for a heap reference. |
| 409 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode { |
| 410 | public: |
| 411 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 412 | Location out, |
| 413 | Location ref, |
| 414 | Location obj, |
| 415 | uint32_t offset, |
| 416 | Location index) |
| 417 | : instruction_(instruction), |
| 418 | out_(out), |
| 419 | ref_(ref), |
| 420 | obj_(obj), |
| 421 | offset_(offset), |
| 422 | index_(index) { |
| 423 | DCHECK(kEmitCompilerReadBarrier); |
| 424 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 425 | // has been overwritten by (or after) the heap object reference load |
| 426 | // to be instrumented, e.g.: |
| 427 | // |
| 428 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 429 | // codegen_->GenerateReadBarrier(instruction, out_loc, out_loc, out_loc, offset); |
| 430 | // |
| 431 | // In that case, we have lost the information about the original |
| 432 | // object, and the emitted read barrier cannot work properly. |
| 433 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 434 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 435 | } |
| 436 | |
| 437 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 438 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 439 | LocationSummary* locations = instruction_->GetLocations(); |
| 440 | Register reg_out = out_.AsRegister<Register>(); |
| 441 | DCHECK(locations->CanCall()); |
| 442 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 443 | DCHECK(!instruction_->IsInvoke() || |
| 444 | (instruction_->IsInvokeStaticOrDirect() && |
| 445 | instruction_->GetLocations()->Intrinsified())); |
| 446 | |
| 447 | __ Bind(GetEntryLabel()); |
| 448 | SaveLiveRegisters(codegen, locations); |
| 449 | |
| 450 | // We may have to change the index's value, but as `index_` is a |
| 451 | // constant member (like other "inputs" of this slow path), |
| 452 | // introduce a copy of it, `index`. |
| 453 | Location index = index_; |
| 454 | if (index_.IsValid()) { |
| 455 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 456 | if (instruction_->IsArrayGet()) { |
| 457 | // Compute the actual memory offset and store it in `index`. |
| 458 | Register index_reg = index_.AsRegister<Register>(); |
| 459 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 460 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 461 | // We are about to change the value of `index_reg` (see the |
| 462 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 463 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 464 | // not been saved by the previous call to |
| 465 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 466 | // callee-save register -- |
| 467 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 468 | // callee-save registers, as it has been designed with the |
| 469 | // assumption that callee-save registers are supposed to be |
| 470 | // handled by the called function. So, as a callee-save |
| 471 | // register, `index_reg` _would_ eventually be saved onto |
| 472 | // the stack, but it would be too late: we would have |
| 473 | // changed its value earlier. Therefore, we manually save |
| 474 | // it here into another freely available register, |
| 475 | // `free_reg`, chosen of course among the caller-save |
| 476 | // registers (as a callee-save `free_reg` register would |
| 477 | // exhibit the same problem). |
| 478 | // |
| 479 | // Note we could have requested a temporary register from |
| 480 | // the register allocator instead; but we prefer not to, as |
| 481 | // this is a slow path, and we know we can find a |
| 482 | // caller-save register that is available. |
| 483 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 484 | __ Mov(free_reg, index_reg); |
| 485 | index_reg = free_reg; |
| 486 | index = Location::RegisterLocation(index_reg); |
| 487 | } else { |
| 488 | // The initial register stored in `index_` has already been |
| 489 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 490 | // (as it is not a callee-save register), so we can freely |
| 491 | // use it. |
| 492 | } |
| 493 | // Shifting the index value contained in `index_reg` by the scale |
| 494 | // factor (2) cannot overflow in practice, as the runtime is |
| 495 | // unable to allocate object arrays with a size larger than |
| 496 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 497 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 498 | static_assert( |
| 499 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 500 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 501 | __ AddConstant(index_reg, index_reg, offset_); |
| 502 | } else { |
| 503 | DCHECK(instruction_->IsInvoke()); |
| 504 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 505 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 506 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 507 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 508 | DCHECK_EQ(offset_, 0U); |
| 509 | DCHECK(index_.IsRegisterPair()); |
| 510 | // UnsafeGet's offset location is a register pair, the low |
| 511 | // part contains the correct offset. |
| 512 | index = index_.ToLow(); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | // We're moving two or three locations to locations that could |
| 517 | // overlap, so we need a parallel move resolver. |
| 518 | InvokeRuntimeCallingConvention calling_convention; |
| 519 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 520 | parallel_move.AddMove(ref_, |
| 521 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 522 | Primitive::kPrimNot, |
| 523 | nullptr); |
| 524 | parallel_move.AddMove(obj_, |
| 525 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 526 | Primitive::kPrimNot, |
| 527 | nullptr); |
| 528 | if (index.IsValid()) { |
| 529 | parallel_move.AddMove(index, |
| 530 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 531 | Primitive::kPrimInt, |
| 532 | nullptr); |
| 533 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 534 | } else { |
| 535 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 536 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 537 | } |
| 538 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 539 | instruction_, |
| 540 | instruction_->GetDexPc(), |
| 541 | this); |
| 542 | CheckEntrypointTypes< |
| 543 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 544 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 545 | |
| 546 | RestoreLiveRegisters(codegen, locations); |
| 547 | __ b(GetExitLabel()); |
| 548 | } |
| 549 | |
| 550 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 551 | |
| 552 | private: |
| 553 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 554 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 555 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 556 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 557 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 558 | return static_cast<Register>(i); |
| 559 | } |
| 560 | } |
| 561 | // We shall never fail to find a free caller-save register, as |
| 562 | // there are more than two core caller-save registers on ARM |
| 563 | // (meaning it is possible to find one which is different from |
| 564 | // `ref` and `obj`). |
| 565 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 566 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 567 | UNREACHABLE(); |
| 568 | } |
| 569 | |
| 570 | HInstruction* const instruction_; |
| 571 | const Location out_; |
| 572 | const Location ref_; |
| 573 | const Location obj_; |
| 574 | const uint32_t offset_; |
| 575 | // An additional location containing an index to an array. |
| 576 | // Only used for HArrayGet and the UnsafeGetObject & |
| 577 | // UnsafeGetObjectVolatile intrinsics. |
| 578 | const Location index_; |
| 579 | |
| 580 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 581 | }; |
| 582 | |
| 583 | // Slow path generating a read barrier for a GC root. |
| 584 | class ReadBarrierForRootSlowPathARM : public SlowPathCode { |
| 585 | public: |
| 586 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
| 587 | : instruction_(instruction), out_(out), root_(root) {} |
| 588 | |
| 589 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 590 | LocationSummary* locations = instruction_->GetLocations(); |
| 591 | Register reg_out = out_.AsRegister<Register>(); |
| 592 | DCHECK(locations->CanCall()); |
| 593 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 594 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()); |
| 595 | |
| 596 | __ Bind(GetEntryLabel()); |
| 597 | SaveLiveRegisters(codegen, locations); |
| 598 | |
| 599 | InvokeRuntimeCallingConvention calling_convention; |
| 600 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 601 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 602 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 603 | instruction_, |
| 604 | instruction_->GetDexPc(), |
| 605 | this); |
| 606 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 607 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 608 | |
| 609 | RestoreLiveRegisters(codegen, locations); |
| 610 | __ b(GetExitLabel()); |
| 611 | } |
| 612 | |
| 613 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 614 | |
| 615 | private: |
| 616 | HInstruction* const instruction_; |
| 617 | const Location out_; |
| 618 | const Location root_; |
| 619 | |
| 620 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 621 | }; |
| 622 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 623 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 624 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 625 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 626 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 627 | switch (cond) { |
| 628 | case kCondEQ: return EQ; |
| 629 | case kCondNE: return NE; |
| 630 | case kCondLT: return LT; |
| 631 | case kCondLE: return LE; |
| 632 | case kCondGT: return GT; |
| 633 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 634 | case kCondB: return LO; |
| 635 | case kCondBE: return LS; |
| 636 | case kCondA: return HI; |
| 637 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 638 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 639 | LOG(FATAL) << "Unreachable"; |
| 640 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 643 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 644 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 645 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 646 | case kCondEQ: return EQ; |
| 647 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 648 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 649 | case kCondLT: return LO; |
| 650 | case kCondLE: return LS; |
| 651 | case kCondGT: return HI; |
| 652 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 653 | // Unsigned remain unchanged. |
| 654 | case kCondB: return LO; |
| 655 | case kCondBE: return LS; |
| 656 | case kCondA: return HI; |
| 657 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 658 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 659 | LOG(FATAL) << "Unreachable"; |
| 660 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 663 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 664 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 668 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 669 | } |
| 670 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 671 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 672 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 673 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 674 | } |
| 675 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 676 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 677 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 678 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 681 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 682 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 683 | return kArmWordSize; |
| 684 | } |
| 685 | |
| 686 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 687 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 688 | return kArmWordSize; |
| 689 | } |
| 690 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 691 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 692 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 693 | const CompilerOptions& compiler_options, |
| 694 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 695 | : CodeGenerator(graph, |
| 696 | kNumberOfCoreRegisters, |
| 697 | kNumberOfSRegisters, |
| 698 | kNumberOfRegisterPairs, |
| 699 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 700 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 701 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 702 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 703 | compiler_options, |
| 704 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 705 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 706 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 707 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 708 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 709 | assembler_(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 710 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 711 | method_patches_(MethodReferenceComparator(), |
| 712 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 713 | call_patches_(MethodReferenceComparator(), |
| 714 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 715 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 716 | // Always save the LR register to mimic Quick. |
| 717 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 718 | } |
| 719 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 720 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 721 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 722 | __ FinalizeCode(); |
| 723 | |
| 724 | // Adjust native pc offsets in stack maps. |
| 725 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 726 | uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset; |
| 727 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 728 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 729 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 730 | // Adjust pc offsets for the disassembly information. |
| 731 | if (disasm_info_ != nullptr) { |
| 732 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 733 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 734 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 735 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 736 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 737 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 738 | } |
| 739 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 740 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 741 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 742 | } |
| 743 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 744 | |
| 745 | CodeGenerator::Finalize(allocator); |
| 746 | } |
| 747 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 748 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 749 | switch (type) { |
| 750 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 751 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 752 | ArmManagedRegister pair = |
| 753 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 754 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 755 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 756 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 757 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 758 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 759 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 760 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | case Primitive::kPrimByte: |
| 764 | case Primitive::kPrimBoolean: |
| 765 | case Primitive::kPrimChar: |
| 766 | case Primitive::kPrimShort: |
| 767 | case Primitive::kPrimInt: |
| 768 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 769 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 770 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 771 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 772 | ArmManagedRegister current = |
| 773 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 774 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 775 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 776 | } |
| 777 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 778 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 781 | case Primitive::kPrimFloat: { |
| 782 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 783 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 784 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 785 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 786 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 787 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 788 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 789 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 790 | } |
| 791 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 792 | case Primitive::kPrimVoid: |
| 793 | LOG(FATAL) << "Unreachable type " << type; |
| 794 | } |
| 795 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 796 | return Location::NoLocation(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Nicolas Geoffray | a0bb2bd | 2015-01-26 12:49:35 +0000 | [diff] [blame] | 799 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 800 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 801 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 802 | |
| 803 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 804 | blocked_core_registers_[SP] = true; |
| 805 | blocked_core_registers_[LR] = true; |
| 806 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 807 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 808 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 809 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 810 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 811 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 812 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 813 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 814 | if (is_baseline) { |
| 815 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 816 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 817 | } |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 818 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 819 | blocked_core_registers_[kCoreSavedRegisterForBaseline] = false; |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 820 | } |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 821 | |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 822 | if (is_baseline || GetGraph()->IsDebuggable()) { |
| 823 | // Stubs do not save callee-save floating point registers. If the graph |
| 824 | // is debuggable, we need to deal with these registers differently. For |
| 825 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 826 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 827 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 828 | } |
| 829 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 830 | |
| 831 | UpdateBlockedPairRegisters(); |
| 832 | } |
| 833 | |
| 834 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 835 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 836 | ArmManagedRegister current = |
| 837 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 838 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 839 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 840 | blocked_register_pairs_[i] = true; |
| 841 | } |
| 842 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 843 | } |
| 844 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 845 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 846 | : HGraphVisitor(graph), |
| 847 | assembler_(codegen->GetAssembler()), |
| 848 | codegen_(codegen) {} |
| 849 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 850 | void CodeGeneratorARM::ComputeSpillMask() { |
| 851 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 852 | // Save one extra register for baseline. Note that on thumb2, there is no easy |
| 853 | // instruction to restore just the PC, so this actually helps both baseline |
| 854 | // and non-baseline to save and restore at least two registers at entry and exit. |
| 855 | core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 856 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 857 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 858 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 859 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 860 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 861 | // but in the range. |
| 862 | if (fpu_spill_mask_ != 0) { |
| 863 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 864 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 865 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 866 | fpu_spill_mask_ |= (1 << i); |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 871 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 872 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 876 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 879 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 880 | bool skip_overflow_check = |
| 881 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 882 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 883 | __ Bind(&frame_entry_label_); |
| 884 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 885 | if (HasEmptyFrame()) { |
| 886 | return; |
| 887 | } |
| 888 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 889 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 890 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 891 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 892 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 893 | } |
| 894 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 895 | __ PushList(core_spill_mask_); |
| 896 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 897 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 898 | if (fpu_spill_mask_ != 0) { |
| 899 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 900 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 901 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 902 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 903 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 904 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 905 | __ AddConstant(SP, -adjust); |
| 906 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 907 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 911 | if (HasEmptyFrame()) { |
| 912 | __ bx(LR); |
| 913 | return; |
| 914 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 915 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 916 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 917 | __ AddConstant(SP, adjust); |
| 918 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 919 | if (fpu_spill_mask_ != 0) { |
| 920 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 921 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 922 | __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_)); |
| 923 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 924 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 925 | // Pop LR into PC to return. |
| 926 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 927 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 928 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 929 | __ cfi().RestoreState(); |
| 930 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 933 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 934 | Label* label = GetLabelOf(block); |
| 935 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 938 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 939 | switch (load->GetType()) { |
| 940 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 941 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 942 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 943 | |
| 944 | case Primitive::kPrimInt: |
| 945 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 946 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 947 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 948 | |
| 949 | case Primitive::kPrimBoolean: |
| 950 | case Primitive::kPrimByte: |
| 951 | case Primitive::kPrimChar: |
| 952 | case Primitive::kPrimShort: |
| 953 | case Primitive::kPrimVoid: |
| 954 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 955 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 959 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 960 | } |
| 961 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 962 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 963 | switch (type) { |
| 964 | case Primitive::kPrimBoolean: |
| 965 | case Primitive::kPrimByte: |
| 966 | case Primitive::kPrimChar: |
| 967 | case Primitive::kPrimShort: |
| 968 | case Primitive::kPrimInt: |
| 969 | case Primitive::kPrimNot: { |
| 970 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 971 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 972 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 973 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 974 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 975 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 976 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 977 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 978 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 979 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 980 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 981 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 982 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 983 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 984 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 985 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 986 | // Skip R1, and use R2_R3 instead. |
| 987 | gp_index_++; |
| 988 | index++; |
| 989 | } |
| 990 | } |
| 991 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 992 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 993 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 994 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 995 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 996 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 997 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 998 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | case Primitive::kPrimFloat: { |
| 1003 | uint32_t stack_index = stack_index_++; |
| 1004 | if (float_index_ % 2 == 0) { |
| 1005 | float_index_ = std::max(double_index_, float_index_); |
| 1006 | } |
| 1007 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1008 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1009 | } else { |
| 1010 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | case Primitive::kPrimDouble: { |
| 1015 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1016 | uint32_t stack_index = stack_index_; |
| 1017 | stack_index_ += 2; |
| 1018 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1019 | uint32_t index = double_index_; |
| 1020 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1021 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1022 | calling_convention.GetFpuRegisterAt(index), |
| 1023 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1024 | DCHECK(ExpectedPairLayout(result)); |
| 1025 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1026 | } else { |
| 1027 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1031 | case Primitive::kPrimVoid: |
| 1032 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1033 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1034 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1035 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1036 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1037 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1038 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1039 | switch (type) { |
| 1040 | case Primitive::kPrimBoolean: |
| 1041 | case Primitive::kPrimByte: |
| 1042 | case Primitive::kPrimChar: |
| 1043 | case Primitive::kPrimShort: |
| 1044 | case Primitive::kPrimInt: |
| 1045 | case Primitive::kPrimNot: { |
| 1046 | return Location::RegisterLocation(R0); |
| 1047 | } |
| 1048 | |
| 1049 | case Primitive::kPrimFloat: { |
| 1050 | return Location::FpuRegisterLocation(S0); |
| 1051 | } |
| 1052 | |
| 1053 | case Primitive::kPrimLong: { |
| 1054 | return Location::RegisterPairLocation(R0, R1); |
| 1055 | } |
| 1056 | |
| 1057 | case Primitive::kPrimDouble: { |
| 1058 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1059 | } |
| 1060 | |
| 1061 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1062 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1063 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1064 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1065 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1068 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1069 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1070 | } |
| 1071 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1072 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1073 | if (source.Equals(destination)) { |
| 1074 | return; |
| 1075 | } |
| 1076 | if (destination.IsRegister()) { |
| 1077 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1078 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1079 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1080 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1081 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1082 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1083 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1084 | } else if (destination.IsFpuRegister()) { |
| 1085 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1086 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1087 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1088 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1089 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1090 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1091 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1092 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1093 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1094 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1095 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1096 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1097 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1098 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1099 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1100 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1101 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1107 | if (source.Equals(destination)) { |
| 1108 | return; |
| 1109 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1110 | if (destination.IsRegisterPair()) { |
| 1111 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1112 | EmitParallelMoves( |
| 1113 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1114 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1115 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1116 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1117 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1118 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1119 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1120 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1121 | } else if (source.IsFpuRegisterPair()) { |
| 1122 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1123 | destination.AsRegisterPairHigh<Register>(), |
| 1124 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1125 | } else { |
| 1126 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1127 | DCHECK(ExpectedPairLayout(destination)); |
| 1128 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1129 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1130 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1131 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1132 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1133 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1134 | SP, |
| 1135 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1136 | } else if (source.IsRegisterPair()) { |
| 1137 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1138 | source.AsRegisterPairLow<Register>(), |
| 1139 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1140 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1141 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1142 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1143 | } else { |
| 1144 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1145 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1146 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1147 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1148 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1149 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1150 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1151 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1152 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1153 | SP, destination.GetStackIndex()); |
| 1154 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1155 | } else if (source.IsFpuRegisterPair()) { |
| 1156 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1157 | SP, |
| 1158 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1159 | } else { |
| 1160 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1161 | EmitParallelMoves( |
| 1162 | Location::StackSlot(source.GetStackIndex()), |
| 1163 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1164 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1165 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1166 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1167 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1172 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1173 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1174 | if (instruction->IsCurrentMethod()) { |
| 1175 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1176 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1177 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1178 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1179 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1180 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1181 | int32_t value = GetInt32ValueOf(const_to_move); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1182 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1183 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1184 | } else { |
| 1185 | DCHECK(location.IsStackSlot()); |
| 1186 | __ LoadImmediate(IP, value); |
| 1187 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 1188 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1189 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 1190 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1191 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1192 | if (location.IsRegisterPair()) { |
| 1193 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 1194 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 1195 | } else { |
| 1196 | DCHECK(location.IsDoubleStackSlot()); |
| 1197 | __ LoadImmediate(IP, Low32Bits(value)); |
| 1198 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 1199 | __ LoadImmediate(IP, High32Bits(value)); |
| 1200 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 1201 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1202 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1203 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1204 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 1205 | switch (instruction->GetType()) { |
| 1206 | case Primitive::kPrimBoolean: |
| 1207 | case Primitive::kPrimByte: |
| 1208 | case Primitive::kPrimChar: |
| 1209 | case Primitive::kPrimShort: |
| 1210 | case Primitive::kPrimInt: |
| 1211 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1212 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | Move32(location, Location::StackSlot(stack_slot)); |
| 1214 | break; |
| 1215 | |
| 1216 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1217 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1218 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 1219 | break; |
| 1220 | |
| 1221 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1222 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1224 | } else if (instruction->IsTemporary()) { |
| 1225 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1226 | if (temp_location.IsStackSlot()) { |
| 1227 | Move32(location, temp_location); |
| 1228 | } else { |
| 1229 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1230 | Move64(location, temp_location); |
| 1231 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1232 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1233 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1234 | switch (instruction->GetType()) { |
| 1235 | case Primitive::kPrimBoolean: |
| 1236 | case Primitive::kPrimByte: |
| 1237 | case Primitive::kPrimChar: |
| 1238 | case Primitive::kPrimShort: |
| 1239 | case Primitive::kPrimNot: |
| 1240 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1241 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1242 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1243 | break; |
| 1244 | |
| 1245 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1246 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1247 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | break; |
| 1249 | |
| 1250 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1251 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1252 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1256 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1257 | DCHECK(location.IsRegister()); |
| 1258 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1259 | } |
| 1260 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1261 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1262 | if (Primitive::Is64BitType(dst_type)) { |
| 1263 | Move64(dst, src); |
| 1264 | } else { |
| 1265 | Move32(dst, src); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1270 | if (location.IsRegister()) { |
| 1271 | locations->AddTemp(location); |
| 1272 | } else if (location.IsRegisterPair()) { |
| 1273 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1274 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1275 | } else { |
| 1276 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1277 | } |
| 1278 | } |
| 1279 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1280 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1281 | HInstruction* instruction, |
| 1282 | uint32_t dex_pc, |
| 1283 | SlowPathCode* slow_path) { |
| 1284 | InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(), |
| 1285 | instruction, |
| 1286 | dex_pc, |
| 1287 | slow_path); |
| 1288 | } |
| 1289 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1290 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 1291 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1292 | uint32_t dex_pc, |
| 1293 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1294 | ValidateInvokeRuntime(instruction, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1295 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1296 | __ blx(LR); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1297 | RecordPcInfo(instruction, dex_pc, slow_path); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1300 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1301 | DCHECK(!successor->IsExitBlock()); |
| 1302 | |
| 1303 | HBasicBlock* block = got->GetBlock(); |
| 1304 | HInstruction* previous = got->GetPrevious(); |
| 1305 | |
| 1306 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1307 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1308 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1309 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1314 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1315 | } |
| 1316 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1317 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1321 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1322 | got->SetLocations(nullptr); |
| 1323 | } |
| 1324 | |
| 1325 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1326 | HandleGoto(got, got->GetSuccessor()); |
| 1327 | } |
| 1328 | |
| 1329 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1330 | try_boundary->SetLocations(nullptr); |
| 1331 | } |
| 1332 | |
| 1333 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1334 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1335 | if (!successor->IsExitBlock()) { |
| 1336 | HandleGoto(try_boundary, successor); |
| 1337 | } |
| 1338 | } |
| 1339 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1340 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1341 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1344 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1347 | void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) { |
| 1348 | ShifterOperand operand; |
| 1349 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) { |
| 1350 | __ cmp(left, operand); |
| 1351 | } else { |
| 1352 | Register temp = IP; |
| 1353 | __ LoadImmediate(temp, right); |
| 1354 | __ cmp(left, ShifterOperand(temp)); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1359 | Label* true_label, |
| 1360 | Label* false_label) { |
| 1361 | __ vmstat(); // transfer FP status register to ARM APSR. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1362 | // TODO: merge into a single branch (except "equal or unordered" and "not equal") |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1363 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1364 | __ b(true_label, VS); // VS for unordered. |
| 1365 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1366 | __ b(false_label, VS); // VS for unordered. |
| 1367 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1368 | __ b(true_label, ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1372 | Label* true_label, |
| 1373 | Label* false_label) { |
| 1374 | LocationSummary* locations = cond->GetLocations(); |
| 1375 | Location left = locations->InAt(0); |
| 1376 | Location right = locations->InAt(1); |
| 1377 | IfCondition if_cond = cond->GetCondition(); |
| 1378 | |
| 1379 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1380 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1381 | IfCondition true_high_cond = if_cond; |
| 1382 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1383 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1384 | |
| 1385 | // Set the conditions for the test, remembering that == needs to be |
| 1386 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1387 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1388 | switch (if_cond) { |
| 1389 | case kCondEQ: |
| 1390 | case kCondNE: |
| 1391 | // Nothing to do. |
| 1392 | break; |
| 1393 | case kCondLT: |
| 1394 | false_high_cond = kCondGT; |
| 1395 | break; |
| 1396 | case kCondLE: |
| 1397 | true_high_cond = kCondLT; |
| 1398 | break; |
| 1399 | case kCondGT: |
| 1400 | false_high_cond = kCondLT; |
| 1401 | break; |
| 1402 | case kCondGE: |
| 1403 | true_high_cond = kCondGT; |
| 1404 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1405 | case kCondB: |
| 1406 | false_high_cond = kCondA; |
| 1407 | break; |
| 1408 | case kCondBE: |
| 1409 | true_high_cond = kCondB; |
| 1410 | break; |
| 1411 | case kCondA: |
| 1412 | false_high_cond = kCondB; |
| 1413 | break; |
| 1414 | case kCondAE: |
| 1415 | true_high_cond = kCondA; |
| 1416 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1417 | } |
| 1418 | if (right.IsConstant()) { |
| 1419 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1420 | int32_t val_low = Low32Bits(value); |
| 1421 | int32_t val_high = High32Bits(value); |
| 1422 | |
| 1423 | GenerateCompareWithImmediate(left_high, val_high); |
| 1424 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1425 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1426 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1427 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1428 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1429 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1430 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1431 | } |
| 1432 | // Must be equal high, so compare the lows. |
| 1433 | GenerateCompareWithImmediate(left_low, val_low); |
| 1434 | } else { |
| 1435 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1436 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1437 | |
| 1438 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1439 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1440 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1441 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1442 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1443 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1444 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1445 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1446 | } |
| 1447 | // Must be equal high, so compare the lows. |
| 1448 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1449 | } |
| 1450 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1451 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1452 | __ b(true_label, final_condition); |
| 1453 | } |
| 1454 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1455 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1456 | Label* true_target_in, |
| 1457 | Label* false_target_in) { |
| 1458 | // Generated branching requires both targets to be explicit. If either of the |
| 1459 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1460 | Label fallthrough_target; |
| 1461 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1462 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1463 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1464 | LocationSummary* locations = condition->GetLocations(); |
| 1465 | Location left = locations->InAt(0); |
| 1466 | Location right = locations->InAt(1); |
| 1467 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1468 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1469 | switch (type) { |
| 1470 | case Primitive::kPrimLong: |
| 1471 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1472 | break; |
| 1473 | case Primitive::kPrimFloat: |
| 1474 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1475 | GenerateFPJumps(condition, true_target, false_target); |
| 1476 | break; |
| 1477 | case Primitive::kPrimDouble: |
| 1478 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1479 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1480 | GenerateFPJumps(condition, true_target, false_target); |
| 1481 | break; |
| 1482 | default: |
| 1483 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1484 | } |
| 1485 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1486 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1487 | __ b(false_target); |
| 1488 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1489 | |
| 1490 | if (fallthrough_target.IsLinked()) { |
| 1491 | __ Bind(&fallthrough_target); |
| 1492 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1493 | } |
| 1494 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1495 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1496 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1497 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1498 | Label* false_target) { |
| 1499 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1500 | |
| 1501 | if (true_target == nullptr && false_target == nullptr) { |
| 1502 | // Nothing to do. The code always falls through. |
| 1503 | return; |
| 1504 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1505 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1506 | if (cond->AsIntConstant()->IsOne()) { |
| 1507 | if (true_target != nullptr) { |
| 1508 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1509 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1510 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1511 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1512 | if (false_target != nullptr) { |
| 1513 | __ b(false_target); |
| 1514 | } |
| 1515 | } |
| 1516 | return; |
| 1517 | } |
| 1518 | |
| 1519 | // The following code generates these patterns: |
| 1520 | // (1) true_target == nullptr && false_target != nullptr |
| 1521 | // - opposite condition true => branch to false_target |
| 1522 | // (2) true_target != nullptr && false_target == nullptr |
| 1523 | // - condition true => branch to true_target |
| 1524 | // (3) true_target != nullptr && false_target != nullptr |
| 1525 | // - condition true => branch to true_target |
| 1526 | // - branch to false_target |
| 1527 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1528 | // Condition has been materialized, compare the output to 0. |
| 1529 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1530 | DCHECK(cond_val.IsRegister()); |
| 1531 | if (true_target == nullptr) { |
| 1532 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1533 | } else { |
| 1534 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1535 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1536 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1537 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1538 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1539 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1540 | |
| 1541 | // If this is a long or FP comparison that has been folded into |
| 1542 | // the HCondition, generate the comparison directly. |
| 1543 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1544 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1545 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1546 | return; |
| 1547 | } |
| 1548 | |
| 1549 | LocationSummary* locations = cond->GetLocations(); |
| 1550 | DCHECK(locations->InAt(0).IsRegister()); |
| 1551 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1552 | Location right = locations->InAt(1); |
| 1553 | if (right.IsRegister()) { |
| 1554 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1555 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1556 | DCHECK(right.IsConstant()); |
| 1557 | GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1558 | } |
| 1559 | if (true_target == nullptr) { |
| 1560 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1561 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1562 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1563 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1564 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1565 | |
| 1566 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1567 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1568 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1569 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1573 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1574 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1575 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1576 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1581 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1582 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1583 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1584 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1585 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1586 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1587 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1591 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1592 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1593 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1594 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1599 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DeoptimizationSlowPathARM(deoptimize); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1600 | codegen_->AddSlowPath(slow_path); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1601 | GenerateTestAndBranch(deoptimize, |
| 1602 | /* condition_input_index */ 0, |
| 1603 | slow_path->GetEntryLabel(), |
| 1604 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1605 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1606 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1607 | void LocationsBuilderARM::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1608 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1609 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1610 | // Handle the long/FP comparisons made in instruction simplification. |
| 1611 | switch (cond->InputAt(0)->GetType()) { |
| 1612 | case Primitive::kPrimLong: |
| 1613 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1614 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1615 | if (cond->NeedsMaterialization()) { |
| 1616 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1617 | } |
| 1618 | break; |
| 1619 | |
| 1620 | case Primitive::kPrimFloat: |
| 1621 | case Primitive::kPrimDouble: |
| 1622 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1623 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1624 | if (cond->NeedsMaterialization()) { |
| 1625 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1626 | } |
| 1627 | break; |
| 1628 | |
| 1629 | default: |
| 1630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1631 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1632 | if (cond->NeedsMaterialization()) { |
| 1633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1634 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1635 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1638 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1639 | if (!cond->NeedsMaterialization()) { |
| 1640 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1641 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1642 | |
| 1643 | LocationSummary* locations = cond->GetLocations(); |
| 1644 | Location left = locations->InAt(0); |
| 1645 | Location right = locations->InAt(1); |
| 1646 | Register out = locations->Out().AsRegister<Register>(); |
| 1647 | Label true_label, false_label; |
| 1648 | |
| 1649 | switch (cond->InputAt(0)->GetType()) { |
| 1650 | default: { |
| 1651 | // Integer case. |
| 1652 | if (right.IsRegister()) { |
| 1653 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 1654 | } else { |
| 1655 | DCHECK(right.IsConstant()); |
| 1656 | GenerateCompareWithImmediate(left.AsRegister<Register>(), |
| 1657 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1658 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1659 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1660 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1661 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1662 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1663 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1664 | return; |
| 1665 | } |
| 1666 | case Primitive::kPrimLong: |
| 1667 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1668 | break; |
| 1669 | case Primitive::kPrimFloat: |
| 1670 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
| 1671 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1672 | break; |
| 1673 | case Primitive::kPrimDouble: |
| 1674 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 1675 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 1676 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1677 | break; |
| 1678 | } |
| 1679 | |
| 1680 | // Convert the jumps into the result. |
| 1681 | Label done_label; |
| 1682 | |
| 1683 | // False case: result = 0. |
| 1684 | __ Bind(&false_label); |
| 1685 | __ LoadImmediate(out, 0); |
| 1686 | __ b(&done_label); |
| 1687 | |
| 1688 | // True case: result = 1. |
| 1689 | __ Bind(&true_label); |
| 1690 | __ LoadImmediate(out, 1); |
| 1691 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 1695 | VisitCondition(comp); |
| 1696 | } |
| 1697 | |
| 1698 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 1699 | VisitCondition(comp); |
| 1700 | } |
| 1701 | |
| 1702 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 1703 | VisitCondition(comp); |
| 1704 | } |
| 1705 | |
| 1706 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1707 | VisitCondition(comp); |
| 1708 | } |
| 1709 | |
| 1710 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1711 | VisitCondition(comp); |
| 1712 | } |
| 1713 | |
| 1714 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1715 | VisitCondition(comp); |
| 1716 | } |
| 1717 | |
| 1718 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1719 | VisitCondition(comp); |
| 1720 | } |
| 1721 | |
| 1722 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1723 | VisitCondition(comp); |
| 1724 | } |
| 1725 | |
| 1726 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1727 | VisitCondition(comp); |
| 1728 | } |
| 1729 | |
| 1730 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1731 | VisitCondition(comp); |
| 1732 | } |
| 1733 | |
| 1734 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1735 | VisitCondition(comp); |
| 1736 | } |
| 1737 | |
| 1738 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1739 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1742 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
| 1743 | VisitCondition(comp); |
| 1744 | } |
| 1745 | |
| 1746 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
| 1747 | VisitCondition(comp); |
| 1748 | } |
| 1749 | |
| 1750 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1751 | VisitCondition(comp); |
| 1752 | } |
| 1753 | |
| 1754 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1755 | VisitCondition(comp); |
| 1756 | } |
| 1757 | |
| 1758 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
| 1759 | VisitCondition(comp); |
| 1760 | } |
| 1761 | |
| 1762 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
| 1763 | VisitCondition(comp); |
| 1764 | } |
| 1765 | |
| 1766 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1767 | VisitCondition(comp); |
| 1768 | } |
| 1769 | |
| 1770 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1771 | VisitCondition(comp); |
| 1772 | } |
| 1773 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1774 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1775 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1778 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1779 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1782 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1783 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1786 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1787 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1791 | LocationSummary* locations = |
| 1792 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1793 | switch (store->InputAt(1)->GetType()) { |
| 1794 | case Primitive::kPrimBoolean: |
| 1795 | case Primitive::kPrimByte: |
| 1796 | case Primitive::kPrimChar: |
| 1797 | case Primitive::kPrimShort: |
| 1798 | case Primitive::kPrimInt: |
| 1799 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1800 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1801 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1802 | break; |
| 1803 | |
| 1804 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1805 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1806 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1807 | break; |
| 1808 | |
| 1809 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1810 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1811 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1814 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1818 | LocationSummary* locations = |
| 1819 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1820 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1823 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1824 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1827 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 1828 | LocationSummary* locations = |
| 1829 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1830 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1831 | } |
| 1832 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1833 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1834 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1837 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1838 | LocationSummary* locations = |
| 1839 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1840 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1841 | } |
| 1842 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1843 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1844 | // Will be generated at use site. |
| 1845 | } |
| 1846 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1847 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1848 | LocationSummary* locations = |
| 1849 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1850 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1851 | } |
| 1852 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1853 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1854 | // Will be generated at use site. |
| 1855 | } |
| 1856 | |
| 1857 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1858 | LocationSummary* locations = |
| 1859 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1860 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1861 | } |
| 1862 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1863 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1864 | // Will be generated at use site. |
| 1865 | } |
| 1866 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1867 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1868 | memory_barrier->SetLocations(nullptr); |
| 1869 | } |
| 1870 | |
| 1871 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1872 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1873 | } |
| 1874 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1875 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1876 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1879 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1880 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1883 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1884 | LocationSummary* locations = |
| 1885 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1886 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1889 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1890 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1893 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1894 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1895 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1896 | // the method_idx. |
| 1897 | HandleInvoke(invoke); |
| 1898 | } |
| 1899 | |
| 1900 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1901 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1902 | } |
| 1903 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1904 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1905 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1906 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1907 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1908 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1909 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1910 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1911 | codegen_->GetInstructionSetFeatures()); |
| 1912 | if (intrinsic.TryDispatch(invoke)) { |
| 1913 | return; |
| 1914 | } |
| 1915 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1916 | HandleInvoke(invoke); |
| 1917 | } |
| 1918 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1919 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 1920 | if (invoke->GetLocations()->Intrinsified()) { |
| 1921 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 1922 | intrinsic.Dispatch(invoke); |
| 1923 | return true; |
| 1924 | } |
| 1925 | return false; |
| 1926 | } |
| 1927 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1928 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1929 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1930 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1931 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1932 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1933 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1934 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1935 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1936 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1937 | LocationSummary* locations = invoke->GetLocations(); |
| 1938 | codegen_->GenerateStaticOrDirectCall( |
| 1939 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1940 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1941 | } |
| 1942 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1943 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1944 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1945 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1948 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1949 | IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(), |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1950 | codegen_->GetAssembler(), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1951 | codegen_->GetInstructionSetFeatures()); |
| 1952 | if (intrinsic.TryDispatch(invoke)) { |
| 1953 | return; |
| 1954 | } |
| 1955 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1956 | HandleInvoke(invoke); |
| 1957 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1958 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1959 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1960 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1961 | return; |
| 1962 | } |
| 1963 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1964 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1965 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1966 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1969 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1970 | HandleInvoke(invoke); |
| 1971 | // Add the hidden argument. |
| 1972 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1973 | } |
| 1974 | |
| 1975 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1976 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1977 | LocationSummary* locations = invoke->GetLocations(); |
| 1978 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1979 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1980 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1981 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1982 | Location receiver = locations->InAt(0); |
| 1983 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1984 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1985 | // Set the hidden argument. This is safe to do this here, as R12 |
| 1986 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 1987 | DCHECK_EQ(R12, hidden_reg); |
| 1988 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1989 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1990 | if (receiver.IsStackSlot()) { |
| 1991 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1992 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1993 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1994 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1995 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1996 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1997 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1998 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1999 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2000 | // emit a read barrier for the previous class reference load. |
| 2001 | // However this is not required in practice, as this is an |
| 2002 | // intermediate/temporary reference and because the current |
| 2003 | // concurrent copying collector keeps the from-space memory |
| 2004 | // intact/accessible until the end of the marking phase (the |
| 2005 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2006 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2007 | // temp = temp->GetImtEntryAt(method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2008 | uint32_t entry_point = |
| 2009 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2010 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 2011 | // LR = temp->GetEntryPoint(); |
| 2012 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2013 | // LR(); |
| 2014 | __ blx(LR); |
| 2015 | DCHECK(!codegen_->IsLeafMethod()); |
| 2016 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2017 | } |
| 2018 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2019 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2020 | LocationSummary* locations = |
| 2021 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2022 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2023 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2024 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2025 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2026 | break; |
| 2027 | } |
| 2028 | case Primitive::kPrimLong: { |
| 2029 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2030 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2031 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2032 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2033 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2034 | case Primitive::kPrimFloat: |
| 2035 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2036 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2037 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2038 | break; |
| 2039 | |
| 2040 | default: |
| 2041 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2046 | LocationSummary* locations = neg->GetLocations(); |
| 2047 | Location out = locations->Out(); |
| 2048 | Location in = locations->InAt(0); |
| 2049 | switch (neg->GetResultType()) { |
| 2050 | case Primitive::kPrimInt: |
| 2051 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2052 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2053 | break; |
| 2054 | |
| 2055 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2056 | DCHECK(in.IsRegisterPair()); |
| 2057 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2058 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2059 | in.AsRegisterPairLow<Register>(), |
| 2060 | ShifterOperand(0)); |
| 2061 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2062 | // instruction here, as it does not exist in the Thumb-2 |
| 2063 | // instruction set. We use the following approach |
| 2064 | // using SBC and SUB instead. |
| 2065 | // |
| 2066 | // out.hi = -C |
| 2067 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2068 | out.AsRegisterPairHigh<Register>(), |
| 2069 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2070 | // out.hi = out.hi - in.hi |
| 2071 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2072 | out.AsRegisterPairHigh<Register>(), |
| 2073 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2074 | break; |
| 2075 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2076 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2077 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2078 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2079 | break; |
| 2080 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2081 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2082 | DCHECK(in.IsFpuRegisterPair()); |
| 2083 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2084 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2085 | break; |
| 2086 | |
| 2087 | default: |
| 2088 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2089 | } |
| 2090 | } |
| 2091 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2092 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2093 | Primitive::Type result_type = conversion->GetResultType(); |
| 2094 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2095 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2096 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2097 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2098 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2099 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2100 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2101 | && result_type == Primitive::kPrimLong) |
| 2102 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2103 | ? LocationSummary::kCall |
| 2104 | : LocationSummary::kNoCall; |
| 2105 | LocationSummary* locations = |
| 2106 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2107 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2108 | // The Java language does not allow treating boolean as an integral type but |
| 2109 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2110 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2111 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimByte: |
| 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 | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2116 | case Primitive::kPrimShort: |
| 2117 | case Primitive::kPrimInt: |
| 2118 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2119 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2120 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2121 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2122 | break; |
| 2123 | |
| 2124 | default: |
| 2125 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2126 | << " to " << result_type; |
| 2127 | } |
| 2128 | break; |
| 2129 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2130 | case Primitive::kPrimShort: |
| 2131 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2132 | case Primitive::kPrimBoolean: |
| 2133 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2134 | case Primitive::kPrimByte: |
| 2135 | case Primitive::kPrimInt: |
| 2136 | case Primitive::kPrimChar: |
| 2137 | // Processing a Dex `int-to-short' instruction. |
| 2138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2139 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2140 | break; |
| 2141 | |
| 2142 | default: |
| 2143 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2144 | << " to " << result_type; |
| 2145 | } |
| 2146 | break; |
| 2147 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2148 | case Primitive::kPrimInt: |
| 2149 | switch (input_type) { |
| 2150 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2151 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2152 | locations->SetInAt(0, Location::Any()); |
| 2153 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2154 | break; |
| 2155 | |
| 2156 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2157 | // Processing a Dex `float-to-int' instruction. |
| 2158 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2159 | locations->SetOut(Location::RequiresRegister()); |
| 2160 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2161 | break; |
| 2162 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2163 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2164 | // Processing a Dex `double-to-int' instruction. |
| 2165 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2166 | locations->SetOut(Location::RequiresRegister()); |
| 2167 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2168 | break; |
| 2169 | |
| 2170 | default: |
| 2171 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2172 | << " to " << result_type; |
| 2173 | } |
| 2174 | break; |
| 2175 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2176 | case Primitive::kPrimLong: |
| 2177 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimBoolean: |
| 2179 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimByte: |
| 2181 | case Primitive::kPrimShort: |
| 2182 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2183 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2184 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2185 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2186 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2187 | break; |
| 2188 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2189 | case Primitive::kPrimFloat: { |
| 2190 | // Processing a Dex `float-to-long' instruction. |
| 2191 | InvokeRuntimeCallingConvention calling_convention; |
| 2192 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2193 | calling_convention.GetFpuRegisterAt(0))); |
| 2194 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2195 | break; |
| 2196 | } |
| 2197 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2198 | case Primitive::kPrimDouble: { |
| 2199 | // Processing a Dex `double-to-long' instruction. |
| 2200 | InvokeRuntimeCallingConvention calling_convention; |
| 2201 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2202 | calling_convention.GetFpuRegisterAt(0), |
| 2203 | calling_convention.GetFpuRegisterAt(1))); |
| 2204 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2205 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2206 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2207 | |
| 2208 | default: |
| 2209 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2210 | << " to " << result_type; |
| 2211 | } |
| 2212 | break; |
| 2213 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2214 | case Primitive::kPrimChar: |
| 2215 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2216 | case Primitive::kPrimBoolean: |
| 2217 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2218 | case Primitive::kPrimByte: |
| 2219 | case Primitive::kPrimShort: |
| 2220 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2221 | // Processing a Dex `int-to-char' instruction. |
| 2222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2223 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2224 | break; |
| 2225 | |
| 2226 | default: |
| 2227 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2228 | << " to " << result_type; |
| 2229 | } |
| 2230 | break; |
| 2231 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2233 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimBoolean: |
| 2235 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2236 | case Primitive::kPrimByte: |
| 2237 | case Primitive::kPrimShort: |
| 2238 | case Primitive::kPrimInt: |
| 2239 | case Primitive::kPrimChar: |
| 2240 | // Processing a Dex `int-to-float' instruction. |
| 2241 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2242 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2243 | break; |
| 2244 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2245 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2246 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2247 | InvokeRuntimeCallingConvention calling_convention; |
| 2248 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2249 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2250 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2251 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2252 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2253 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2254 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2255 | // Processing a Dex `double-to-float' instruction. |
| 2256 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2257 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2258 | break; |
| 2259 | |
| 2260 | default: |
| 2261 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2262 | << " to " << result_type; |
| 2263 | }; |
| 2264 | break; |
| 2265 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2267 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimBoolean: |
| 2269 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimByte: |
| 2271 | case Primitive::kPrimShort: |
| 2272 | case Primitive::kPrimInt: |
| 2273 | case Primitive::kPrimChar: |
| 2274 | // Processing a Dex `int-to-double' instruction. |
| 2275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2276 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2277 | break; |
| 2278 | |
| 2279 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2280 | // Processing a Dex `long-to-double' instruction. |
| 2281 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2282 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2283 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2284 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2285 | break; |
| 2286 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2287 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2288 | // Processing a Dex `float-to-double' instruction. |
| 2289 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2290 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | |
| 2293 | default: |
| 2294 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2295 | << " to " << result_type; |
| 2296 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | |
| 2299 | default: |
| 2300 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2301 | << " to " << result_type; |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2306 | LocationSummary* locations = conversion->GetLocations(); |
| 2307 | Location out = locations->Out(); |
| 2308 | Location in = locations->InAt(0); |
| 2309 | Primitive::Type result_type = conversion->GetResultType(); |
| 2310 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2311 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2312 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2313 | case Primitive::kPrimByte: |
| 2314 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2315 | case Primitive::kPrimBoolean: |
| 2316 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2317 | case Primitive::kPrimShort: |
| 2318 | case Primitive::kPrimInt: |
| 2319 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2320 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2321 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2322 | break; |
| 2323 | |
| 2324 | default: |
| 2325 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2326 | << " to " << result_type; |
| 2327 | } |
| 2328 | break; |
| 2329 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimShort: |
| 2331 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimBoolean: |
| 2333 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2334 | case Primitive::kPrimByte: |
| 2335 | case Primitive::kPrimInt: |
| 2336 | case Primitive::kPrimChar: |
| 2337 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2338 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2339 | break; |
| 2340 | |
| 2341 | default: |
| 2342 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2343 | << " to " << result_type; |
| 2344 | } |
| 2345 | break; |
| 2346 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimInt: |
| 2348 | switch (input_type) { |
| 2349 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2350 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2351 | DCHECK(out.IsRegister()); |
| 2352 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2353 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2354 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2355 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2356 | } else { |
| 2357 | DCHECK(in.IsConstant()); |
| 2358 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2359 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2360 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2361 | } |
| 2362 | break; |
| 2363 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimFloat: { |
| 2365 | // Processing a Dex `float-to-int' instruction. |
| 2366 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2367 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 2368 | __ vcvtis(temp, temp); |
| 2369 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2370 | break; |
| 2371 | } |
| 2372 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2373 | case Primitive::kPrimDouble: { |
| 2374 | // Processing a Dex `double-to-int' instruction. |
| 2375 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2376 | DRegister temp_d = FromLowSToD(temp_s); |
| 2377 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 2378 | __ vcvtid(temp_s, temp_d); |
| 2379 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2380 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2381 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2382 | |
| 2383 | default: |
| 2384 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2385 | << " to " << result_type; |
| 2386 | } |
| 2387 | break; |
| 2388 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2389 | case Primitive::kPrimLong: |
| 2390 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2391 | case Primitive::kPrimBoolean: |
| 2392 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2393 | case Primitive::kPrimByte: |
| 2394 | case Primitive::kPrimShort: |
| 2395 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2396 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2397 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2398 | DCHECK(out.IsRegisterPair()); |
| 2399 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2400 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2401 | // Sign extension. |
| 2402 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2403 | out.AsRegisterPairLow<Register>(), |
| 2404 | 31); |
| 2405 | break; |
| 2406 | |
| 2407 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2408 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2409 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2410 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2411 | conversion->GetDexPc(), |
| 2412 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2413 | break; |
| 2414 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2416 | // Processing a Dex `double-to-long' instruction. |
| 2417 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2418 | conversion, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 2419 | conversion->GetDexPc(), |
| 2420 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | |
| 2423 | default: |
| 2424 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2425 | << " to " << result_type; |
| 2426 | } |
| 2427 | break; |
| 2428 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimChar: |
| 2430 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimBoolean: |
| 2432 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimShort: |
| 2435 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2436 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2437 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2438 | break; |
| 2439 | |
| 2440 | default: |
| 2441 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2442 | << " to " << result_type; |
| 2443 | } |
| 2444 | break; |
| 2445 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2447 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimBoolean: |
| 2449 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2450 | case Primitive::kPrimByte: |
| 2451 | case Primitive::kPrimShort: |
| 2452 | case Primitive::kPrimInt: |
| 2453 | case Primitive::kPrimChar: { |
| 2454 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2455 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2456 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2457 | break; |
| 2458 | } |
| 2459 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2460 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2461 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2462 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f), |
| 2463 | conversion, |
| 2464 | conversion->GetDexPc(), |
| 2465 | nullptr); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2466 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2467 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2469 | // Processing a Dex `double-to-float' instruction. |
| 2470 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2471 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | |
| 2474 | default: |
| 2475 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2476 | << " to " << result_type; |
| 2477 | }; |
| 2478 | break; |
| 2479 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2480 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2481 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2482 | case Primitive::kPrimBoolean: |
| 2483 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2484 | case Primitive::kPrimByte: |
| 2485 | case Primitive::kPrimShort: |
| 2486 | case Primitive::kPrimInt: |
| 2487 | case Primitive::kPrimChar: { |
| 2488 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2489 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2490 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2491 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2492 | break; |
| 2493 | } |
| 2494 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimLong: { |
| 2496 | // Processing a Dex `long-to-double' instruction. |
| 2497 | Register low = in.AsRegisterPairLow<Register>(); |
| 2498 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2499 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2500 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2501 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2502 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2503 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2504 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2505 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2506 | // temp_d = int-to-double(high) |
| 2507 | __ vmovsr(temp_s, high); |
| 2508 | __ vcvtdi(temp_d, temp_s); |
| 2509 | // constant_d = k2Pow32EncodingForDouble |
| 2510 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2511 | // out_d = unsigned-to-double(low) |
| 2512 | __ vmovsr(out_s, low); |
| 2513 | __ vcvtdu(out_d, out_s); |
| 2514 | // out_d += temp_d * constant_d |
| 2515 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2516 | break; |
| 2517 | } |
| 2518 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2519 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2520 | // Processing a Dex `float-to-double' instruction. |
| 2521 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2522 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2523 | break; |
| 2524 | |
| 2525 | default: |
| 2526 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2527 | << " to " << result_type; |
| 2528 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | |
| 2531 | default: |
| 2532 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2533 | << " to " << result_type; |
| 2534 | } |
| 2535 | } |
| 2536 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2537 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2538 | LocationSummary* locations = |
| 2539 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2540 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2543 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2545 | break; |
| 2546 | } |
| 2547 | |
| 2548 | case Primitive::kPrimLong: { |
| 2549 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2550 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2551 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2552 | break; |
| 2553 | } |
| 2554 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2555 | case Primitive::kPrimFloat: |
| 2556 | case Primitive::kPrimDouble: { |
| 2557 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2558 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2559 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2560 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2561 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2562 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2563 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2564 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2565 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2569 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2570 | Location out = locations->Out(); |
| 2571 | Location first = locations->InAt(0); |
| 2572 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2573 | switch (add->GetResultType()) { |
| 2574 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2575 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2576 | __ add(out.AsRegister<Register>(), |
| 2577 | first.AsRegister<Register>(), |
| 2578 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2579 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2580 | __ AddConstant(out.AsRegister<Register>(), |
| 2581 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2582 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2583 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2584 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2585 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimLong: { |
| 2587 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2588 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2589 | first.AsRegisterPairLow<Register>(), |
| 2590 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2591 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2592 | first.AsRegisterPairHigh<Register>(), |
| 2593 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2594 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2595 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2596 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2597 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2598 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2599 | first.AsFpuRegister<SRegister>(), |
| 2600 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2601 | break; |
| 2602 | |
| 2603 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2604 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2605 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2606 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2607 | break; |
| 2608 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2609 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2610 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2614 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2615 | LocationSummary* locations = |
| 2616 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2617 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2618 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2619 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2620 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2621 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2622 | break; |
| 2623 | } |
| 2624 | |
| 2625 | case Primitive::kPrimLong: { |
| 2626 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2627 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2628 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2629 | break; |
| 2630 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2631 | case Primitive::kPrimFloat: |
| 2632 | case Primitive::kPrimDouble: { |
| 2633 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2634 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2635 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2636 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2637 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2638 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2639 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2640 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 2644 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2645 | Location out = locations->Out(); |
| 2646 | Location first = locations->InAt(0); |
| 2647 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2648 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2649 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2650 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2651 | __ sub(out.AsRegister<Register>(), |
| 2652 | first.AsRegister<Register>(), |
| 2653 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2654 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2655 | __ AddConstant(out.AsRegister<Register>(), |
| 2656 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2657 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2658 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2659 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2660 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2661 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2662 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2663 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2664 | __ subs(out.AsRegisterPairLow<Register>(), |
| 2665 | first.AsRegisterPairLow<Register>(), |
| 2666 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2667 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2668 | first.AsRegisterPairHigh<Register>(), |
| 2669 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2670 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2671 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2672 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2673 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2674 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 2675 | first.AsFpuRegister<SRegister>(), |
| 2676 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2677 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2681 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2682 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2683 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2684 | break; |
| 2685 | } |
| 2686 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2687 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2688 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2689 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2690 | } |
| 2691 | } |
| 2692 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2693 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 2694 | LocationSummary* locations = |
| 2695 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2696 | switch (mul->GetResultType()) { |
| 2697 | case Primitive::kPrimInt: |
| 2698 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2699 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2700 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2701 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2702 | break; |
| 2703 | } |
| 2704 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2705 | case Primitive::kPrimFloat: |
| 2706 | case Primitive::kPrimDouble: { |
| 2707 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2708 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2709 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2710 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2711 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2712 | |
| 2713 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2714 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 2719 | LocationSummary* locations = mul->GetLocations(); |
| 2720 | Location out = locations->Out(); |
| 2721 | Location first = locations->InAt(0); |
| 2722 | Location second = locations->InAt(1); |
| 2723 | switch (mul->GetResultType()) { |
| 2724 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2725 | __ mul(out.AsRegister<Register>(), |
| 2726 | first.AsRegister<Register>(), |
| 2727 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2728 | break; |
| 2729 | } |
| 2730 | case Primitive::kPrimLong: { |
| 2731 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 2732 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 2733 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2734 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 2735 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2736 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2737 | |
| 2738 | // Extra checks to protect caused by the existence of R1_R2. |
| 2739 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 2740 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 2741 | DCHECK_NE(out_hi, in1_lo); |
| 2742 | DCHECK_NE(out_hi, in2_lo); |
| 2743 | |
| 2744 | // input: in1 - 64 bits, in2 - 64 bits |
| 2745 | // output: out |
| 2746 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2747 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2748 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2749 | |
| 2750 | // IP <- in1.lo * in2.hi |
| 2751 | __ mul(IP, in1_lo, in2_hi); |
| 2752 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2753 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2754 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2755 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2756 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2757 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2758 | break; |
| 2759 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2760 | |
| 2761 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2762 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2763 | first.AsFpuRegister<SRegister>(), |
| 2764 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2765 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2769 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2770 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2771 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2772 | break; |
| 2773 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2774 | |
| 2775 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2776 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2780 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2781 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2782 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2783 | |
| 2784 | LocationSummary* locations = instruction->GetLocations(); |
| 2785 | Location second = locations->InAt(1); |
| 2786 | DCHECK(second.IsConstant()); |
| 2787 | |
| 2788 | Register out = locations->Out().AsRegister<Register>(); |
| 2789 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2790 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2791 | DCHECK(imm == 1 || imm == -1); |
| 2792 | |
| 2793 | if (instruction->IsRem()) { |
| 2794 | __ LoadImmediate(out, 0); |
| 2795 | } else { |
| 2796 | if (imm == 1) { |
| 2797 | __ Mov(out, dividend); |
| 2798 | } else { |
| 2799 | __ rsb(out, dividend, ShifterOperand(0)); |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2805 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2806 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2807 | |
| 2808 | LocationSummary* locations = instruction->GetLocations(); |
| 2809 | Location second = locations->InAt(1); |
| 2810 | DCHECK(second.IsConstant()); |
| 2811 | |
| 2812 | Register out = locations->Out().AsRegister<Register>(); |
| 2813 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2814 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2815 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 2816 | uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2817 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 2818 | int ctz_imm = CTZ(abs_imm); |
| 2819 | |
| 2820 | if (ctz_imm == 1) { |
| 2821 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 2822 | } else { |
| 2823 | __ Asr(temp, dividend, 31); |
| 2824 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 2825 | } |
| 2826 | __ add(out, temp, ShifterOperand(dividend)); |
| 2827 | |
| 2828 | if (instruction->IsDiv()) { |
| 2829 | __ Asr(out, out, ctz_imm); |
| 2830 | if (imm < 0) { |
| 2831 | __ rsb(out, out, ShifterOperand(0)); |
| 2832 | } |
| 2833 | } else { |
| 2834 | __ ubfx(out, out, 0, ctz_imm); |
| 2835 | __ sub(out, out, ShifterOperand(temp)); |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(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 | Register out = locations->Out().AsRegister<Register>(); |
| 2848 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 2849 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 2850 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2851 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2852 | |
| 2853 | int64_t magic; |
| 2854 | int shift; |
| 2855 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2856 | |
| 2857 | __ LoadImmediate(temp1, magic); |
| 2858 | __ smull(temp2, temp1, dividend, temp1); |
| 2859 | |
| 2860 | if (imm > 0 && magic < 0) { |
| 2861 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 2862 | } else if (imm < 0 && magic > 0) { |
| 2863 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 2864 | } |
| 2865 | |
| 2866 | if (shift != 0) { |
| 2867 | __ Asr(temp1, temp1, shift); |
| 2868 | } |
| 2869 | |
| 2870 | if (instruction->IsDiv()) { |
| 2871 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2872 | } else { |
| 2873 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 2874 | // TODO: Strength reduction for mls. |
| 2875 | __ LoadImmediate(temp2, imm); |
| 2876 | __ mls(out, temp1, temp2, dividend); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 2881 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2882 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 2883 | |
| 2884 | LocationSummary* locations = instruction->GetLocations(); |
| 2885 | Location second = locations->InAt(1); |
| 2886 | DCHECK(second.IsConstant()); |
| 2887 | |
| 2888 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2889 | if (imm == 0) { |
| 2890 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2891 | } else if (imm == 1 || imm == -1) { |
| 2892 | DivRemOneOrMinusOne(instruction); |
| 2893 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 2894 | DivRemByPowerOfTwo(instruction); |
| 2895 | } else { |
| 2896 | DCHECK(imm <= -2 || imm >= 2); |
| 2897 | GenerateDivRemWithAnyConstant(instruction); |
| 2898 | } |
| 2899 | } |
| 2900 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2901 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2902 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2903 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 2904 | // pLdiv runtime call. |
| 2905 | call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2906 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 2907 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2908 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 2909 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 2910 | // pIdivmod runtime call. |
| 2911 | call_kind = LocationSummary::kCall; |
| 2912 | } |
| 2913 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2914 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2915 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2916 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2917 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2918 | if (div->InputAt(1)->IsConstant()) { |
| 2919 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 2920 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2921 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2922 | int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue()); |
| 2923 | if (abs_imm <= 1) { |
| 2924 | // No temp register required. |
| 2925 | } else { |
| 2926 | locations->AddTemp(Location::RequiresRegister()); |
| 2927 | if (!IsPowerOfTwo(abs_imm)) { |
| 2928 | locations->AddTemp(Location::RequiresRegister()); |
| 2929 | } |
| 2930 | } |
| 2931 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2932 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2933 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2934 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2935 | } else { |
| 2936 | InvokeRuntimeCallingConvention calling_convention; |
| 2937 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2938 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2939 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 2940 | // we only need the former. |
| 2941 | locations->SetOut(Location::RegisterLocation(R0)); |
| 2942 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2943 | break; |
| 2944 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2945 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2946 | InvokeRuntimeCallingConvention calling_convention; |
| 2947 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2948 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2949 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2950 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2951 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2952 | break; |
| 2953 | } |
| 2954 | case Primitive::kPrimFloat: |
| 2955 | case Primitive::kPrimDouble: { |
| 2956 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2957 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2958 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2959 | break; |
| 2960 | } |
| 2961 | |
| 2962 | default: |
| 2963 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2968 | LocationSummary* locations = div->GetLocations(); |
| 2969 | Location out = locations->Out(); |
| 2970 | Location first = locations->InAt(0); |
| 2971 | Location second = locations->InAt(1); |
| 2972 | |
| 2973 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2974 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2975 | if (second.IsConstant()) { |
| 2976 | GenerateDivRemConstantIntegral(div); |
| 2977 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 2978 | __ sdiv(out.AsRegister<Register>(), |
| 2979 | first.AsRegister<Register>(), |
| 2980 | second.AsRegister<Register>()); |
| 2981 | } else { |
| 2982 | InvokeRuntimeCallingConvention calling_convention; |
| 2983 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 2984 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 2985 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 2986 | |
| 2987 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr); |
| 2988 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2989 | break; |
| 2990 | } |
| 2991 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2992 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2993 | InvokeRuntimeCallingConvention calling_convention; |
| 2994 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2995 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2996 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2997 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2998 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2999 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3000 | |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3001 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3002 | break; |
| 3003 | } |
| 3004 | |
| 3005 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3006 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3007 | first.AsFpuRegister<SRegister>(), |
| 3008 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | } |
| 3011 | |
| 3012 | case Primitive::kPrimDouble: { |
| 3013 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3014 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3015 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3016 | break; |
| 3017 | } |
| 3018 | |
| 3019 | default: |
| 3020 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3021 | } |
| 3022 | } |
| 3023 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3024 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3025 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3026 | |
| 3027 | // Most remainders are implemented in the runtime. |
| 3028 | LocationSummary::CallKind call_kind = LocationSummary::kCall; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3029 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3030 | // sdiv will be replaced by other instruction sequence. |
| 3031 | call_kind = LocationSummary::kNoCall; |
| 3032 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3033 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3034 | // Have hardware divide instruction for int, do it with three instructions. |
| 3035 | call_kind = LocationSummary::kNoCall; |
| 3036 | } |
| 3037 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3038 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3039 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3040 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3041 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3042 | if (rem->InputAt(1)->IsConstant()) { |
| 3043 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3044 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3045 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3046 | int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue()); |
| 3047 | if (abs_imm <= 1) { |
| 3048 | // No temp register required. |
| 3049 | } else { |
| 3050 | locations->AddTemp(Location::RequiresRegister()); |
| 3051 | if (!IsPowerOfTwo(abs_imm)) { |
| 3052 | locations->AddTemp(Location::RequiresRegister()); |
| 3053 | } |
| 3054 | } |
| 3055 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3056 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3057 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3058 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3059 | locations->AddTemp(Location::RequiresRegister()); |
| 3060 | } else { |
| 3061 | InvokeRuntimeCallingConvention calling_convention; |
| 3062 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3063 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3064 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3065 | // we only need the latter. |
| 3066 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3067 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3068 | break; |
| 3069 | } |
| 3070 | case Primitive::kPrimLong: { |
| 3071 | InvokeRuntimeCallingConvention calling_convention; |
| 3072 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3073 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3074 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3075 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3076 | // The runtime helper puts the output in R2,R3. |
| 3077 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3078 | break; |
| 3079 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3080 | case Primitive::kPrimFloat: { |
| 3081 | InvokeRuntimeCallingConvention calling_convention; |
| 3082 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3083 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3084 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3085 | break; |
| 3086 | } |
| 3087 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3088 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3089 | InvokeRuntimeCallingConvention calling_convention; |
| 3090 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3091 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3092 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3093 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3094 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3095 | break; |
| 3096 | } |
| 3097 | |
| 3098 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3099 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3104 | LocationSummary* locations = rem->GetLocations(); |
| 3105 | Location out = locations->Out(); |
| 3106 | Location first = locations->InAt(0); |
| 3107 | Location second = locations->InAt(1); |
| 3108 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3109 | Primitive::Type type = rem->GetResultType(); |
| 3110 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3111 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3112 | if (second.IsConstant()) { |
| 3113 | GenerateDivRemConstantIntegral(rem); |
| 3114 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3115 | Register reg1 = first.AsRegister<Register>(); |
| 3116 | Register reg2 = second.AsRegister<Register>(); |
| 3117 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3118 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3119 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3120 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3121 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3122 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3123 | } else { |
| 3124 | InvokeRuntimeCallingConvention calling_convention; |
| 3125 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3126 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3127 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3128 | |
| 3129 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr); |
| 3130 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3131 | break; |
| 3132 | } |
| 3133 | |
| 3134 | case Primitive::kPrimLong: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3135 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3136 | break; |
| 3137 | } |
| 3138 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3139 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3140 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3141 | break; |
| 3142 | } |
| 3143 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3144 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3145 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3146 | break; |
| 3147 | } |
| 3148 | |
| 3149 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3150 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3154 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3155 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3156 | ? LocationSummary::kCallOnSlowPath |
| 3157 | : LocationSummary::kNoCall; |
| 3158 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3159 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3160 | if (instruction->HasUses()) { |
| 3161 | locations->SetOut(Location::SameAsFirstInput()); |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3166 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3167 | codegen_->AddSlowPath(slow_path); |
| 3168 | |
| 3169 | LocationSummary* locations = instruction->GetLocations(); |
| 3170 | Location value = locations->InAt(0); |
| 3171 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3172 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3173 | case Primitive::kPrimByte: |
| 3174 | case Primitive::kPrimChar: |
| 3175 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3176 | case Primitive::kPrimInt: { |
| 3177 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3178 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3179 | } else { |
| 3180 | DCHECK(value.IsConstant()) << value; |
| 3181 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3182 | __ b(slow_path->GetEntryLabel()); |
| 3183 | } |
| 3184 | } |
| 3185 | break; |
| 3186 | } |
| 3187 | case Primitive::kPrimLong: { |
| 3188 | if (value.IsRegisterPair()) { |
| 3189 | __ orrs(IP, |
| 3190 | value.AsRegisterPairLow<Register>(), |
| 3191 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3192 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3193 | } else { |
| 3194 | DCHECK(value.IsConstant()) << value; |
| 3195 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3196 | __ b(slow_path->GetEntryLabel()); |
| 3197 | } |
| 3198 | } |
| 3199 | break; |
| 3200 | default: |
| 3201 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3202 | } |
| 3203 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3204 | } |
| 3205 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3206 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3207 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3208 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3209 | LocationSummary* locations = |
| 3210 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3211 | |
| 3212 | switch (op->GetResultType()) { |
| 3213 | case Primitive::kPrimInt: { |
| 3214 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3215 | if (op->InputAt(1)->IsConstant()) { |
| 3216 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3217 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3218 | } else { |
| 3219 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3220 | // Make the output overlap, as it will be used to hold the masked |
| 3221 | // second input. |
| 3222 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3223 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3224 | break; |
| 3225 | } |
| 3226 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3227 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3228 | if (op->InputAt(1)->IsConstant()) { |
| 3229 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3230 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3231 | // don't clash with high registers which the register allocator currently guarantees. |
| 3232 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3233 | } else { |
| 3234 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3235 | locations->AddTemp(Location::RequiresRegister()); |
| 3236 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3237 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3238 | break; |
| 3239 | } |
| 3240 | default: |
| 3241 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3246 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3247 | |
| 3248 | LocationSummary* locations = op->GetLocations(); |
| 3249 | Location out = locations->Out(); |
| 3250 | Location first = locations->InAt(0); |
| 3251 | Location second = locations->InAt(1); |
| 3252 | |
| 3253 | Primitive::Type type = op->GetResultType(); |
| 3254 | switch (type) { |
| 3255 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3256 | Register out_reg = out.AsRegister<Register>(); |
| 3257 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3258 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3259 | Register second_reg = second.AsRegister<Register>(); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3260 | // Arm doesn't mask the shift count so we need to do it ourselves. |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3261 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3262 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3263 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3264 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3265 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3266 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3267 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3268 | } |
| 3269 | } else { |
| 3270 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3271 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 3272 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 3273 | __ Mov(out_reg, first_reg); |
| 3274 | } else if (op->IsShl()) { |
| 3275 | __ Lsl(out_reg, first_reg, shift_value); |
| 3276 | } else if (op->IsShr()) { |
| 3277 | __ Asr(out_reg, first_reg, shift_value); |
| 3278 | } else { |
| 3279 | __ Lsr(out_reg, first_reg, shift_value); |
| 3280 | } |
| 3281 | } |
| 3282 | break; |
| 3283 | } |
| 3284 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3285 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3286 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3287 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3288 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3289 | Register low = first.AsRegisterPairLow<Register>(); |
| 3290 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3291 | if (second.IsRegister()) { |
| 3292 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3293 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3294 | Register second_reg = second.AsRegister<Register>(); |
| 3295 | |
| 3296 | if (op->IsShl()) { |
| 3297 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3298 | // Shift the high part |
| 3299 | __ Lsl(o_h, high, o_l); |
| 3300 | // Shift the low part and `or` what overflew on the high part |
| 3301 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3302 | __ Lsr(temp, low, temp); |
| 3303 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3304 | // If the shift is > 32 bits, override the high part |
| 3305 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3306 | __ it(PL); |
| 3307 | __ Lsl(o_h, low, temp, PL); |
| 3308 | // Shift the low part |
| 3309 | __ Lsl(o_l, low, o_l); |
| 3310 | } else if (op->IsShr()) { |
| 3311 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3312 | // Shift the low part |
| 3313 | __ Lsr(o_l, low, o_h); |
| 3314 | // Shift the high part and `or` what underflew on the low part |
| 3315 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3316 | __ Lsl(temp, high, temp); |
| 3317 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3318 | // If the shift is > 32 bits, override the low part |
| 3319 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3320 | __ it(PL); |
| 3321 | __ Asr(o_l, high, temp, PL); |
| 3322 | // Shift the high part |
| 3323 | __ Asr(o_h, high, o_h); |
| 3324 | } else { |
| 3325 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue)); |
| 3326 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3327 | __ Lsr(o_l, low, o_h); |
| 3328 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3329 | __ Lsl(temp, high, temp); |
| 3330 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3331 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3332 | __ it(PL); |
| 3333 | __ Lsr(o_l, high, temp, PL); |
| 3334 | __ Lsr(o_h, high, o_h); |
| 3335 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3336 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3337 | // Register allocator doesn't create partial overlap. |
| 3338 | DCHECK_NE(o_l, high); |
| 3339 | DCHECK_NE(o_h, low); |
| 3340 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3341 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxLongShiftValue); |
| 3342 | if (shift_value > 32) { |
| 3343 | if (op->IsShl()) { |
| 3344 | __ Lsl(o_h, low, shift_value - 32); |
| 3345 | __ LoadImmediate(o_l, 0); |
| 3346 | } else if (op->IsShr()) { |
| 3347 | __ Asr(o_l, high, shift_value - 32); |
| 3348 | __ Asr(o_h, high, 31); |
| 3349 | } else { |
| 3350 | __ Lsr(o_l, high, shift_value - 32); |
| 3351 | __ LoadImmediate(o_h, 0); |
| 3352 | } |
| 3353 | } else if (shift_value == 32) { |
| 3354 | if (op->IsShl()) { |
| 3355 | __ mov(o_h, ShifterOperand(low)); |
| 3356 | __ LoadImmediate(o_l, 0); |
| 3357 | } else if (op->IsShr()) { |
| 3358 | __ mov(o_l, ShifterOperand(high)); |
| 3359 | __ Asr(o_h, high, 31); |
| 3360 | } else { |
| 3361 | __ mov(o_l, ShifterOperand(high)); |
| 3362 | __ LoadImmediate(o_h, 0); |
| 3363 | } |
| 3364 | } else { // shift_value < 32 |
| 3365 | if (op->IsShl()) { |
| 3366 | __ Lsl(o_h, high, shift_value); |
| 3367 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3368 | __ Lsl(o_l, low, shift_value); |
| 3369 | } else if (op->IsShr()) { |
| 3370 | __ Lsr(o_l, low, shift_value); |
| 3371 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3372 | __ Asr(o_h, high, shift_value); |
| 3373 | } else { |
| 3374 | __ Lsr(o_l, low, shift_value); |
| 3375 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3376 | __ Lsr(o_h, high, shift_value); |
| 3377 | } |
| 3378 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3379 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3380 | break; |
| 3381 | } |
| 3382 | default: |
| 3383 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3384 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3389 | HandleShift(shl); |
| 3390 | } |
| 3391 | |
| 3392 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3393 | HandleShift(shl); |
| 3394 | } |
| 3395 | |
| 3396 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3397 | HandleShift(shr); |
| 3398 | } |
| 3399 | |
| 3400 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3401 | HandleShift(shr); |
| 3402 | } |
| 3403 | |
| 3404 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3405 | HandleShift(ushr); |
| 3406 | } |
| 3407 | |
| 3408 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3409 | HandleShift(ushr); |
| 3410 | } |
| 3411 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3412 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3413 | LocationSummary* locations = |
| 3414 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3415 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3416 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3417 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3418 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 3422 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3423 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3424 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3425 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3426 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3427 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3428 | instruction->GetDexPc(), |
| 3429 | nullptr); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3432 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3433 | LocationSummary* locations = |
| 3434 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3435 | InvokeRuntimeCallingConvention calling_convention; |
| 3436 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3437 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3438 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3439 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 3443 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3444 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3445 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3446 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3447 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3448 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3449 | instruction->GetDexPc(), |
| 3450 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3451 | } |
| 3452 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3453 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3454 | LocationSummary* locations = |
| 3455 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3456 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3457 | if (location.IsStackSlot()) { |
| 3458 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3459 | } else if (location.IsDoubleStackSlot()) { |
| 3460 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3461 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3462 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3463 | } |
| 3464 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3465 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 3466 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3467 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3471 | LocationSummary* locations = |
| 3472 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3473 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3474 | } |
| 3475 | |
| 3476 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3477 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3478 | } |
| 3479 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3480 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3481 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3482 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3484 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3485 | } |
| 3486 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3487 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 3488 | LocationSummary* locations = not_->GetLocations(); |
| 3489 | Location out = locations->Out(); |
| 3490 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3491 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3492 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3493 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3494 | break; |
| 3495 | |
| 3496 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3497 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 3498 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 3499 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 3500 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3501 | break; |
| 3502 | |
| 3503 | default: |
| 3504 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3505 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3506 | } |
| 3507 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3508 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3509 | LocationSummary* locations = |
| 3510 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3512 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3513 | } |
| 3514 | |
| 3515 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3516 | LocationSummary* locations = bool_not->GetLocations(); |
| 3517 | Location out = locations->Out(); |
| 3518 | Location in = locations->InAt(0); |
| 3519 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 3520 | } |
| 3521 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3522 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3523 | LocationSummary* locations = |
| 3524 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3525 | switch (compare->InputAt(0)->GetType()) { |
| 3526 | case Primitive::kPrimLong: { |
| 3527 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3528 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3529 | // Output overlaps because it is written before doing the low comparison. |
| 3530 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| 3533 | case Primitive::kPrimFloat: |
| 3534 | case Primitive::kPrimDouble: { |
| 3535 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3536 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3537 | locations->SetOut(Location::RequiresRegister()); |
| 3538 | break; |
| 3539 | } |
| 3540 | default: |
| 3541 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3542 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3546 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3547 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3548 | Location left = locations->InAt(0); |
| 3549 | Location right = locations->InAt(1); |
| 3550 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3551 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3552 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 3553 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3554 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3555 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 3556 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3557 | __ b(&less, LT); |
| 3558 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3559 | // 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] | 3560 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3561 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 3562 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3563 | break; |
| 3564 | } |
| 3565 | case Primitive::kPrimFloat: |
| 3566 | case Primitive::kPrimDouble: { |
| 3567 | __ LoadImmediate(out, 0); |
| 3568 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3569 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3570 | } else { |
| 3571 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 3572 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 3573 | } |
| 3574 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 3575 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3576 | break; |
| 3577 | } |
| 3578 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3579 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3580 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3581 | __ b(&done, EQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3582 | __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3583 | |
| 3584 | __ Bind(&greater); |
| 3585 | __ LoadImmediate(out, 1); |
| 3586 | __ b(&done); |
| 3587 | |
| 3588 | __ Bind(&less); |
| 3589 | __ LoadImmediate(out, -1); |
| 3590 | |
| 3591 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3592 | } |
| 3593 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3594 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3595 | LocationSummary* locations = |
| 3596 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3597 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3598 | locations->SetInAt(i, Location::Any()); |
| 3599 | } |
| 3600 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3601 | } |
| 3602 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3603 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3604 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3607 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3608 | // TODO (ported from quick): revisit Arm barrier kinds |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3609 | DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3610 | switch (kind) { |
| 3611 | case MemBarrierKind::kAnyStore: |
| 3612 | case MemBarrierKind::kLoadAny: |
| 3613 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3614 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | } |
| 3617 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3618 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3619 | break; |
| 3620 | } |
| 3621 | default: |
| 3622 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 3623 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 3624 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 3628 | uint32_t offset, |
| 3629 | Register out_lo, |
| 3630 | Register out_hi) { |
| 3631 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3632 | // Ensure `out_lo` is different from `addr`, so that loading |
| 3633 | // `offset` into `out_lo` does not clutter `addr`. |
| 3634 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3635 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3636 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 3637 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3638 | } |
| 3639 | __ ldrexd(out_lo, out_hi, addr); |
| 3640 | } |
| 3641 | |
| 3642 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 3643 | uint32_t offset, |
| 3644 | Register value_lo, |
| 3645 | Register value_hi, |
| 3646 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3647 | Register temp2, |
| 3648 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 3649 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3650 | if (offset != 0) { |
| 3651 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 3652 | __ add(IP, addr, ShifterOperand(temp1)); |
| 3653 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3654 | } |
| 3655 | __ Bind(&fail); |
| 3656 | // We need a load followed by store. (The address used in a STREX instruction must |
| 3657 | // be the same as the address in the most recently executed LDREX instruction.) |
| 3658 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3659 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3660 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3661 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3665 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3666 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3667 | LocationSummary* locations = |
| 3668 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3669 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3670 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3671 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3672 | if (Primitive::IsFloatingPointType(field_type)) { |
| 3673 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3674 | } else { |
| 3675 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3676 | } |
| 3677 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3678 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3679 | bool generate_volatile = field_info.IsVolatile() |
| 3680 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3681 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3682 | bool needs_write_barrier = |
| 3683 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3684 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3685 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3686 | if (needs_write_barrier) { |
| 3687 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3688 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3689 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3690 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3691 | // - registers need to be consecutive |
| 3692 | // - the first register should be even but not R14. |
| 3693 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3694 | // enable Arm encoding. |
| 3695 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3696 | |
| 3697 | locations->AddTemp(Location::RequiresRegister()); |
| 3698 | locations->AddTemp(Location::RequiresRegister()); |
| 3699 | if (field_type == Primitive::kPrimDouble) { |
| 3700 | // For doubles we need two more registers to copy the value. |
| 3701 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 3702 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 3703 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3704 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3705 | } |
| 3706 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3707 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3708 | const FieldInfo& field_info, |
| 3709 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3710 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3711 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3712 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3713 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3714 | Location value = locations->InAt(1); |
| 3715 | |
| 3716 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3717 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3718 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3719 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3720 | bool needs_write_barrier = |
| 3721 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3722 | |
| 3723 | if (is_volatile) { |
| 3724 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3725 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3726 | |
| 3727 | switch (field_type) { |
| 3728 | case Primitive::kPrimBoolean: |
| 3729 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3730 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3731 | break; |
| 3732 | } |
| 3733 | |
| 3734 | case Primitive::kPrimShort: |
| 3735 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3736 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3737 | break; |
| 3738 | } |
| 3739 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3740 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3741 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3742 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3743 | // Note that in the case where `value` is a null reference, |
| 3744 | // we do not enter this block, as a null reference does not |
| 3745 | // need poisoning. |
| 3746 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3747 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3748 | __ Mov(temp, value.AsRegister<Register>()); |
| 3749 | __ PoisonHeapReference(temp); |
| 3750 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 3751 | } else { |
| 3752 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 3753 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | |
| 3757 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3758 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3759 | GenerateWideAtomicStore(base, offset, |
| 3760 | value.AsRegisterPairLow<Register>(), |
| 3761 | value.AsRegisterPairHigh<Register>(), |
| 3762 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3763 | locations->GetTemp(1).AsRegister<Register>(), |
| 3764 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3765 | } else { |
| 3766 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3767 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3768 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3769 | break; |
| 3770 | } |
| 3771 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3772 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3773 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3774 | break; |
| 3775 | } |
| 3776 | |
| 3777 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3778 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3779 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3780 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3781 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3782 | |
| 3783 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 3784 | |
| 3785 | GenerateWideAtomicStore(base, offset, |
| 3786 | value_reg_lo, |
| 3787 | value_reg_hi, |
| 3788 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3789 | locations->GetTemp(3).AsRegister<Register>(), |
| 3790 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3791 | } else { |
| 3792 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3794 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3795 | break; |
| 3796 | } |
| 3797 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3798 | case Primitive::kPrimVoid: |
| 3799 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3800 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3801 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3802 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3803 | // Longs and doubles are handled in the switch. |
| 3804 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 3805 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3806 | } |
| 3807 | |
| 3808 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3809 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3810 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3811 | codegen_->MarkGCCard( |
| 3812 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3813 | } |
| 3814 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3815 | if (is_volatile) { |
| 3816 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3817 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3818 | } |
| 3819 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3820 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3821 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3822 | |
| 3823 | bool object_field_get_with_read_barrier = |
| 3824 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3825 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3826 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 3827 | object_field_get_with_read_barrier ? |
| 3828 | LocationSummary::kCallOnSlowPath : |
| 3829 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3830 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3831 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3832 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3833 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3834 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3835 | // The output overlaps in case of volatile long: we don't want the |
| 3836 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 3837 | // object's location. Likewise, in the case of an object field get |
| 3838 | // with read barriers enabled, we do not want the load to overwrite |
| 3839 | // the object's location, as we need it to emit the read barrier. |
| 3840 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 3841 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 3842 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3843 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3844 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3845 | } else { |
| 3846 | locations->SetOut(Location::RequiresRegister(), |
| 3847 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 3848 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3849 | if (volatile_for_double) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3850 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 3851 | // - registers need to be consecutive |
| 3852 | // - the first register should be even but not R14. |
| 3853 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 3854 | // enable Arm encoding. |
| 3855 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 3856 | locations->AddTemp(Location::RequiresRegister()); |
| 3857 | locations->AddTemp(Location::RequiresRegister()); |
| 3858 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3859 | } |
| 3860 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 3861 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 3862 | Opcode opcode) { |
| 3863 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 3864 | if (constant->IsConstant() && |
| 3865 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 3866 | return Location::ConstantLocation(constant->AsConstant()); |
| 3867 | } |
| 3868 | return Location::RequiresRegister(); |
| 3869 | } |
| 3870 | |
| 3871 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 3872 | Opcode opcode) { |
| 3873 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 3874 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 3875 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode) && |
| 3876 | CanEncodeConstantAsImmediate(High32Bits(value), opcode); |
| 3877 | } else { |
| 3878 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode) { |
| 3883 | ShifterOperand so; |
| 3884 | ArmAssembler* assembler = codegen_->GetAssembler(); |
| 3885 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, &so)) { |
| 3886 | return true; |
| 3887 | } |
| 3888 | Opcode neg_opcode = kNoOperand; |
| 3889 | switch (opcode) { |
| 3890 | case AND: |
| 3891 | neg_opcode = BIC; |
| 3892 | break; |
| 3893 | case ORR: |
| 3894 | neg_opcode = ORN; |
| 3895 | break; |
| 3896 | default: |
| 3897 | return false; |
| 3898 | } |
| 3899 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, ~value, &so); |
| 3900 | } |
| 3901 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3902 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 3903 | const FieldInfo& field_info) { |
| 3904 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3905 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3906 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3907 | Location base_loc = locations->InAt(0); |
| 3908 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3909 | Location out = locations->Out(); |
| 3910 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3911 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3912 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3913 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3914 | |
| 3915 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3916 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3917 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3918 | break; |
| 3919 | } |
| 3920 | |
| 3921 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3922 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3923 | break; |
| 3924 | } |
| 3925 | |
| 3926 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3927 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3928 | break; |
| 3929 | } |
| 3930 | |
| 3931 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3932 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3933 | break; |
| 3934 | } |
| 3935 | |
| 3936 | case Primitive::kPrimInt: |
| 3937 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3938 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3939 | break; |
| 3940 | } |
| 3941 | |
| 3942 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3943 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3944 | GenerateWideAtomicLoad(base, offset, |
| 3945 | out.AsRegisterPairLow<Register>(), |
| 3946 | out.AsRegisterPairHigh<Register>()); |
| 3947 | } else { |
| 3948 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 3949 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3950 | break; |
| 3951 | } |
| 3952 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3953 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3954 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3955 | break; |
| 3956 | } |
| 3957 | |
| 3958 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3959 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 3960 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3961 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 3962 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 3963 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3964 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3965 | __ vmovdrr(out_reg, lo, hi); |
| 3966 | } else { |
| 3967 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3968 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3969 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3970 | break; |
| 3971 | } |
| 3972 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3973 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3974 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3975 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3976 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3977 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3978 | // Doubles are handled in the switch. |
| 3979 | if (field_type != Primitive::kPrimDouble) { |
| 3980 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3981 | } |
| 3982 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3983 | if (is_volatile) { |
| 3984 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3985 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3986 | |
| 3987 | if (field_type == Primitive::kPrimNot) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3988 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, base_loc, offset); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3989 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3993 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3994 | } |
| 3995 | |
| 3996 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3997 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4001 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4002 | } |
| 4003 | |
| 4004 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4005 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4006 | } |
| 4007 | |
| 4008 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4009 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4010 | } |
| 4011 | |
| 4012 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4013 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4014 | } |
| 4015 | |
| 4016 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4017 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4018 | } |
| 4019 | |
| 4020 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4021 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4024 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4025 | HUnresolvedInstanceFieldGet* instruction) { |
| 4026 | FieldAccessCallingConventionARM calling_convention; |
| 4027 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4028 | instruction, instruction->GetFieldType(), calling_convention); |
| 4029 | } |
| 4030 | |
| 4031 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4032 | HUnresolvedInstanceFieldGet* instruction) { |
| 4033 | FieldAccessCallingConventionARM calling_convention; |
| 4034 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4035 | instruction->GetFieldType(), |
| 4036 | instruction->GetFieldIndex(), |
| 4037 | instruction->GetDexPc(), |
| 4038 | calling_convention); |
| 4039 | } |
| 4040 | |
| 4041 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4042 | HUnresolvedInstanceFieldSet* instruction) { |
| 4043 | FieldAccessCallingConventionARM calling_convention; |
| 4044 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4045 | instruction, instruction->GetFieldType(), calling_convention); |
| 4046 | } |
| 4047 | |
| 4048 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4049 | HUnresolvedInstanceFieldSet* instruction) { |
| 4050 | FieldAccessCallingConventionARM calling_convention; |
| 4051 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4052 | instruction->GetFieldType(), |
| 4053 | instruction->GetFieldIndex(), |
| 4054 | instruction->GetDexPc(), |
| 4055 | calling_convention); |
| 4056 | } |
| 4057 | |
| 4058 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4059 | HUnresolvedStaticFieldGet* instruction) { |
| 4060 | FieldAccessCallingConventionARM calling_convention; |
| 4061 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4062 | instruction, instruction->GetFieldType(), calling_convention); |
| 4063 | } |
| 4064 | |
| 4065 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4066 | HUnresolvedStaticFieldGet* instruction) { |
| 4067 | FieldAccessCallingConventionARM calling_convention; |
| 4068 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4069 | instruction->GetFieldType(), |
| 4070 | instruction->GetFieldIndex(), |
| 4071 | instruction->GetDexPc(), |
| 4072 | calling_convention); |
| 4073 | } |
| 4074 | |
| 4075 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4076 | HUnresolvedStaticFieldSet* instruction) { |
| 4077 | FieldAccessCallingConventionARM calling_convention; |
| 4078 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4079 | instruction, instruction->GetFieldType(), calling_convention); |
| 4080 | } |
| 4081 | |
| 4082 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4083 | HUnresolvedStaticFieldSet* instruction) { |
| 4084 | FieldAccessCallingConventionARM calling_convention; |
| 4085 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4086 | instruction->GetFieldType(), |
| 4087 | instruction->GetFieldIndex(), |
| 4088 | instruction->GetDexPc(), |
| 4089 | calling_convention); |
| 4090 | } |
| 4091 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4092 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4093 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4094 | ? LocationSummary::kCallOnSlowPath |
| 4095 | : LocationSummary::kNoCall; |
| 4096 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4097 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4098 | if (instruction->HasUses()) { |
| 4099 | locations->SetOut(Location::SameAsFirstInput()); |
| 4100 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4103 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4104 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4105 | return; |
| 4106 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4107 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4108 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4109 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 4110 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4111 | } |
| 4112 | |
| 4113 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4114 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4115 | codegen_->AddSlowPath(slow_path); |
| 4116 | |
| 4117 | LocationSummary* locations = instruction->GetLocations(); |
| 4118 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4119 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4120 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4121 | } |
| 4122 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4123 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4124 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4125 | GenerateImplicitNullCheck(instruction); |
| 4126 | } else { |
| 4127 | GenerateExplicitNullCheck(instruction); |
| 4128 | } |
| 4129 | } |
| 4130 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4131 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4132 | bool object_array_get_with_read_barrier = |
| 4133 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4134 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4135 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4136 | object_array_get_with_read_barrier ? |
| 4137 | LocationSummary::kCallOnSlowPath : |
| 4138 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4140 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4141 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4142 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4143 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4144 | // The output overlaps in the case of an object array get with |
| 4145 | // read barriers enabled: we do not want the move to overwrite the |
| 4146 | // array's location, as we need it to emit the read barrier. |
| 4147 | locations->SetOut( |
| 4148 | Location::RequiresRegister(), |
| 4149 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4150 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4154 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4155 | Location obj_loc = locations->InAt(0); |
| 4156 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4157 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4158 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4159 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4160 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4161 | case Primitive::kPrimBoolean: { |
| 4162 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4163 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4164 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4165 | size_t offset = |
| 4166 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4167 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 4168 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4169 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4170 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 4171 | } |
| 4172 | break; |
| 4173 | } |
| 4174 | |
| 4175 | case Primitive::kPrimByte: { |
| 4176 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4177 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4178 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4179 | size_t offset = |
| 4180 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4181 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 4182 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4183 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4184 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 4185 | } |
| 4186 | break; |
| 4187 | } |
| 4188 | |
| 4189 | case Primitive::kPrimShort: { |
| 4190 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4191 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4192 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4193 | size_t offset = |
| 4194 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4195 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 4196 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4197 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4198 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 4199 | } |
| 4200 | break; |
| 4201 | } |
| 4202 | |
| 4203 | case Primitive::kPrimChar: { |
| 4204 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4205 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4206 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4207 | size_t offset = |
| 4208 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4209 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 4210 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4211 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4212 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 4213 | } |
| 4214 | break; |
| 4215 | } |
| 4216 | |
| 4217 | case Primitive::kPrimInt: |
| 4218 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4219 | static_assert( |
| 4220 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4221 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4222 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4223 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4224 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4225 | size_t offset = |
| 4226 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4227 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 4228 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4229 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4230 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 4231 | } |
| 4232 | break; |
| 4233 | } |
| 4234 | |
| 4235 | case Primitive::kPrimLong: { |
| 4236 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4237 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4238 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4239 | size_t offset = |
| 4240 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4241 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4242 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4243 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4244 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4245 | } |
| 4246 | break; |
| 4247 | } |
| 4248 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4249 | case Primitive::kPrimFloat: { |
| 4250 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4251 | Location out = locations->Out(); |
| 4252 | DCHECK(out.IsFpuRegister()); |
| 4253 | if (index.IsConstant()) { |
| 4254 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4255 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset); |
| 4256 | } else { |
| 4257 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4258 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4259 | } |
| 4260 | break; |
| 4261 | } |
| 4262 | |
| 4263 | case Primitive::kPrimDouble: { |
| 4264 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4265 | Location out = locations->Out(); |
| 4266 | DCHECK(out.IsFpuRegisterPair()); |
| 4267 | if (index.IsConstant()) { |
| 4268 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4269 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 4270 | } else { |
| 4271 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 4272 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4273 | } |
| 4274 | break; |
| 4275 | } |
| 4276 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4277 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4278 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4279 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4280 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4281 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4282 | |
| 4283 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4284 | static_assert( |
| 4285 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4286 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4287 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4288 | Location out = locations->Out(); |
| 4289 | if (index.IsConstant()) { |
| 4290 | uint32_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4291 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset); |
| 4292 | } else { |
| 4293 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, data_offset, index); |
| 4294 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4295 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4299 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4300 | |
| 4301 | bool needs_write_barrier = |
| 4302 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4303 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 4304 | bool object_array_set_with_read_barrier = |
| 4305 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4306 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4307 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4308 | instruction, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4309 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 4310 | LocationSummary::kCallOnSlowPath : |
| 4311 | LocationSummary::kNoCall); |
| 4312 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4313 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4314 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4315 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4316 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4317 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4318 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4319 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4320 | if (needs_write_barrier) { |
| 4321 | // Temporary registers for the write barrier. |
| 4322 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4323 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for read barrier too. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4324 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 4328 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4329 | Location array_loc = locations->InAt(0); |
| 4330 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4331 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4332 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4333 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4334 | bool needs_write_barrier = |
| 4335 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4336 | |
| 4337 | switch (value_type) { |
| 4338 | case Primitive::kPrimBoolean: |
| 4339 | case Primitive::kPrimByte: { |
| 4340 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4341 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4342 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4343 | size_t offset = |
| 4344 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4345 | __ StoreToOffset(kStoreByte, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4346 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4347 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4348 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 4349 | } |
| 4350 | break; |
| 4351 | } |
| 4352 | |
| 4353 | case Primitive::kPrimShort: |
| 4354 | case Primitive::kPrimChar: { |
| 4355 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4356 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4357 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4358 | size_t offset = |
| 4359 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4360 | __ StoreToOffset(kStoreHalfword, value, array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4361 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4362 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4363 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 4364 | } |
| 4365 | break; |
| 4366 | } |
| 4367 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4368 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4369 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4370 | Location value_loc = locations->InAt(2); |
| 4371 | Register value = value_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4372 | Register source = value; |
| 4373 | |
| 4374 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 4375 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4376 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4377 | size_t offset = |
| 4378 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4379 | __ StoreToOffset(kStoreWord, source, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4380 | } else { |
| 4381 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4382 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4383 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4384 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4385 | DCHECK(!needs_write_barrier); |
| 4386 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4387 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4388 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4389 | |
| 4390 | DCHECK(needs_write_barrier); |
| 4391 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4392 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4393 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4394 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4395 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4396 | Label done; |
| 4397 | SlowPathCode* slow_path = nullptr; |
| 4398 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4399 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4400 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 4401 | codegen_->AddSlowPath(slow_path); |
| 4402 | if (instruction->GetValueCanBeNull()) { |
| 4403 | Label non_zero; |
| 4404 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 4405 | if (index.IsConstant()) { |
| 4406 | size_t offset = |
| 4407 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4408 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4409 | } else { |
| 4410 | DCHECK(index.IsRegister()) << index; |
| 4411 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4412 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4413 | } |
| 4414 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4415 | __ b(&done); |
| 4416 | __ Bind(&non_zero); |
| 4417 | } |
| 4418 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4419 | if (kEmitCompilerReadBarrier) { |
| 4420 | // When read barriers are enabled, the type checking |
| 4421 | // instrumentation requires two read barriers: |
| 4422 | // |
| 4423 | // __ Mov(temp2, temp1); |
| 4424 | // // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4425 | // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4426 | // codegen_->GenerateReadBarrier( |
| 4427 | // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset); |
| 4428 | // |
| 4429 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4430 | // __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4431 | // codegen_->GenerateReadBarrier( |
| 4432 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc); |
| 4433 | // |
| 4434 | // __ cmp(temp1, ShifterOperand(temp2)); |
| 4435 | // |
| 4436 | // However, the second read barrier may trash `temp`, as it |
| 4437 | // is a temporary register, and as such would not be saved |
| 4438 | // along with live registers before calling the runtime (nor |
| 4439 | // restored afterwards). So in this case, we bail out and |
| 4440 | // delegate the work to the array set slow path. |
| 4441 | // |
| 4442 | // TODO: Extend the register allocator to support a new |
| 4443 | // "(locally) live temp" location so as to avoid always |
| 4444 | // going into the slow path when read barriers are enabled. |
| 4445 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4446 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4447 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 4448 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 4449 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4450 | __ MaybeUnpoisonHeapReference(temp1); |
| 4451 | |
| 4452 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 4453 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 4454 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 4455 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 4456 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 4457 | // nor `temp2`, as we are comparing two poisoned references. |
| 4458 | __ cmp(temp1, ShifterOperand(temp2)); |
| 4459 | |
| 4460 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4461 | Label do_put; |
| 4462 | __ b(&do_put, EQ); |
| 4463 | // If heap poisoning is enabled, the `temp1` reference has |
| 4464 | // not been unpoisoned yet; unpoison it now. |
| 4465 | __ MaybeUnpoisonHeapReference(temp1); |
| 4466 | |
| 4467 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 4468 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 4469 | // If heap poisoning is enabled, no need to unpoison |
| 4470 | // `temp1`, as we are comparing against null below. |
| 4471 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 4472 | __ Bind(&do_put); |
| 4473 | } else { |
| 4474 | __ b(slow_path->GetEntryLabel(), NE); |
| 4475 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | if (kPoisonHeapReferences) { |
| 4480 | // Note that in the case where `value` is a null reference, |
| 4481 | // we do not enter this block, as a null reference does not |
| 4482 | // need poisoning. |
| 4483 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4484 | __ Mov(temp1, value); |
| 4485 | __ PoisonHeapReference(temp1); |
| 4486 | source = temp1; |
| 4487 | } |
| 4488 | |
| 4489 | if (index.IsConstant()) { |
| 4490 | size_t offset = |
| 4491 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4492 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 4493 | } else { |
| 4494 | DCHECK(index.IsRegister()) << index; |
| 4495 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4496 | __ StoreToOffset(kStoreWord, source, IP, data_offset); |
| 4497 | } |
| 4498 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4499 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4500 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4501 | } |
| 4502 | |
| 4503 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 4504 | |
| 4505 | if (done.IsLinked()) { |
| 4506 | __ Bind(&done); |
| 4507 | } |
| 4508 | |
| 4509 | if (slow_path != nullptr) { |
| 4510 | __ Bind(slow_path->GetExitLabel()); |
| 4511 | } |
| 4512 | |
| 4513 | break; |
| 4514 | } |
| 4515 | |
| 4516 | case Primitive::kPrimInt: { |
| 4517 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4518 | Register value = locations->InAt(2).AsRegister<Register>(); |
| 4519 | if (index.IsConstant()) { |
| 4520 | size_t offset = |
| 4521 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4522 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 4523 | } else { |
| 4524 | DCHECK(index.IsRegister()) << index; |
| 4525 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 4526 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 4527 | } |
| 4528 | |
| 4529 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4530 | break; |
| 4531 | } |
| 4532 | |
| 4533 | case Primitive::kPrimLong: { |
| 4534 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4535 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4537 | size_t offset = |
| 4538 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4539 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4540 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4541 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4542 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4543 | } |
| 4544 | break; |
| 4545 | } |
| 4546 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4547 | case Primitive::kPrimFloat: { |
| 4548 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4549 | Location value = locations->InAt(2); |
| 4550 | DCHECK(value.IsFpuRegister()); |
| 4551 | if (index.IsConstant()) { |
| 4552 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4553 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4554 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4555 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4556 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 4557 | } |
| 4558 | break; |
| 4559 | } |
| 4560 | |
| 4561 | case Primitive::kPrimDouble: { |
| 4562 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4563 | Location value = locations->InAt(2); |
| 4564 | DCHECK(value.IsFpuRegisterPair()); |
| 4565 | if (index.IsConstant()) { |
| 4566 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4567 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4568 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4569 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4570 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 4571 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4572 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4573 | break; |
| 4574 | } |
| 4575 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4576 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4577 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4578 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4579 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4580 | |
| 4581 | // Ints and objects are handled in the switch. |
| 4582 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 4583 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4584 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4588 | LocationSummary* locations = |
| 4589 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4590 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4591 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 4595 | LocationSummary* locations = instruction->GetLocations(); |
| 4596 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4597 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4598 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4599 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4600 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4604 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4605 | ? LocationSummary::kCallOnSlowPath |
| 4606 | : LocationSummary::kNoCall; |
| 4607 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4608 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4609 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4610 | if (instruction->HasUses()) { |
| 4611 | locations->SetOut(Location::SameAsFirstInput()); |
| 4612 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4616 | LocationSummary* locations = instruction->GetLocations(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4617 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4618 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4619 | codegen_->AddSlowPath(slow_path); |
| 4620 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4621 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 4622 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4623 | |
| 4624 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4625 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4626 | } |
| 4627 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4628 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 4629 | Register card, |
| 4630 | Register object, |
| 4631 | Register value, |
| 4632 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4633 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4634 | if (can_be_null) { |
| 4635 | __ CompareAndBranchIfZero(value, &is_null); |
| 4636 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4637 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 4638 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 4639 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4640 | if (can_be_null) { |
| 4641 | __ Bind(&is_null); |
| 4642 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4645 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 4646 | temp->SetLocations(nullptr); |
| 4647 | } |
| 4648 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4649 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4650 | // Nothing to do, this is driven by the code generator. |
| 4651 | } |
| 4652 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4653 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4654 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4658 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4659 | } |
| 4660 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4661 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4662 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4663 | } |
| 4664 | |
| 4665 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4666 | HBasicBlock* block = instruction->GetBlock(); |
| 4667 | if (block->GetLoopInformation() != nullptr) { |
| 4668 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4669 | // The back edge will generate the suspend check. |
| 4670 | return; |
| 4671 | } |
| 4672 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4673 | // The goto will generate the suspend check. |
| 4674 | return; |
| 4675 | } |
| 4676 | GenerateSuspendCheck(instruction, nullptr); |
| 4677 | } |
| 4678 | |
| 4679 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4680 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4681 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4682 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 4683 | if (slow_path == nullptr) { |
| 4684 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 4685 | instruction->SetSlowPath(slow_path); |
| 4686 | codegen_->AddSlowPath(slow_path); |
| 4687 | if (successor != nullptr) { |
| 4688 | DCHECK(successor->IsLoopHeader()); |
| 4689 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4690 | } |
| 4691 | } else { |
| 4692 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4693 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4694 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 4695 | __ LoadFromOffset( |
| 4696 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4697 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4698 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4699 | __ Bind(slow_path->GetReturnLabel()); |
| 4700 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4701 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4702 | __ b(slow_path->GetEntryLabel()); |
| 4703 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4704 | } |
| 4705 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4706 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 4707 | return codegen_->GetAssembler(); |
| 4708 | } |
| 4709 | |
| 4710 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4711 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4712 | Location source = move->GetSource(); |
| 4713 | Location destination = move->GetDestination(); |
| 4714 | |
| 4715 | if (source.IsRegister()) { |
| 4716 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4717 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4718 | } else { |
| 4719 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4720 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4721 | SP, destination.GetStackIndex()); |
| 4722 | } |
| 4723 | } else if (source.IsStackSlot()) { |
| 4724 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4725 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4726 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4727 | } else if (destination.IsFpuRegister()) { |
| 4728 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4729 | } else { |
| 4730 | DCHECK(destination.IsStackSlot()); |
| 4731 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 4732 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4733 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4734 | } else if (source.IsFpuRegister()) { |
| 4735 | if (destination.IsFpuRegister()) { |
| 4736 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4737 | } else { |
| 4738 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4739 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 4740 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4741 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4742 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4743 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 4744 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4745 | } else if (destination.IsRegisterPair()) { |
| 4746 | DCHECK(ExpectedPairLayout(destination)); |
| 4747 | __ LoadFromOffset( |
| 4748 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 4749 | } else { |
| 4750 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 4751 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4752 | SP, |
| 4753 | source.GetStackIndex()); |
| 4754 | } |
| 4755 | } else if (source.IsRegisterPair()) { |
| 4756 | if (destination.IsRegisterPair()) { |
| 4757 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 4758 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 4759 | } else { |
| 4760 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4761 | DCHECK(ExpectedPairLayout(source)); |
| 4762 | __ StoreToOffset( |
| 4763 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 4764 | } |
| 4765 | } else if (source.IsFpuRegisterPair()) { |
| 4766 | if (destination.IsFpuRegisterPair()) { |
| 4767 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 4768 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 4769 | } else { |
| 4770 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4771 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 4772 | SP, |
| 4773 | destination.GetStackIndex()); |
| 4774 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4775 | } else { |
| 4776 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4777 | HConstant* constant = source.GetConstant(); |
| 4778 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4779 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4780 | if (destination.IsRegister()) { |
| 4781 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 4782 | } else { |
| 4783 | DCHECK(destination.IsStackSlot()); |
| 4784 | __ LoadImmediate(IP, value); |
| 4785 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4786 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4787 | } else if (constant->IsLongConstant()) { |
| 4788 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4789 | if (destination.IsRegisterPair()) { |
| 4790 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 4791 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4792 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4793 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4794 | __ LoadImmediate(IP, Low32Bits(value)); |
| 4795 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4796 | __ LoadImmediate(IP, High32Bits(value)); |
| 4797 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4798 | } |
| 4799 | } else if (constant->IsDoubleConstant()) { |
| 4800 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4801 | if (destination.IsFpuRegisterPair()) { |
| 4802 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4803 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4804 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4805 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4806 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 4807 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4808 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 4809 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 4810 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4811 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4812 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4813 | float value = constant->AsFloatConstant()->GetValue(); |
| 4814 | if (destination.IsFpuRegister()) { |
| 4815 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 4816 | } else { |
| 4817 | DCHECK(destination.IsStackSlot()); |
| 4818 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 4819 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 4820 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4821 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 4826 | __ Mov(IP, reg); |
| 4827 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 4828 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 4829 | } |
| 4830 | |
| 4831 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 4832 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 4833 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 4834 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4835 | SP, mem1 + stack_offset); |
| 4836 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 4837 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 4838 | SP, mem2 + stack_offset); |
| 4839 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 4840 | } |
| 4841 | |
| 4842 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4843 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4844 | Location source = move->GetSource(); |
| 4845 | Location destination = move->GetDestination(); |
| 4846 | |
| 4847 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4848 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 4849 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 4850 | __ Mov(IP, source.AsRegister<Register>()); |
| 4851 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4852 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4853 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4854 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4855 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4856 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4857 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4858 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4859 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4860 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4861 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4862 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4863 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4864 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4865 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4866 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4867 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 4868 | destination.AsRegisterPairHigh<Register>(), |
| 4869 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4870 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4871 | Register low_reg = source.IsRegisterPair() |
| 4872 | ? source.AsRegisterPairLow<Register>() |
| 4873 | : destination.AsRegisterPairLow<Register>(); |
| 4874 | int mem = source.IsRegisterPair() |
| 4875 | ? destination.GetStackIndex() |
| 4876 | : source.GetStackIndex(); |
| 4877 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4878 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4879 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4880 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4881 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4882 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 4883 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4884 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4885 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4886 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4887 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 4888 | DRegister reg = source.IsFpuRegisterPair() |
| 4889 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 4890 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 4891 | int mem = source.IsFpuRegisterPair() |
| 4892 | ? destination.GetStackIndex() |
| 4893 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4894 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4895 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 4896 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 4897 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 4898 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 4899 | : destination.AsFpuRegister<SRegister>(); |
| 4900 | int mem = source.IsFpuRegister() |
| 4901 | ? destination.GetStackIndex() |
| 4902 | : source.GetStackIndex(); |
| 4903 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4904 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 4905 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 4906 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4907 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4908 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 4909 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4910 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 4911 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 4916 | __ Push(static_cast<Register>(reg)); |
| 4917 | } |
| 4918 | |
| 4919 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 4920 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4921 | } |
| 4922 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4923 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4924 | InvokeRuntimeCallingConvention calling_convention; |
| 4925 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4926 | cls, |
| 4927 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4928 | Location::RegisterLocation(R0), |
| 4929 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4933 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4934 | if (cls->NeedsAccessCheck()) { |
| 4935 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 4936 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4937 | cls, |
| 4938 | cls->GetDexPc(), |
| 4939 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4940 | return; |
| 4941 | } |
| 4942 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4943 | Location out_loc = locations->Out(); |
| 4944 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4945 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4946 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4947 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4948 | DCHECK(!cls->CanCallRuntime()); |
| 4949 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4950 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 4951 | if (kEmitCompilerReadBarrier) { |
| 4952 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 4953 | __ AddConstant(out, current_method, declaring_class_offset); |
| 4954 | // /* mirror::Class* */ out = out->Read() |
| 4955 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 4956 | } else { |
| 4957 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4958 | __ LoadFromOffset(kLoadWord, out, current_method, declaring_class_offset); |
| 4959 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4960 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4961 | DCHECK(cls->CanCallRuntime()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4962 | // /* GcRoot<mirror::Class>[] */ out = |
| 4963 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4964 | __ LoadFromOffset(kLoadWord, |
| 4965 | out, |
| 4966 | current_method, |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4967 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4968 | |
| 4969 | size_t cache_offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 4970 | if (kEmitCompilerReadBarrier) { |
| 4971 | // /* GcRoot<mirror::Class>* */ out = &out[type_index] |
| 4972 | __ AddConstant(out, out, cache_offset); |
| 4973 | // /* mirror::Class* */ out = out->Read() |
| 4974 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 4975 | } else { |
| 4976 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 4977 | __ LoadFromOffset(kLoadWord, out, out, cache_offset); |
| 4978 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4979 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4980 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4981 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4982 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4983 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4984 | if (cls->MustGenerateClinitCheck()) { |
| 4985 | GenerateClassInitializationCheck(slow_path, out); |
| 4986 | } else { |
| 4987 | __ Bind(slow_path->GetExitLabel()); |
| 4988 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 4993 | LocationSummary* locations = |
| 4994 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4995 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4996 | if (check->HasUses()) { |
| 4997 | locations->SetOut(Location::SameAsFirstInput()); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5002 | // We assume the class is not null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5003 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5004 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5005 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5006 | GenerateClassInitializationCheck(slow_path, |
| 5007 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5008 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5009 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5010 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5011 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5012 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5013 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5014 | __ b(slow_path->GetEntryLabel(), LT); |
| 5015 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5016 | // properly. Therefore, we do a memory fence. |
| 5017 | __ dmb(ISH); |
| 5018 | __ Bind(slow_path->GetExitLabel()); |
| 5019 | } |
| 5020 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5021 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 5022 | LocationSummary* locations = |
| 5023 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5024 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5025 | locations->SetOut(Location::RequiresRegister()); |
| 5026 | } |
| 5027 | |
| 5028 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5029 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5030 | codegen_->AddSlowPath(slow_path); |
| 5031 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5032 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5033 | Location out_loc = locations->Out(); |
| 5034 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5035 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5036 | |
| 5037 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 5038 | if (kEmitCompilerReadBarrier) { |
| 5039 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 5040 | __ AddConstant(out, current_method, declaring_class_offset); |
| 5041 | // /* mirror::Class* */ out = out->Read() |
| 5042 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 5043 | } else { |
| 5044 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5045 | __ LoadFromOffset(kLoadWord, out, current_method, declaring_class_offset); |
| 5046 | } |
| 5047 | |
| 5048 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5049 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5050 | |
| 5051 | size_t cache_offset = CodeGenerator::GetCacheOffset(load->GetStringIndex()); |
| 5052 | if (kEmitCompilerReadBarrier) { |
| 5053 | // /* GcRoot<mirror::String>* */ out = &out[string_index] |
| 5054 | __ AddConstant(out, out, cache_offset); |
| 5055 | // /* mirror::String* */ out = out->Read() |
| 5056 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 5057 | } else { |
| 5058 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5059 | __ LoadFromOffset(kLoadWord, out, out, cache_offset); |
| 5060 | } |
| 5061 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5062 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5063 | __ Bind(slow_path->GetExitLabel()); |
| 5064 | } |
| 5065 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5066 | static int32_t GetExceptionTlsOffset() { |
| 5067 | return Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 5068 | } |
| 5069 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5070 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 5071 | LocationSummary* locations = |
| 5072 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5073 | locations->SetOut(Location::RequiresRegister()); |
| 5074 | } |
| 5075 | |
| 5076 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5077 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5078 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 5079 | } |
| 5080 | |
| 5081 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 5082 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5083 | } |
| 5084 | |
| 5085 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5086 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5087 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 5091 | LocationSummary* locations = |
| 5092 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5093 | InvokeRuntimeCallingConvention calling_convention; |
| 5094 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5095 | } |
| 5096 | |
| 5097 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 5098 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5099 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5100 | } |
| 5101 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5102 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5103 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5104 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5105 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5106 | case TypeCheckKind::kExactCheck: |
| 5107 | case TypeCheckKind::kAbstractClassCheck: |
| 5108 | case TypeCheckKind::kClassHierarchyCheck: |
| 5109 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5110 | call_kind = |
| 5111 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5112 | break; |
| 5113 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5114 | case TypeCheckKind::kUnresolvedCheck: |
| 5115 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5116 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5117 | break; |
| 5118 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5119 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5120 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5122 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5123 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 5124 | // Note that TypeCheckSlowPathARM uses this register too. |
| 5125 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5126 | // When read barriers are enabled, we need a temporary register for |
| 5127 | // some cases. |
| 5128 | if (kEmitCompilerReadBarrier && |
| 5129 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5130 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5131 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 5132 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5133 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5134 | } |
| 5135 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5136 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5137 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5138 | Location obj_loc = locations->InAt(0); |
| 5139 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5140 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5141 | Location out_loc = locations->Out(); |
| 5142 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5143 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5144 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5145 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5146 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5147 | Label done, zero; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5148 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5149 | |
| 5150 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5151 | // avoid null check if we know obj is not null. |
| 5152 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 5153 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5154 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5155 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5156 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5157 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
| 5158 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5159 | |
| 5160 | switch (instruction->GetTypeCheckKind()) { |
| 5161 | case TypeCheckKind::kExactCheck: { |
| 5162 | __ cmp(out, ShifterOperand(cls)); |
| 5163 | // Classes must be equal for the instanceof to succeed. |
| 5164 | __ b(&zero, NE); |
| 5165 | __ LoadImmediate(out, 1); |
| 5166 | __ b(&done); |
| 5167 | break; |
| 5168 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5169 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5170 | case TypeCheckKind::kAbstractClassCheck: { |
| 5171 | // If the class is abstract, we eagerly fetch the super class of the |
| 5172 | // object to avoid doing a comparison we know will fail. |
| 5173 | Label loop; |
| 5174 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5175 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5176 | if (kEmitCompilerReadBarrier) { |
| 5177 | // Save the value of `out` into `temp` before overwriting it |
| 5178 | // in the following move operation, as we will need it for the |
| 5179 | // read barrier below. |
| 5180 | Register temp = temp_loc.AsRegister<Register>(); |
| 5181 | __ Mov(temp, out); |
| 5182 | } |
| 5183 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5184 | __ LoadFromOffset(kLoadWord, out, out, super_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5185 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5186 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5187 | __ CompareAndBranchIfZero(out, &done); |
| 5188 | __ cmp(out, ShifterOperand(cls)); |
| 5189 | __ b(&loop, NE); |
| 5190 | __ LoadImmediate(out, 1); |
| 5191 | if (zero.IsLinked()) { |
| 5192 | __ b(&done); |
| 5193 | } |
| 5194 | break; |
| 5195 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5196 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5197 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5198 | // Walk over the class hierarchy to find a match. |
| 5199 | Label loop, success; |
| 5200 | __ Bind(&loop); |
| 5201 | __ cmp(out, ShifterOperand(cls)); |
| 5202 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5203 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5204 | if (kEmitCompilerReadBarrier) { |
| 5205 | // Save the value of `out` into `temp` before overwriting it |
| 5206 | // in the following move operation, as we will need it for the |
| 5207 | // read barrier below. |
| 5208 | Register temp = temp_loc.AsRegister<Register>(); |
| 5209 | __ Mov(temp, out); |
| 5210 | } |
| 5211 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5212 | __ LoadFromOffset(kLoadWord, out, out, super_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5213 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5214 | __ CompareAndBranchIfNonZero(out, &loop); |
| 5215 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5216 | __ b(&done); |
| 5217 | __ Bind(&success); |
| 5218 | __ LoadImmediate(out, 1); |
| 5219 | if (zero.IsLinked()) { |
| 5220 | __ b(&done); |
| 5221 | } |
| 5222 | break; |
| 5223 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5224 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5225 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5226 | // Do an exact check. |
| 5227 | Label exact_check; |
| 5228 | __ cmp(out, ShifterOperand(cls)); |
| 5229 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5230 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5231 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5232 | if (kEmitCompilerReadBarrier) { |
| 5233 | // Save the value of `out` into `temp` before overwriting it |
| 5234 | // in the following move operation, as we will need it for the |
| 5235 | // read barrier below. |
| 5236 | Register temp = temp_loc.AsRegister<Register>(); |
| 5237 | __ Mov(temp, out); |
| 5238 | } |
| 5239 | // /* HeapReference<Class> */ out = out->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5240 | __ LoadFromOffset(kLoadWord, out, out, component_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5241 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, component_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5242 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5243 | __ CompareAndBranchIfZero(out, &done); |
| 5244 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 5245 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 5246 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5247 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5248 | __ LoadImmediate(out, 1); |
| 5249 | __ b(&done); |
| 5250 | break; |
| 5251 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5252 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5253 | case TypeCheckKind::kArrayCheck: { |
| 5254 | __ cmp(out, ShifterOperand(cls)); |
| 5255 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5256 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5257 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5258 | codegen_->AddSlowPath(slow_path); |
| 5259 | __ b(slow_path->GetEntryLabel(), NE); |
| 5260 | __ LoadImmediate(out, 1); |
| 5261 | if (zero.IsLinked()) { |
| 5262 | __ b(&done); |
| 5263 | } |
| 5264 | break; |
| 5265 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5266 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5267 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5268 | case TypeCheckKind::kInterfaceCheck: { |
| 5269 | // Note that we indeed only call on slow path, but we always go |
| 5270 | // into the slow path for the unresolved & interface check |
| 5271 | // cases. |
| 5272 | // |
| 5273 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5274 | // entry point without resorting to a type checking slow path |
| 5275 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5276 | // require to assign fixed registers for the inputs of this |
| 5277 | // HInstanceOf instruction (following the runtime calling |
| 5278 | // convention), which might be cluttered by the potential first |
| 5279 | // read barrier emission at the beginning of this method. |
| 5280 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5281 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5282 | /* is_fatal */ false); |
| 5283 | codegen_->AddSlowPath(slow_path); |
| 5284 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5285 | if (zero.IsLinked()) { |
| 5286 | __ b(&done); |
| 5287 | } |
| 5288 | break; |
| 5289 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5290 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5291 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5292 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5293 | __ Bind(&zero); |
| 5294 | __ LoadImmediate(out, 0); |
| 5295 | } |
| 5296 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5297 | if (done.IsLinked()) { |
| 5298 | __ Bind(&done); |
| 5299 | } |
| 5300 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5301 | if (slow_path != nullptr) { |
| 5302 | __ Bind(slow_path->GetExitLabel()); |
| 5303 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5304 | } |
| 5305 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5306 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5307 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5308 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5309 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5310 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5311 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5312 | case TypeCheckKind::kExactCheck: |
| 5313 | case TypeCheckKind::kAbstractClassCheck: |
| 5314 | case TypeCheckKind::kClassHierarchyCheck: |
| 5315 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5316 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5317 | LocationSummary::kCallOnSlowPath : |
| 5318 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5319 | break; |
| 5320 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5321 | case TypeCheckKind::kUnresolvedCheck: |
| 5322 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5323 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5324 | break; |
| 5325 | } |
| 5326 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5327 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5328 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5329 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5330 | // Note that TypeCheckSlowPathARM uses this "temp" register too. |
| 5331 | locations->AddTemp(Location::RequiresRegister()); |
| 5332 | // When read barriers are enabled, we need an additional temporary |
| 5333 | // register for some cases. |
| 5334 | if (kEmitCompilerReadBarrier && |
| 5335 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5336 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5337 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5338 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5339 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 5343 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5344 | Location obj_loc = locations->InAt(0); |
| 5345 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5346 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5347 | Location temp_loc = locations->GetTemp(0); |
| 5348 | Register temp = temp_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5349 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5350 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5351 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5352 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5353 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5354 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5355 | bool is_type_check_slow_path_fatal = |
| 5356 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5357 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5358 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5359 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5360 | !instruction->CanThrowIntoCatchBlock(); |
| 5361 | SlowPathCode* type_check_slow_path = |
| 5362 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 5363 | is_type_check_slow_path_fatal); |
| 5364 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5365 | |
| 5366 | Label done; |
| 5367 | // Avoid null check if we know obj is not null. |
| 5368 | if (instruction->MustDoNullCheck()) { |
| 5369 | __ CompareAndBranchIfZero(obj, &done); |
| 5370 | } |
| 5371 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5372 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5373 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 5374 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5375 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5376 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5377 | case TypeCheckKind::kExactCheck: |
| 5378 | case TypeCheckKind::kArrayCheck: { |
| 5379 | __ cmp(temp, ShifterOperand(cls)); |
| 5380 | // Jump to slow path for throwing the exception or doing a |
| 5381 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5382 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5383 | break; |
| 5384 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5385 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5386 | case TypeCheckKind::kAbstractClassCheck: { |
| 5387 | // If the class is abstract, we eagerly fetch the super class of the |
| 5388 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5389 | Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5390 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5391 | Location temp2_loc = |
| 5392 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 5393 | if (kEmitCompilerReadBarrier) { |
| 5394 | // Save the value of `temp` into `temp2` before overwriting it |
| 5395 | // in the following move operation, as we will need it for the |
| 5396 | // read barrier below. |
| 5397 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 5398 | __ Mov(temp2, temp); |
| 5399 | } |
| 5400 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5401 | __ LoadFromOffset(kLoadWord, temp, temp, super_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5402 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 5403 | |
| 5404 | // If the class reference currently in `temp` is not null, jump |
| 5405 | // to the `compare_classes` label to compare it with the checked |
| 5406 | // class. |
| 5407 | __ CompareAndBranchIfNonZero(temp, &compare_classes); |
| 5408 | // Otherwise, jump to the slow path to throw the exception. |
| 5409 | // |
| 5410 | // But before, move back the object's class into `temp` before |
| 5411 | // going into the slow path, as it has been overwritten in the |
| 5412 | // meantime. |
| 5413 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5414 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 5415 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5416 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5417 | |
| 5418 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5419 | __ cmp(temp, ShifterOperand(cls)); |
| 5420 | __ b(&loop, NE); |
| 5421 | break; |
| 5422 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5423 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5424 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5425 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5426 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5427 | __ Bind(&loop); |
| 5428 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5429 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5430 | |
| 5431 | Location temp2_loc = |
| 5432 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 5433 | if (kEmitCompilerReadBarrier) { |
| 5434 | // Save the value of `temp` into `temp2` before overwriting it |
| 5435 | // in the following move operation, as we will need it for the |
| 5436 | // read barrier below. |
| 5437 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 5438 | __ Mov(temp2, temp); |
| 5439 | } |
| 5440 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5441 | __ LoadFromOffset(kLoadWord, temp, temp, super_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5442 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 5443 | |
| 5444 | // If the class reference currently in `temp` is not null, jump |
| 5445 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5446 | __ CompareAndBranchIfNonZero(temp, &loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5447 | // Otherwise, jump to the slow path to throw the exception. |
| 5448 | // |
| 5449 | // But before, move back the object's class into `temp` before |
| 5450 | // going into the slow path, as it has been overwritten in the |
| 5451 | // meantime. |
| 5452 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5453 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 5454 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5455 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5456 | break; |
| 5457 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5458 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5459 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5460 | // Do an exact check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5461 | Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5462 | __ cmp(temp, ShifterOperand(cls)); |
| 5463 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5464 | |
| 5465 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5466 | Location temp2_loc = |
| 5467 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 5468 | if (kEmitCompilerReadBarrier) { |
| 5469 | // Save the value of `temp` into `temp2` before overwriting it |
| 5470 | // in the following move operation, as we will need it for the |
| 5471 | // read barrier below. |
| 5472 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 5473 | __ Mov(temp2, temp); |
| 5474 | } |
| 5475 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5476 | __ LoadFromOffset(kLoadWord, temp, temp, component_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5477 | codegen_->MaybeGenerateReadBarrier( |
| 5478 | instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5479 | |
| 5480 | // If the component type is not null (i.e. the object is indeed |
| 5481 | // an array), jump to label `check_non_primitive_component_type` |
| 5482 | // to further check that this component type is not a primitive |
| 5483 | // type. |
| 5484 | __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type); |
| 5485 | // Otherwise, jump to the slow path to throw the exception. |
| 5486 | // |
| 5487 | // But before, move back the object's class into `temp` before |
| 5488 | // going into the slow path, as it has been overwritten in the |
| 5489 | // meantime. |
| 5490 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5491 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 5492 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5493 | __ b(type_check_slow_path->GetEntryLabel()); |
| 5494 | |
| 5495 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5496 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5497 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
| 5498 | __ CompareAndBranchIfZero(temp, &done); |
| 5499 | // Same comment as above regarding `temp` and the slow path. |
| 5500 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5501 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 5502 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 5503 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5504 | break; |
| 5505 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5506 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5507 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5508 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5509 | // We always go into the type check slow path for the unresolved & |
| 5510 | // interface check cases. |
| 5511 | // |
| 5512 | // We cannot directly call the CheckCast runtime entry point |
| 5513 | // without resorting to a type checking slow path here (i.e. by |
| 5514 | // calling InvokeRuntime directly), as it would require to |
| 5515 | // assign fixed registers for the inputs of this HInstanceOf |
| 5516 | // instruction (following the runtime calling convention), which |
| 5517 | // might be cluttered by the potential first read barrier |
| 5518 | // emission at the beginning of this method. |
| 5519 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5520 | break; |
| 5521 | } |
| 5522 | __ Bind(&done); |
| 5523 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5524 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5527 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5528 | LocationSummary* locations = |
| 5529 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5530 | InvokeRuntimeCallingConvention calling_convention; |
| 5531 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5532 | } |
| 5533 | |
| 5534 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5535 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 5536 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 5537 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 5538 | instruction->GetDexPc(), |
| 5539 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5542 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 5543 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 5544 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5545 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5546 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5547 | LocationSummary* locations = |
| 5548 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5549 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5550 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5551 | // 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] | 5552 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5553 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5554 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 5558 | HandleBitwiseOperation(instruction); |
| 5559 | } |
| 5560 | |
| 5561 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 5562 | HandleBitwiseOperation(instruction); |
| 5563 | } |
| 5564 | |
| 5565 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 5566 | HandleBitwiseOperation(instruction); |
| 5567 | } |
| 5568 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5569 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 5570 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 5571 | if (value == 0xffffffffu) { |
| 5572 | if (out != first) { |
| 5573 | __ mov(out, ShifterOperand(first)); |
| 5574 | } |
| 5575 | return; |
| 5576 | } |
| 5577 | if (value == 0u) { |
| 5578 | __ mov(out, ShifterOperand(0)); |
| 5579 | return; |
| 5580 | } |
| 5581 | ShifterOperand so; |
| 5582 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 5583 | __ and_(out, first, so); |
| 5584 | } else { |
| 5585 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 5586 | __ bic(out, first, ShifterOperand(~value)); |
| 5587 | } |
| 5588 | } |
| 5589 | |
| 5590 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 5591 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 5592 | if (value == 0u) { |
| 5593 | if (out != first) { |
| 5594 | __ mov(out, ShifterOperand(first)); |
| 5595 | } |
| 5596 | return; |
| 5597 | } |
| 5598 | if (value == 0xffffffffu) { |
| 5599 | __ mvn(out, ShifterOperand(0)); |
| 5600 | return; |
| 5601 | } |
| 5602 | ShifterOperand so; |
| 5603 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 5604 | __ orr(out, first, so); |
| 5605 | } else { |
| 5606 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 5607 | __ orn(out, first, ShifterOperand(~value)); |
| 5608 | } |
| 5609 | } |
| 5610 | |
| 5611 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 5612 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 5613 | if (value == 0u) { |
| 5614 | if (out != first) { |
| 5615 | __ mov(out, ShifterOperand(first)); |
| 5616 | } |
| 5617 | return; |
| 5618 | } |
| 5619 | __ eor(out, first, ShifterOperand(value)); |
| 5620 | } |
| 5621 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5622 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5623 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5624 | Location first = locations->InAt(0); |
| 5625 | Location second = locations->InAt(1); |
| 5626 | Location out = locations->Out(); |
| 5627 | |
| 5628 | if (second.IsConstant()) { |
| 5629 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 5630 | uint32_t value_low = Low32Bits(value); |
| 5631 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5632 | Register first_reg = first.AsRegister<Register>(); |
| 5633 | Register out_reg = out.AsRegister<Register>(); |
| 5634 | if (instruction->IsAnd()) { |
| 5635 | GenerateAndConst(out_reg, first_reg, value_low); |
| 5636 | } else if (instruction->IsOr()) { |
| 5637 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 5638 | } else { |
| 5639 | DCHECK(instruction->IsXor()); |
| 5640 | GenerateEorConst(out_reg, first_reg, value_low); |
| 5641 | } |
| 5642 | } else { |
| 5643 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5644 | uint32_t value_high = High32Bits(value); |
| 5645 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5646 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5647 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5648 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 5649 | if (instruction->IsAnd()) { |
| 5650 | GenerateAndConst(out_low, first_low, value_low); |
| 5651 | GenerateAndConst(out_high, first_high, value_high); |
| 5652 | } else if (instruction->IsOr()) { |
| 5653 | GenerateOrrConst(out_low, first_low, value_low); |
| 5654 | GenerateOrrConst(out_high, first_high, value_high); |
| 5655 | } else { |
| 5656 | DCHECK(instruction->IsXor()); |
| 5657 | GenerateEorConst(out_low, first_low, value_low); |
| 5658 | GenerateEorConst(out_high, first_high, value_high); |
| 5659 | } |
| 5660 | } |
| 5661 | return; |
| 5662 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5663 | |
| 5664 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5665 | Register first_reg = first.AsRegister<Register>(); |
| 5666 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 5667 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5668 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5669 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5670 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5671 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5672 | } else { |
| 5673 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5674 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5675 | } |
| 5676 | } else { |
| 5677 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5678 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5679 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 5680 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 5681 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 5682 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 5683 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5684 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5685 | __ and_(out_low, first_low, second_low); |
| 5686 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5687 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5688 | __ orr(out_low, first_low, second_low); |
| 5689 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5690 | } else { |
| 5691 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5692 | __ eor(out_low, first_low, second_low); |
| 5693 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5694 | } |
| 5695 | } |
| 5696 | } |
| 5697 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5698 | void CodeGeneratorARM::GenerateReadBarrier(HInstruction* instruction, |
| 5699 | Location out, |
| 5700 | Location ref, |
| 5701 | Location obj, |
| 5702 | uint32_t offset, |
| 5703 | Location index) { |
| 5704 | DCHECK(kEmitCompilerReadBarrier); |
| 5705 | |
| 5706 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5707 | // reference will be carried out by the runtime within the slow |
| 5708 | // path. |
| 5709 | // |
| 5710 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5711 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5712 | // not used by the artReadBarrierSlow entry point. |
| 5713 | // |
| 5714 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5715 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 5716 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 5717 | AddSlowPath(slow_path); |
| 5718 | |
| 5719 | // TODO: When read barrier has a fast path, add it here. |
| 5720 | /* Currently the read barrier call is inserted after the original load. |
| 5721 | * However, if we have a fast path, we need to perform the load of obj.LockWord *before* the |
| 5722 | * original load. This load-load ordering is required by the read barrier. |
| 5723 | * The fast path/slow path (for Baker's algorithm) should look like: |
| 5724 | * |
| 5725 | * bool isGray = obj.LockWord & kReadBarrierMask; |
| 5726 | * lfence; // load fence or artificial data dependence to prevent load-load reordering |
| 5727 | * ref = obj.field; // this is the original load |
| 5728 | * if (isGray) { |
| 5729 | * ref = Mark(ref); // ideally the slow path just does Mark(ref) |
| 5730 | * } |
| 5731 | */ |
| 5732 | |
| 5733 | __ b(slow_path->GetEntryLabel()); |
| 5734 | __ Bind(slow_path->GetExitLabel()); |
| 5735 | } |
| 5736 | |
| 5737 | void CodeGeneratorARM::MaybeGenerateReadBarrier(HInstruction* instruction, |
| 5738 | Location out, |
| 5739 | Location ref, |
| 5740 | Location obj, |
| 5741 | uint32_t offset, |
| 5742 | Location index) { |
| 5743 | if (kEmitCompilerReadBarrier) { |
| 5744 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5745 | // by the runtime within the slow path. |
| 5746 | GenerateReadBarrier(instruction, out, ref, obj, offset, index); |
| 5747 | } else if (kPoisonHeapReferences) { |
| 5748 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | void CodeGeneratorARM::GenerateReadBarrierForRoot(HInstruction* instruction, |
| 5753 | Location out, |
| 5754 | Location root) { |
| 5755 | DCHECK(kEmitCompilerReadBarrier); |
| 5756 | |
| 5757 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5758 | // not need to do anything special for this here. |
| 5759 | SlowPathCode* slow_path = |
| 5760 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 5761 | AddSlowPath(slow_path); |
| 5762 | |
| 5763 | // TODO: Implement a fast path for ReadBarrierForRoot, performing |
| 5764 | // the following operation (for Baker's algorithm): |
| 5765 | // |
| 5766 | // if (thread.tls32_.is_gc_marking) { |
| 5767 | // root = Mark(root); |
| 5768 | // } |
| 5769 | |
| 5770 | __ b(slow_path->GetEntryLabel()); |
| 5771 | __ Bind(slow_path->GetExitLabel()); |
| 5772 | } |
| 5773 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5774 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 5775 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 5776 | MethodReference target_method) { |
| 5777 | if (desired_dispatch_info.method_load_kind == |
| 5778 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative) { |
| 5779 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 5780 | return HInvokeStaticOrDirect::DispatchInfo { |
| 5781 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 5782 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 5783 | 0u, |
| 5784 | 0u |
| 5785 | }; |
| 5786 | } |
| 5787 | if (desired_dispatch_info.code_ptr_location == |
| 5788 | HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
| 5789 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 5790 | if (&outer_dex_file != target_method.dex_file) { |
| 5791 | // Calls across dex files are more likely to exceed the available BL range, |
| 5792 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 5793 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 5794 | (desired_dispatch_info.method_load_kind == |
| 5795 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 5796 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 5797 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 5798 | return HInvokeStaticOrDirect::DispatchInfo { |
| 5799 | desired_dispatch_info.method_load_kind, |
| 5800 | code_ptr_location, |
| 5801 | desired_dispatch_info.method_load_data, |
| 5802 | 0u |
| 5803 | }; |
| 5804 | } |
| 5805 | } |
| 5806 | return desired_dispatch_info; |
| 5807 | } |
| 5808 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5809 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5810 | // 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] | 5811 | switch (invoke->GetCodePtrLocation()) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5812 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5813 | // LR = code address from literal pool with link-time patch. |
| 5814 | __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5815 | break; |
| 5816 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5817 | // LR = invoke->GetDirectCodePtr(); |
| 5818 | __ LoadImmediate(LR, invoke->GetDirectCodePtr()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5819 | break; |
| 5820 | default: |
| 5821 | break; |
| 5822 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5823 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5824 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5825 | switch (invoke->GetMethodLoadKind()) { |
| 5826 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 5827 | // temp = thread->string_init_entrypoint |
| 5828 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset()); |
| 5829 | break; |
| 5830 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 5831 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 5832 | break; |
| 5833 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 5834 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 5835 | break; |
| 5836 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 5837 | __ LoadLiteral(temp.AsRegister<Register>(), |
| 5838 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 5839 | break; |
| 5840 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5841 | // TODO: Implement this type. |
| 5842 | // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 5843 | LOG(FATAL) << "Unsupported"; |
| 5844 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5845 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 5846 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 5847 | Register method_reg; |
| 5848 | Register reg = temp.AsRegister<Register>(); |
| 5849 | if (current_method.IsRegister()) { |
| 5850 | method_reg = current_method.AsRegister<Register>(); |
| 5851 | } else { |
| 5852 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 5853 | DCHECK(!current_method.IsValid()); |
| 5854 | method_reg = reg; |
| 5855 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 5856 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5857 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 5858 | __ LoadFromOffset(kLoadWord, |
| 5859 | reg, |
| 5860 | method_reg, |
| 5861 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5862 | // temp = temp[index_in_cache] |
| 5863 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 5864 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 5865 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 5866 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | switch (invoke->GetCodePtrLocation()) { |
| 5870 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 5871 | __ bl(GetFrameEntryLabel()); |
| 5872 | break; |
| 5873 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5874 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 5875 | __ BindTrackedLabel(&relative_call_patches_.back().label); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5876 | // Arbitrarily branch to the BL itself, override at link time. |
| 5877 | __ bl(&relative_call_patches_.back().label); |
| 5878 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5879 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 5880 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 5881 | // LR prepared above for better instruction scheduling. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5882 | // LR() |
| 5883 | __ blx(LR); |
| 5884 | break; |
| 5885 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5886 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 5887 | __ LoadFromOffset( |
| 5888 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
| 5889 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value()); |
| 5890 | // LR() |
| 5891 | __ blx(LR); |
| 5892 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5893 | } |
| 5894 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 5895 | DCHECK(!IsLeafMethod()); |
| 5896 | } |
| 5897 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5898 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 5899 | Register temp = temp_location.AsRegister<Register>(); |
| 5900 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5901 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 5902 | LocationSummary* locations = invoke->GetLocations(); |
| 5903 | Location receiver = locations->InAt(0); |
| 5904 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5905 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5906 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5907 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
| 5908 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5909 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5910 | // emit a read barrier for the previous class reference load. |
| 5911 | // However this is not required in practice, as this is an |
| 5912 | // intermediate/temporary reference and because the current |
| 5913 | // concurrent copying collector keeps the from-space memory |
| 5914 | // intact/accessible until the end of the marking phase (the |
| 5915 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5916 | __ MaybeUnpoisonHeapReference(temp); |
| 5917 | // temp = temp->GetMethodAt(method_offset); |
| 5918 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5919 | kArmWordSize).Int32Value(); |
| 5920 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 5921 | // LR = temp->GetEntryPoint(); |
| 5922 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 5923 | // LR(); |
| 5924 | __ blx(LR); |
| 5925 | } |
| 5926 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5927 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 5928 | DCHECK(linker_patches->empty()); |
| 5929 | size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size(); |
| 5930 | linker_patches->reserve(size); |
| 5931 | for (const auto& entry : method_patches_) { |
| 5932 | const MethodReference& target_method = entry.first; |
| 5933 | Literal* literal = entry.second; |
| 5934 | DCHECK(literal->GetLabel()->IsBound()); |
| 5935 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 5936 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 5937 | target_method.dex_file, |
| 5938 | target_method.dex_method_index)); |
| 5939 | } |
| 5940 | for (const auto& entry : call_patches_) { |
| 5941 | const MethodReference& target_method = entry.first; |
| 5942 | Literal* literal = entry.second; |
| 5943 | DCHECK(literal->GetLabel()->IsBound()); |
| 5944 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 5945 | linker_patches->push_back(LinkerPatch::CodePatch(literal_offset, |
| 5946 | target_method.dex_file, |
| 5947 | target_method.dex_method_index)); |
| 5948 | } |
| 5949 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 5950 | uint32_t literal_offset = info.label.Position(); |
| 5951 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 5952 | info.target_method.dex_file, |
| 5953 | info.target_method.dex_method_index)); |
| 5954 | } |
| 5955 | } |
| 5956 | |
| 5957 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 5958 | MethodToLiteralMap* map) { |
| 5959 | // Look up the literal for target_method. |
| 5960 | auto lb = map->lower_bound(target_method); |
| 5961 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 5962 | return lb->second; |
| 5963 | } |
| 5964 | // We don't have a literal for this method yet, insert a new one. |
| 5965 | Literal* literal = __ NewLiteral<uint32_t>(0u); |
| 5966 | map->PutBefore(lb, target_method, literal); |
| 5967 | return literal; |
| 5968 | } |
| 5969 | |
| 5970 | Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) { |
| 5971 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 5972 | } |
| 5973 | |
| 5974 | Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) { |
| 5975 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 5976 | } |
| 5977 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5978 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5979 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5980 | LOG(FATAL) << "Unreachable"; |
| 5981 | } |
| 5982 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5983 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5984 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5985 | LOG(FATAL) << "Unreachable"; |
| 5986 | } |
| 5987 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5988 | void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) { |
| 5989 | DCHECK(codegen_->IsBaseline()); |
| 5990 | LocationSummary* locations = |
| 5991 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5992 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5993 | } |
| 5994 | |
| 5995 | void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5996 | DCHECK(codegen_->IsBaseline()); |
| 5997 | // Will be generated at use site. |
| 5998 | } |
| 5999 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6000 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6001 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6002 | LocationSummary* locations = |
| 6003 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6004 | locations->SetInAt(0, Location::RequiresRegister()); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6005 | if (switch_instr->GetNumEntries() >= kPackedSwitchJumpTableThreshold && |
| 6006 | codegen_->GetAssembler()->IsThumb()) { |
| 6007 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 6008 | if (switch_instr->GetStartValue() != 0) { |
| 6009 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 6010 | } |
| 6011 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6015 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6016 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6017 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6018 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6019 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6020 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6021 | if (num_entries < kPackedSwitchJumpTableThreshold || !codegen_->GetAssembler()->IsThumb()) { |
| 6022 | // Create a series of compare/jumps. |
| 6023 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6024 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6025 | GenerateCompareWithImmediate(value_reg, lower_bound + i); |
| 6026 | __ b(codegen_->GetLabelOf(successors[i]), EQ); |
| 6027 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6028 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 6029 | // And the default for any other value. |
| 6030 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6031 | __ b(codegen_->GetLabelOf(default_block)); |
| 6032 | } |
| 6033 | } else { |
| 6034 | // Create a table lookup. |
| 6035 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6036 | |
| 6037 | // Materialize a pointer to the switch table |
| 6038 | std::vector<Label*> labels(num_entries); |
| 6039 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6040 | for (uint32_t i = 0; i < num_entries; i++) { |
| 6041 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 6042 | } |
| 6043 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 6044 | |
| 6045 | // Remove the bias. |
| 6046 | Register key_reg; |
| 6047 | if (lower_bound != 0) { |
| 6048 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 6049 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 6050 | } else { |
| 6051 | key_reg = value_reg; |
| 6052 | } |
| 6053 | |
| 6054 | // Check whether the value is in the table, jump to default block if not. |
| 6055 | __ CmpConstant(key_reg, num_entries - 1); |
| 6056 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 6057 | |
| 6058 | // Load the displacement from the table. |
| 6059 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 6060 | |
| 6061 | // Dispatch is a direct add to the PC (for Thumb2). |
| 6062 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6063 | } |
| 6064 | } |
| 6065 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6066 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6067 | if (!trg.IsValid()) { |
| 6068 | DCHECK(type == Primitive::kPrimVoid); |
| 6069 | return; |
| 6070 | } |
| 6071 | |
| 6072 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6073 | |
| 6074 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 6075 | if (return_loc.Equals(trg)) { |
| 6076 | return; |
| 6077 | } |
| 6078 | |
| 6079 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 6080 | // with the last branch. |
| 6081 | if (type == Primitive::kPrimLong) { |
| 6082 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6083 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 6084 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 6085 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6086 | } else if (type == Primitive::kPrimDouble) { |
| 6087 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6088 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 6089 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 6090 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6091 | } else { |
| 6092 | // Let the parallel move resolver take care of all of this. |
| 6093 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6094 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6095 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6096 | } |
| 6097 | } |
| 6098 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6099 | #undef __ |
| 6100 | #undef QUICK_ENTRY_POINT |
| 6101 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6102 | } // namespace arm |
| 6103 | } // namespace art |