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" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 20 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 21 | #include "gc/accounting/card_table.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 22 | #include "mirror/array-inl.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 23 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 24 | #include "mirror/class.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 26 | #include "utils/arm/assembler_arm.h" |
| 27 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 28 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 29 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 30 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 32 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | namespace arm { |
| 34 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 35 | static DRegister FromLowSToD(SRegister reg) { |
| 36 | DCHECK_EQ(reg % 2, 0); |
| 37 | return static_cast<DRegister>(reg / 2); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 40 | static bool ExpectedPairLayout(Location location) { |
| 41 | // We expected this for both core and fpu register pairs. |
| 42 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 43 | } |
| 44 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | static constexpr int kCurrentMethodStackOffset = 0; |
| 46 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 47 | static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 48 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 49 | arraysize(kRuntimeParameterCoreRegisters); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 50 | static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 }; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 51 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 52 | arraysize(kRuntimeParameterFpuRegisters); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 53 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 54 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | public: |
| 56 | InvokeRuntimeCallingConvention() |
| 57 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 58 | kRuntimeParameterCoreRegistersLength, |
| 59 | kRuntimeParameterFpuRegisters, |
| 60 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 64 | }; |
| 65 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | #define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 67 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 69 | class SlowPathCodeARM : public SlowPathCode { |
| 70 | public: |
| 71 | SlowPathCodeARM() : entry_label_(), exit_label_() {} |
| 72 | |
| 73 | Label* GetEntryLabel() { return &entry_label_; } |
| 74 | Label* GetExitLabel() { return &exit_label_; } |
| 75 | |
| 76 | private: |
| 77 | Label entry_label_; |
| 78 | Label exit_label_; |
| 79 | |
| 80 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM); |
| 81 | }; |
| 82 | |
| 83 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 84 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 85 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 87 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 88 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 89 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 90 | arm_codegen->InvokeRuntime( |
| 91 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 95 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 97 | }; |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
| 100 | public: |
| 101 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 102 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 103 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 105 | __ Bind(GetEntryLabel()); |
| 106 | arm_codegen->InvokeRuntime( |
| 107 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc()); |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | HDivZeroCheck* const instruction_; |
| 112 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 113 | }; |
| 114 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 115 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
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 | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 123 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 124 | arm_codegen->InvokeRuntime( |
| 125 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 126 | codegen->RestoreLiveRegisters(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 | |
| 139 | private: |
| 140 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 141 | // If not null, the block to branch to after the suspend check. |
| 142 | HBasicBlock* const successor_; |
| 143 | |
| 144 | // 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] | 145 | Label return_label_; |
| 146 | |
| 147 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 148 | }; |
| 149 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 150 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 151 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 152 | BoundsCheckSlowPathARM(HBoundsCheck* instruction, |
| 153 | Location index_location, |
| 154 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 155 | : instruction_(instruction), |
| 156 | index_location_(index_location), |
| 157 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 159 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 160 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 162 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 163 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 164 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 165 | codegen->EmitParallelMoves( |
| 166 | index_location_, |
| 167 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 168 | length_location_, |
| 169 | Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 170 | arm_codegen->InvokeRuntime( |
| 171 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 175 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | const Location index_location_; |
| 177 | const Location length_location_; |
| 178 | |
| 179 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 180 | }; |
| 181 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 182 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 183 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 184 | LoadClassSlowPathARM(HLoadClass* cls, |
| 185 | HInstruction* at, |
| 186 | uint32_t dex_pc, |
| 187 | bool do_clinit) |
| 188 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 189 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 190 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 191 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 192 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 193 | LocationSummary* locations = at_->GetLocations(); |
| 194 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 195 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 196 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 197 | codegen->SaveLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 198 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 199 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 200 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 201 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 202 | int32_t entry_point_offset = do_clinit_ |
| 203 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 204 | : QUICK_ENTRY_POINT(pInitializeType); |
| 205 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_); |
| 206 | |
| 207 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 208 | Location out = locations->Out(); |
| 209 | if (out.IsValid()) { |
| 210 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 211 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 212 | } |
| 213 | codegen->RestoreLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 214 | __ b(GetExitLabel()); |
| 215 | } |
| 216 | |
| 217 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 218 | // The class this slow path will load. |
| 219 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 220 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 221 | // The instruction where this slow path is happening. |
| 222 | // (Might be the load class or an initialization check). |
| 223 | HInstruction* const at_; |
| 224 | |
| 225 | // The dex PC of `at_`. |
| 226 | const uint32_t dex_pc_; |
| 227 | |
| 228 | // Whether to initialize the class. |
| 229 | const bool do_clinit_; |
| 230 | |
| 231 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | }; |
| 233 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 234 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 235 | public: |
| 236 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 237 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 238 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 239 | LocationSummary* locations = instruction_->GetLocations(); |
| 240 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 241 | |
| 242 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 243 | __ Bind(GetEntryLabel()); |
| 244 | codegen->SaveLiveRegisters(locations); |
| 245 | |
| 246 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 247 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
| 248 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 249 | arm_codegen->InvokeRuntime( |
| 250 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc()); |
| 251 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 252 | |
| 253 | codegen->RestoreLiveRegisters(locations); |
| 254 | __ b(GetExitLabel()); |
| 255 | } |
| 256 | |
| 257 | private: |
| 258 | HLoadString* const instruction_; |
| 259 | |
| 260 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 261 | }; |
| 262 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 263 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
| 264 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 265 | TypeCheckSlowPathARM(HInstruction* instruction, |
| 266 | Location class_to_check, |
| 267 | Location object_class, |
| 268 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 269 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 270 | class_to_check_(class_to_check), |
| 271 | object_class_(object_class), |
| 272 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 273 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 274 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 275 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 276 | DCHECK(instruction_->IsCheckCast() |
| 277 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 278 | |
| 279 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 280 | __ Bind(GetEntryLabel()); |
| 281 | codegen->SaveLiveRegisters(locations); |
| 282 | |
| 283 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 284 | // move resolver. |
| 285 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 286 | codegen->EmitParallelMoves( |
| 287 | class_to_check_, |
| 288 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 289 | object_class_, |
| 290 | Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 292 | if (instruction_->IsInstanceOf()) { |
| 293 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_); |
| 294 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 295 | } else { |
| 296 | DCHECK(instruction_->IsCheckCast()); |
| 297 | arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_); |
| 298 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
| 300 | codegen->RestoreLiveRegisters(locations); |
| 301 | __ b(GetExitLabel()); |
| 302 | } |
| 303 | |
| 304 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 305 | HInstruction* const instruction_; |
| 306 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 307 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 308 | uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | |
| 310 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 311 | }; |
| 312 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 313 | #undef __ |
| 314 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 315 | #undef __ |
| 316 | #define __ reinterpret_cast<ArmAssembler*>(GetAssembler())-> |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 317 | |
| 318 | inline Condition ARMCondition(IfCondition cond) { |
| 319 | switch (cond) { |
| 320 | case kCondEQ: return EQ; |
| 321 | case kCondNE: return NE; |
| 322 | case kCondLT: return LT; |
| 323 | case kCondLE: return LE; |
| 324 | case kCondGT: return GT; |
| 325 | case kCondGE: return GE; |
| 326 | default: |
| 327 | LOG(FATAL) << "Unknown if condition"; |
| 328 | } |
| 329 | return EQ; // Unreachable. |
| 330 | } |
| 331 | |
| 332 | inline Condition ARMOppositeCondition(IfCondition cond) { |
| 333 | switch (cond) { |
| 334 | case kCondEQ: return NE; |
| 335 | case kCondNE: return EQ; |
| 336 | case kCondLT: return GE; |
| 337 | case kCondLE: return GT; |
| 338 | case kCondGT: return LE; |
| 339 | case kCondGE: return LT; |
| 340 | default: |
| 341 | LOG(FATAL) << "Unknown if condition"; |
| 342 | } |
| 343 | return EQ; // Unreachable. |
| 344 | } |
| 345 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 346 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 347 | stream << ArmManagedRegister::FromCoreRegister(Register(reg)); |
| 348 | } |
| 349 | |
| 350 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 351 | stream << ArmManagedRegister::FromSRegister(SRegister(reg)); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 354 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 355 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 356 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 359 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 360 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 361 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 364 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 365 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 366 | return kArmWordSize; |
| 367 | } |
| 368 | |
| 369 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 370 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 371 | return kArmWordSize; |
| 372 | } |
| 373 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 374 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 375 | const ArmInstructionSetFeatures& isa_features, |
| 376 | const CompilerOptions& compiler_options) |
| 377 | : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame^] | 378 | kNumberOfRegisterPairs, (1 << R6) | (1 << R7) | (1 << LR), 0, compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 379 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 380 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 381 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 382 | move_resolver_(graph->GetArena(), this), |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 383 | assembler_(true), |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame^] | 384 | isa_features_(isa_features) { |
| 385 | // We unconditionally allocate R6 and R7 to ensure we can do long operations |
| 386 | // with baseline. |
| 387 | AddAllocatedRegister(Location::RegisterLocation(R6)); |
| 388 | AddAllocatedRegister(Location::RegisterLocation(R7)); |
| 389 | // Save the link register to mimic Quick. |
| 390 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 393 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 394 | switch (type) { |
| 395 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 396 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 397 | ArmManagedRegister pair = |
| 398 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 399 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 400 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 401 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 402 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 403 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 404 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 405 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | case Primitive::kPrimByte: |
| 409 | case Primitive::kPrimBoolean: |
| 410 | case Primitive::kPrimChar: |
| 411 | case Primitive::kPrimShort: |
| 412 | case Primitive::kPrimInt: |
| 413 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 414 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 415 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 416 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 417 | ArmManagedRegister current = |
| 418 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 419 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 420 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 421 | } |
| 422 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 423 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 426 | case Primitive::kPrimFloat: { |
| 427 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 428 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 429 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 430 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 431 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 432 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 433 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 434 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 435 | } |
| 436 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 437 | case Primitive::kPrimVoid: |
| 438 | LOG(FATAL) << "Unreachable type " << type; |
| 439 | } |
| 440 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 441 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 444 | void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 445 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 446 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 447 | |
| 448 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 449 | blocked_core_registers_[SP] = true; |
| 450 | blocked_core_registers_[LR] = true; |
| 451 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 452 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 453 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 454 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 455 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 456 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 457 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 458 | |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 459 | // TODO: We currently don't use Quick's callee saved registers. |
| 460 | // We always save and restore R6 and R7 to make sure we can use three |
| 461 | // register pairs for long operations. |
| 462 | blocked_core_registers_[R4] = true; |
| 463 | blocked_core_registers_[R5] = true; |
| 464 | blocked_core_registers_[R8] = true; |
| 465 | blocked_core_registers_[R10] = true; |
| 466 | blocked_core_registers_[R11] = true; |
| 467 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 468 | blocked_fpu_registers_[S16] = true; |
| 469 | blocked_fpu_registers_[S17] = true; |
| 470 | blocked_fpu_registers_[S18] = true; |
| 471 | blocked_fpu_registers_[S19] = true; |
| 472 | blocked_fpu_registers_[S20] = true; |
| 473 | blocked_fpu_registers_[S21] = true; |
| 474 | blocked_fpu_registers_[S22] = true; |
| 475 | blocked_fpu_registers_[S23] = true; |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 476 | blocked_fpu_registers_[S24] = true; |
| 477 | blocked_fpu_registers_[S25] = true; |
| 478 | blocked_fpu_registers_[S26] = true; |
| 479 | blocked_fpu_registers_[S27] = true; |
| 480 | blocked_fpu_registers_[S28] = true; |
| 481 | blocked_fpu_registers_[S29] = true; |
| 482 | blocked_fpu_registers_[S30] = true; |
| 483 | blocked_fpu_registers_[S31] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 484 | |
| 485 | UpdateBlockedPairRegisters(); |
| 486 | } |
| 487 | |
| 488 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 489 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 490 | ArmManagedRegister current = |
| 491 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 492 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 493 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 494 | blocked_register_pairs_[i] = true; |
| 495 | } |
| 496 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 499 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 500 | : HGraphVisitor(graph), |
| 501 | assembler_(codegen->GetAssembler()), |
| 502 | codegen_(codegen) {} |
| 503 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 504 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 505 | bool skip_overflow_check = |
| 506 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame^] | 507 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 508 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame^] | 509 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 510 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 511 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame^] | 514 | __ PushList(core_spill_mask_); |
| 515 | __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize())); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 516 | __ StoreToOffset(kStoreWord, R0, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame^] | 520 | __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize()); |
| 521 | __ PopList((core_spill_mask_ & (~(1 << LR))) | 1 << PC); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 524 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
| 525 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 528 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 529 | switch (load->GetType()) { |
| 530 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 531 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 532 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 533 | break; |
| 534 | |
| 535 | case Primitive::kPrimInt: |
| 536 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 537 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 538 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 539 | |
| 540 | case Primitive::kPrimBoolean: |
| 541 | case Primitive::kPrimByte: |
| 542 | case Primitive::kPrimChar: |
| 543 | case Primitive::kPrimShort: |
| 544 | case Primitive::kPrimVoid: |
| 545 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 546 | } |
| 547 | |
| 548 | LOG(FATAL) << "Unreachable"; |
| 549 | return Location(); |
| 550 | } |
| 551 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 552 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 553 | switch (type) { |
| 554 | case Primitive::kPrimBoolean: |
| 555 | case Primitive::kPrimByte: |
| 556 | case Primitive::kPrimChar: |
| 557 | case Primitive::kPrimShort: |
| 558 | case Primitive::kPrimInt: |
| 559 | case Primitive::kPrimNot: { |
| 560 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 561 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 562 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 563 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 564 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 565 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 566 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 567 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 568 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 569 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 570 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 571 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 572 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 573 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 574 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 575 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 576 | // Skip R1, and use R2_R3 instead. |
| 577 | gp_index_++; |
| 578 | index++; |
| 579 | } |
| 580 | } |
| 581 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 582 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 583 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 584 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 585 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 586 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 587 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | case Primitive::kPrimFloat: { |
| 592 | uint32_t stack_index = stack_index_++; |
| 593 | if (float_index_ % 2 == 0) { |
| 594 | float_index_ = std::max(double_index_, float_index_); |
| 595 | } |
| 596 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 597 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 598 | } else { |
| 599 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | case Primitive::kPrimDouble: { |
| 604 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 605 | uint32_t stack_index = stack_index_; |
| 606 | stack_index_ += 2; |
| 607 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 608 | uint32_t index = double_index_; |
| 609 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 610 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 611 | calling_convention.GetFpuRegisterAt(index), |
| 612 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 613 | DCHECK(ExpectedPairLayout(result)); |
| 614 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 615 | } else { |
| 616 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 620 | case Primitive::kPrimVoid: |
| 621 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 622 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 623 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 624 | return Location(); |
| 625 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 626 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 627 | Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) { |
| 628 | switch (type) { |
| 629 | case Primitive::kPrimBoolean: |
| 630 | case Primitive::kPrimByte: |
| 631 | case Primitive::kPrimChar: |
| 632 | case Primitive::kPrimShort: |
| 633 | case Primitive::kPrimInt: |
| 634 | case Primitive::kPrimNot: { |
| 635 | return Location::RegisterLocation(R0); |
| 636 | } |
| 637 | |
| 638 | case Primitive::kPrimFloat: { |
| 639 | return Location::FpuRegisterLocation(S0); |
| 640 | } |
| 641 | |
| 642 | case Primitive::kPrimLong: { |
| 643 | return Location::RegisterPairLocation(R0, R1); |
| 644 | } |
| 645 | |
| 646 | case Primitive::kPrimDouble: { |
| 647 | return Location::FpuRegisterPairLocation(S0, S1); |
| 648 | } |
| 649 | |
| 650 | case Primitive::kPrimVoid: |
| 651 | return Location(); |
| 652 | } |
| 653 | UNREACHABLE(); |
| 654 | return Location(); |
| 655 | } |
| 656 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 657 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 658 | if (source.Equals(destination)) { |
| 659 | return; |
| 660 | } |
| 661 | if (destination.IsRegister()) { |
| 662 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 663 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 664 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 665 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 666 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 667 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 668 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 669 | } else if (destination.IsFpuRegister()) { |
| 670 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 671 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 672 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 673 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 674 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 675 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 676 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 677 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 678 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 679 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 680 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 681 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 682 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 683 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 684 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 685 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 686 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 692 | if (source.Equals(destination)) { |
| 693 | return; |
| 694 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 695 | if (destination.IsRegisterPair()) { |
| 696 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 697 | EmitParallelMoves( |
| 698 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 699 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| 700 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| 701 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 702 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 703 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 704 | } else { |
| 705 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 706 | DCHECK(ExpectedPairLayout(destination)); |
| 707 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 708 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 709 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 710 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 711 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 712 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 713 | SP, |
| 714 | source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 715 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 716 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 717 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 718 | } else { |
| 719 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 720 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 721 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 722 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 723 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 724 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 725 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 726 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 727 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 728 | SP, destination.GetStackIndex()); |
| 729 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 730 | } else if (source.IsFpuRegisterPair()) { |
| 731 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 732 | SP, |
| 733 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 734 | } else { |
| 735 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 736 | EmitParallelMoves( |
| 737 | Location::StackSlot(source.GetStackIndex()), |
| 738 | Location::StackSlot(destination.GetStackIndex()), |
| 739 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
| 740 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 745 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 746 | LocationSummary* locations = instruction->GetLocations(); |
| 747 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 748 | return; |
| 749 | } |
| 750 | |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 751 | if (locations != nullptr && locations->Out().IsConstant()) { |
| 752 | HConstant* const_to_move = locations->Out().GetConstant(); |
| 753 | if (const_to_move->IsIntConstant()) { |
| 754 | int32_t value = const_to_move->AsIntConstant()->GetValue(); |
| 755 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 756 | __ LoadImmediate(location.AsRegister<Register>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 757 | } else { |
| 758 | DCHECK(location.IsStackSlot()); |
| 759 | __ LoadImmediate(IP, value); |
| 760 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 761 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 762 | } else { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 763 | DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName(); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 764 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 765 | if (location.IsRegisterPair()) { |
| 766 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 767 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
| 768 | } else { |
| 769 | DCHECK(location.IsDoubleStackSlot()); |
| 770 | __ LoadImmediate(IP, Low32Bits(value)); |
| 771 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
| 772 | __ LoadImmediate(IP, High32Bits(value)); |
| 773 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
| 774 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 775 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 776 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 777 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 778 | switch (instruction->GetType()) { |
| 779 | case Primitive::kPrimBoolean: |
| 780 | case Primitive::kPrimByte: |
| 781 | case Primitive::kPrimChar: |
| 782 | case Primitive::kPrimShort: |
| 783 | case Primitive::kPrimInt: |
| 784 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 785 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 786 | Move32(location, Location::StackSlot(stack_slot)); |
| 787 | break; |
| 788 | |
| 789 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 790 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 791 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 792 | break; |
| 793 | |
| 794 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 795 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 796 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 797 | } else if (instruction->IsTemporary()) { |
| 798 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 799 | if (temp_location.IsStackSlot()) { |
| 800 | Move32(location, temp_location); |
| 801 | } else { |
| 802 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 803 | Move64(location, temp_location); |
| 804 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 805 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 806 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 807 | switch (instruction->GetType()) { |
| 808 | case Primitive::kPrimBoolean: |
| 809 | case Primitive::kPrimByte: |
| 810 | case Primitive::kPrimChar: |
| 811 | case Primitive::kPrimShort: |
| 812 | case Primitive::kPrimNot: |
| 813 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 814 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 815 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 816 | break; |
| 817 | |
| 818 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 819 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 820 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 824 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 825 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 829 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 830 | HInstruction* instruction, |
| 831 | uint32_t dex_pc) { |
| 832 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 833 | __ blx(LR); |
| 834 | RecordPcInfo(instruction, dex_pc); |
| 835 | DCHECK(instruction->IsSuspendCheck() |
| 836 | || instruction->IsBoundsCheck() |
| 837 | || instruction->IsNullCheck() |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 838 | || instruction->IsDivZeroCheck() |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 839 | || instruction->GetLocations()->CanCall() |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 840 | || !IsLeafMethod()); |
| 841 | } |
| 842 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 843 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 844 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 847 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 848 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 849 | DCHECK(!successor->IsExitBlock()); |
| 850 | |
| 851 | HBasicBlock* block = got->GetBlock(); |
| 852 | HInstruction* previous = got->GetPrevious(); |
| 853 | |
| 854 | HLoopInformation* info = block->GetLoopInformation(); |
| 855 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 856 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 857 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 862 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 863 | } |
| 864 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 865 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 869 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 870 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 873 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 874 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 875 | if (kIsDebugBuild) { |
| 876 | __ Comment("Unreachable"); |
| 877 | __ bkpt(0); |
| 878 | } |
| 879 | } |
| 880 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 881 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 882 | LocationSummary* locations = |
| 883 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 884 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 885 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 886 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 887 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 890 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 891 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 892 | if (cond->IsIntConstant()) { |
| 893 | // Constant condition, statically compared against 1. |
| 894 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 895 | if (cond_value == 1) { |
| 896 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 897 | if_instr->IfTrueSuccessor())) { |
| 898 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 899 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 900 | return; |
| 901 | } else { |
| 902 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 903 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 904 | } else { |
| 905 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 906 | // Condition has been materialized, compare the output to 0 |
| 907 | DCHECK(if_instr->GetLocations()->InAt(0).IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 908 | __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 909 | ShifterOperand(0)); |
| 910 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE); |
| 911 | } else { |
| 912 | // Condition has not been materialized, use its inputs as the |
| 913 | // comparison and its condition as the branch condition. |
| 914 | LocationSummary* locations = cond->GetLocations(); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 915 | DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 916 | Register left = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 917 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 918 | __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 919 | } else { |
| 920 | DCHECK(locations->InAt(1).IsConstant()); |
| 921 | int32_t value = |
| 922 | locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 923 | ShifterOperand operand; |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 924 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) { |
| 925 | __ cmp(left, operand); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 926 | } else { |
| 927 | Register temp = IP; |
| 928 | __ LoadImmediate(temp, value); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 929 | __ cmp(left, ShifterOperand(temp)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), |
| 933 | ARMCondition(cond->AsCondition()->GetCondition())); |
| 934 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 935 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 936 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 937 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 938 | __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 942 | |
| 943 | void LocationsBuilderARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 944 | LocationSummary* locations = |
| 945 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 946 | locations->SetInAt(0, Location::RequiresRegister()); |
| 947 | locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 948 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 949 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 950 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 953 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 954 | if (!comp->NeedsMaterialization()) return; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 955 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 956 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 957 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 958 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 959 | __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 960 | } else { |
| 961 | DCHECK(locations->InAt(1).IsConstant()); |
| 962 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 963 | ShifterOperand operand; |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 964 | if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) { |
| 965 | __ cmp(left, operand); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 966 | } else { |
| 967 | Register temp = IP; |
| 968 | __ LoadImmediate(temp, value); |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 969 | __ cmp(left, ShifterOperand(temp)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 970 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 971 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 972 | __ it(ARMCondition(comp->GetCondition()), kItElse); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 973 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 974 | ARMCondition(comp->GetCondition())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 975 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 976 | ARMOppositeCondition(comp->GetCondition())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 980 | VisitCondition(comp); |
| 981 | } |
| 982 | |
| 983 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 984 | VisitCondition(comp); |
| 985 | } |
| 986 | |
| 987 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 988 | VisitCondition(comp); |
| 989 | } |
| 990 | |
| 991 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 992 | VisitCondition(comp); |
| 993 | } |
| 994 | |
| 995 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 996 | VisitCondition(comp); |
| 997 | } |
| 998 | |
| 999 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1000 | VisitCondition(comp); |
| 1001 | } |
| 1002 | |
| 1003 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1004 | VisitCondition(comp); |
| 1005 | } |
| 1006 | |
| 1007 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1008 | VisitCondition(comp); |
| 1009 | } |
| 1010 | |
| 1011 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1012 | VisitCondition(comp); |
| 1013 | } |
| 1014 | |
| 1015 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1016 | VisitCondition(comp); |
| 1017 | } |
| 1018 | |
| 1019 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1020 | VisitCondition(comp); |
| 1021 | } |
| 1022 | |
| 1023 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1024 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1028 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1031 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1032 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1035 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1036 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1039 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1040 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1041 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1045 | LocationSummary* locations = |
| 1046 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1047 | switch (store->InputAt(1)->GetType()) { |
| 1048 | case Primitive::kPrimBoolean: |
| 1049 | case Primitive::kPrimByte: |
| 1050 | case Primitive::kPrimChar: |
| 1051 | case Primitive::kPrimShort: |
| 1052 | case Primitive::kPrimInt: |
| 1053 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1054 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1055 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1056 | break; |
| 1057 | |
| 1058 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1059 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1060 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1061 | break; |
| 1062 | |
| 1063 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1064 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1065 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1068 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1069 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1073 | LocationSummary* locations = |
| 1074 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1075 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1078 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1079 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1080 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1083 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1084 | LocationSummary* locations = |
| 1085 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1086 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 1090 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1091 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1094 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1095 | LocationSummary* locations = |
| 1096 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1097 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1098 | } |
| 1099 | |
| 1100 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1101 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1102 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1106 | LocationSummary* locations = |
| 1107 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1108 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1109 | } |
| 1110 | |
| 1111 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1112 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1113 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1116 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1117 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1120 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1121 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1122 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1125 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1126 | LocationSummary* locations = |
| 1127 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1128 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1131 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1132 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1133 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1136 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1137 | HandleInvoke(invoke); |
| 1138 | } |
| 1139 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1140 | void CodeGeneratorARM::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1141 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1144 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1145 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1146 | |
| 1147 | // TODO: Implement all kinds of calls: |
| 1148 | // 1) boot -> boot |
| 1149 | // 2) app -> boot |
| 1150 | // 3) app -> app |
| 1151 | // |
| 1152 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1153 | |
| 1154 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1155 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1156 | // temp = temp->dex_cache_resolved_methods_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1157 | __ LoadFromOffset( |
| 1158 | kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
Nicolas Geoffray | 4e44c82 | 2014-12-17 12:25:12 +0000 | [diff] [blame] | 1159 | // temp = temp[index_in_cache] |
| 1160 | __ LoadFromOffset( |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1161 | kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex())); |
Nicolas Geoffray | 4e44c82 | 2014-12-17 12:25:12 +0000 | [diff] [blame] | 1162 | // LR = temp[offset_of_quick_compiled_code] |
| 1163 | __ LoadFromOffset(kLoadWord, LR, temp, |
| 1164 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 1165 | kArmWordSize).Int32Value()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1166 | // LR() |
| 1167 | __ blx(LR); |
| 1168 | |
| 1169 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1170 | DCHECK(!codegen_->IsLeafMethod()); |
| 1171 | } |
| 1172 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1173 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1174 | LocationSummary* locations = |
| 1175 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1176 | locations->AddTemp(Location::RegisterLocation(R0)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1177 | |
| 1178 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1179 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1180 | HInstruction* input = invoke->InputAt(i); |
| 1181 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1182 | } |
| 1183 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1184 | locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1187 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1188 | HandleInvoke(invoke); |
| 1189 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1190 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1191 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1192 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1193 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1194 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1195 | LocationSummary* locations = invoke->GetLocations(); |
| 1196 | Location receiver = locations->InAt(0); |
| 1197 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1198 | // temp = object->GetClass(); |
| 1199 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1200 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1201 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1202 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1203 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1204 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1205 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1206 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1207 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1208 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1209 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1210 | // LR = temp->GetEntryPoint(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1211 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1212 | // LR(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1213 | __ blx(LR); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1214 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1215 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1218 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1219 | HandleInvoke(invoke); |
| 1220 | // Add the hidden argument. |
| 1221 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1222 | } |
| 1223 | |
| 1224 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1225 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1226 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1227 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1228 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1229 | LocationSummary* locations = invoke->GetLocations(); |
| 1230 | Location receiver = locations->InAt(0); |
| 1231 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1232 | |
| 1233 | // Set the hidden argument. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1234 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(), |
| 1235 | invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1236 | |
| 1237 | // temp = object->GetClass(); |
| 1238 | if (receiver.IsStackSlot()) { |
| 1239 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1240 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1241 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1242 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1243 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1244 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1245 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1246 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1247 | kArmWordSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1248 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1249 | // LR = temp->GetEntryPoint(); |
| 1250 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1251 | // LR(); |
| 1252 | __ blx(LR); |
| 1253 | DCHECK(!codegen_->IsLeafMethod()); |
| 1254 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1255 | } |
| 1256 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1257 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1258 | LocationSummary* locations = |
| 1259 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1260 | switch (neg->GetResultType()) { |
| 1261 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1262 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1263 | Location::OutputOverlap output_overlaps = (neg->GetResultType() == Primitive::kPrimLong) |
| 1264 | ? Location::kOutputOverlap |
| 1265 | : Location::kNoOutputOverlap; |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1266 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1267 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1268 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1269 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1270 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1271 | case Primitive::kPrimFloat: |
| 1272 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1273 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1274 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1275 | break; |
| 1276 | |
| 1277 | default: |
| 1278 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1283 | LocationSummary* locations = neg->GetLocations(); |
| 1284 | Location out = locations->Out(); |
| 1285 | Location in = locations->InAt(0); |
| 1286 | switch (neg->GetResultType()) { |
| 1287 | case Primitive::kPrimInt: |
| 1288 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1289 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1290 | break; |
| 1291 | |
| 1292 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1293 | DCHECK(in.IsRegisterPair()); |
| 1294 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1295 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1296 | in.AsRegisterPairLow<Register>(), |
| 1297 | ShifterOperand(0)); |
| 1298 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1299 | // instruction here, as it does not exist in the Thumb-2 |
| 1300 | // instruction set. We use the following approach |
| 1301 | // using SBC and SUB instead. |
| 1302 | // |
| 1303 | // out.hi = -C |
| 1304 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1305 | out.AsRegisterPairHigh<Register>(), |
| 1306 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1307 | // out.hi = out.hi - in.hi |
| 1308 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1309 | out.AsRegisterPairHigh<Register>(), |
| 1310 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1311 | break; |
| 1312 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1313 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1314 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1315 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1316 | break; |
| 1317 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1318 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1319 | DCHECK(in.IsFpuRegisterPair()); |
| 1320 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1321 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1322 | break; |
| 1323 | |
| 1324 | default: |
| 1325 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1326 | } |
| 1327 | } |
| 1328 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1329 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1330 | Primitive::Type result_type = conversion->GetResultType(); |
| 1331 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1332 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1333 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1334 | // The float-to-long and double-to-long type conversions rely on a |
| 1335 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1336 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1337 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1338 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1339 | ? LocationSummary::kCall |
| 1340 | : LocationSummary::kNoCall; |
| 1341 | LocationSummary* locations = |
| 1342 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1343 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1344 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1345 | case Primitive::kPrimByte: |
| 1346 | switch (input_type) { |
| 1347 | case Primitive::kPrimShort: |
| 1348 | case Primitive::kPrimInt: |
| 1349 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1350 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1352 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1353 | break; |
| 1354 | |
| 1355 | default: |
| 1356 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1357 | << " to " << result_type; |
| 1358 | } |
| 1359 | break; |
| 1360 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1361 | case Primitive::kPrimShort: |
| 1362 | switch (input_type) { |
| 1363 | case Primitive::kPrimByte: |
| 1364 | case Primitive::kPrimInt: |
| 1365 | case Primitive::kPrimChar: |
| 1366 | // Processing a Dex `int-to-short' instruction. |
| 1367 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1368 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1369 | break; |
| 1370 | |
| 1371 | default: |
| 1372 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1373 | << " to " << result_type; |
| 1374 | } |
| 1375 | break; |
| 1376 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1377 | case Primitive::kPrimInt: |
| 1378 | switch (input_type) { |
| 1379 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1380 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1381 | locations->SetInAt(0, Location::Any()); |
| 1382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1383 | break; |
| 1384 | |
| 1385 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1386 | // Processing a Dex `float-to-int' instruction. |
| 1387 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1388 | locations->SetOut(Location::RequiresRegister()); |
| 1389 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1390 | break; |
| 1391 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1392 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1393 | // Processing a Dex `double-to-int' instruction. |
| 1394 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1395 | locations->SetOut(Location::RequiresRegister()); |
| 1396 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1397 | break; |
| 1398 | |
| 1399 | default: |
| 1400 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1401 | << " to " << result_type; |
| 1402 | } |
| 1403 | break; |
| 1404 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1405 | case Primitive::kPrimLong: |
| 1406 | switch (input_type) { |
| 1407 | case Primitive::kPrimByte: |
| 1408 | case Primitive::kPrimShort: |
| 1409 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1410 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1411 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1412 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1413 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1414 | break; |
| 1415 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1416 | case Primitive::kPrimFloat: { |
| 1417 | // Processing a Dex `float-to-long' instruction. |
| 1418 | InvokeRuntimeCallingConvention calling_convention; |
| 1419 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 1420 | calling_convention.GetFpuRegisterAt(0))); |
| 1421 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 1422 | break; |
| 1423 | } |
| 1424 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1425 | case Primitive::kPrimDouble: { |
| 1426 | // Processing a Dex `double-to-long' instruction. |
| 1427 | InvokeRuntimeCallingConvention calling_convention; |
| 1428 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 1429 | calling_convention.GetFpuRegisterAt(0), |
| 1430 | calling_convention.GetFpuRegisterAt(1))); |
| 1431 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1432 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1433 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1434 | |
| 1435 | default: |
| 1436 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1437 | << " to " << result_type; |
| 1438 | } |
| 1439 | break; |
| 1440 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1441 | case Primitive::kPrimChar: |
| 1442 | switch (input_type) { |
| 1443 | case Primitive::kPrimByte: |
| 1444 | case Primitive::kPrimShort: |
| 1445 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1446 | // Processing a Dex `int-to-char' instruction. |
| 1447 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1448 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1449 | break; |
| 1450 | |
| 1451 | default: |
| 1452 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1453 | << " to " << result_type; |
| 1454 | } |
| 1455 | break; |
| 1456 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1457 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1458 | switch (input_type) { |
| 1459 | case Primitive::kPrimByte: |
| 1460 | case Primitive::kPrimShort: |
| 1461 | case Primitive::kPrimInt: |
| 1462 | case Primitive::kPrimChar: |
| 1463 | // Processing a Dex `int-to-float' instruction. |
| 1464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1465 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1466 | break; |
| 1467 | |
| 1468 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1469 | // Processing a Dex `long-to-float' instruction. |
| 1470 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1471 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1472 | locations->AddTemp(Location::RequiresRegister()); |
| 1473 | locations->AddTemp(Location::RequiresRegister()); |
| 1474 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1475 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1476 | break; |
| 1477 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1478 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1479 | // Processing a Dex `double-to-float' instruction. |
| 1480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1481 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1482 | break; |
| 1483 | |
| 1484 | default: |
| 1485 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1486 | << " to " << result_type; |
| 1487 | }; |
| 1488 | break; |
| 1489 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1490 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1491 | switch (input_type) { |
| 1492 | case Primitive::kPrimByte: |
| 1493 | case Primitive::kPrimShort: |
| 1494 | case Primitive::kPrimInt: |
| 1495 | case Primitive::kPrimChar: |
| 1496 | // Processing a Dex `int-to-double' instruction. |
| 1497 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1498 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1499 | break; |
| 1500 | |
| 1501 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1502 | // Processing a Dex `long-to-double' instruction. |
| 1503 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1504 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1505 | locations->AddTemp(Location::RequiresRegister()); |
| 1506 | locations->AddTemp(Location::RequiresRegister()); |
| 1507 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1508 | break; |
| 1509 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1510 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1511 | // Processing a Dex `float-to-double' instruction. |
| 1512 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1513 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1514 | break; |
| 1515 | |
| 1516 | default: |
| 1517 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1518 | << " to " << result_type; |
| 1519 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | |
| 1522 | default: |
| 1523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1524 | << " to " << result_type; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1529 | LocationSummary* locations = conversion->GetLocations(); |
| 1530 | Location out = locations->Out(); |
| 1531 | Location in = locations->InAt(0); |
| 1532 | Primitive::Type result_type = conversion->GetResultType(); |
| 1533 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1534 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1535 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1536 | case Primitive::kPrimByte: |
| 1537 | switch (input_type) { |
| 1538 | case Primitive::kPrimShort: |
| 1539 | case Primitive::kPrimInt: |
| 1540 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1541 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1542 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | |
| 1545 | default: |
| 1546 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1547 | << " to " << result_type; |
| 1548 | } |
| 1549 | break; |
| 1550 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1551 | case Primitive::kPrimShort: |
| 1552 | switch (input_type) { |
| 1553 | case Primitive::kPrimByte: |
| 1554 | case Primitive::kPrimInt: |
| 1555 | case Primitive::kPrimChar: |
| 1556 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1557 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1558 | break; |
| 1559 | |
| 1560 | default: |
| 1561 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1562 | << " to " << result_type; |
| 1563 | } |
| 1564 | break; |
| 1565 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1566 | case Primitive::kPrimInt: |
| 1567 | switch (input_type) { |
| 1568 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1569 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1570 | DCHECK(out.IsRegister()); |
| 1571 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1572 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1573 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1574 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1575 | } else { |
| 1576 | DCHECK(in.IsConstant()); |
| 1577 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1578 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1579 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1580 | } |
| 1581 | break; |
| 1582 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1583 | case Primitive::kPrimFloat: { |
| 1584 | // Processing a Dex `float-to-int' instruction. |
| 1585 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1586 | __ vmovs(temp, in.AsFpuRegister<SRegister>()); |
| 1587 | __ vcvtis(temp, temp); |
| 1588 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 1589 | break; |
| 1590 | } |
| 1591 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1592 | case Primitive::kPrimDouble: { |
| 1593 | // Processing a Dex `double-to-int' instruction. |
| 1594 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1595 | DRegister temp_d = FromLowSToD(temp_s); |
| 1596 | __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 1597 | __ vcvtid(temp_s, temp_d); |
| 1598 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1599 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1600 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1601 | |
| 1602 | default: |
| 1603 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1604 | << " to " << result_type; |
| 1605 | } |
| 1606 | break; |
| 1607 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1608 | case Primitive::kPrimLong: |
| 1609 | switch (input_type) { |
| 1610 | case Primitive::kPrimByte: |
| 1611 | case Primitive::kPrimShort: |
| 1612 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1613 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1614 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1615 | DCHECK(out.IsRegisterPair()); |
| 1616 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1617 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1618 | // Sign extension. |
| 1619 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 1620 | out.AsRegisterPairLow<Register>(), |
| 1621 | 31); |
| 1622 | break; |
| 1623 | |
| 1624 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1625 | // Processing a Dex `float-to-long' instruction. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1626 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 1627 | conversion, |
| 1628 | conversion->GetDexPc()); |
| 1629 | break; |
| 1630 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1631 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1632 | // Processing a Dex `double-to-long' instruction. |
| 1633 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 1634 | conversion, |
| 1635 | conversion->GetDexPc()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1636 | break; |
| 1637 | |
| 1638 | default: |
| 1639 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1640 | << " to " << result_type; |
| 1641 | } |
| 1642 | break; |
| 1643 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1644 | case Primitive::kPrimChar: |
| 1645 | switch (input_type) { |
| 1646 | case Primitive::kPrimByte: |
| 1647 | case Primitive::kPrimShort: |
| 1648 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1649 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1650 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1651 | break; |
| 1652 | |
| 1653 | default: |
| 1654 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1655 | << " to " << result_type; |
| 1656 | } |
| 1657 | break; |
| 1658 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1659 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1660 | switch (input_type) { |
| 1661 | case Primitive::kPrimByte: |
| 1662 | case Primitive::kPrimShort: |
| 1663 | case Primitive::kPrimInt: |
| 1664 | case Primitive::kPrimChar: { |
| 1665 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1666 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 1667 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1668 | break; |
| 1669 | } |
| 1670 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1671 | case Primitive::kPrimLong: { |
| 1672 | // Processing a Dex `long-to-float' instruction. |
| 1673 | Register low = in.AsRegisterPairLow<Register>(); |
| 1674 | Register high = in.AsRegisterPairHigh<Register>(); |
| 1675 | SRegister output = out.AsFpuRegister<SRegister>(); |
| 1676 | Register constant_low = locations->GetTemp(0).AsRegister<Register>(); |
| 1677 | Register constant_high = locations->GetTemp(1).AsRegister<Register>(); |
| 1678 | SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>(); |
| 1679 | DRegister temp1_d = FromLowSToD(temp1_s); |
| 1680 | SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>(); |
| 1681 | DRegister temp2_d = FromLowSToD(temp2_s); |
| 1682 | |
| 1683 | // Operations use doubles for precision reasons (each 32-bit |
| 1684 | // half of a long fits in the 53-bit mantissa of a double, |
| 1685 | // but not in the 24-bit mantissa of a float). This is |
| 1686 | // especially important for the low bits. The result is |
| 1687 | // eventually converted to float. |
| 1688 | |
| 1689 | // temp1_d = int-to-double(high) |
| 1690 | __ vmovsr(temp1_s, high); |
| 1691 | __ vcvtdi(temp1_d, temp1_s); |
| 1692 | // Using vmovd to load the `k2Pow32EncodingForDouble` constant |
| 1693 | // as an immediate value into `temp2_d` does not work, as |
| 1694 | // this instruction only transfers 8 significant bits of its |
| 1695 | // immediate operand. Instead, use two 32-bit core |
| 1696 | // registers to load `k2Pow32EncodingForDouble` into |
| 1697 | // `temp2_d`. |
| 1698 | __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble)); |
| 1699 | __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble)); |
| 1700 | __ vmovdrr(temp2_d, constant_low, constant_high); |
| 1701 | // temp1_d = temp1_d * 2^32 |
| 1702 | __ vmuld(temp1_d, temp1_d, temp2_d); |
| 1703 | // temp2_d = unsigned-to-double(low) |
| 1704 | __ vmovsr(temp2_s, low); |
| 1705 | __ vcvtdu(temp2_d, temp2_s); |
| 1706 | // temp1_d = temp1_d + temp2_d |
| 1707 | __ vaddd(temp1_d, temp1_d, temp2_d); |
| 1708 | // output = double-to-float(temp1_d); |
| 1709 | __ vcvtsd(output, temp1_d); |
| 1710 | break; |
| 1711 | } |
| 1712 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1713 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1714 | // Processing a Dex `double-to-float' instruction. |
| 1715 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 1716 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1717 | break; |
| 1718 | |
| 1719 | default: |
| 1720 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1721 | << " to " << result_type; |
| 1722 | }; |
| 1723 | break; |
| 1724 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1725 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1726 | switch (input_type) { |
| 1727 | case Primitive::kPrimByte: |
| 1728 | case Primitive::kPrimShort: |
| 1729 | case Primitive::kPrimInt: |
| 1730 | case Primitive::kPrimChar: { |
| 1731 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1732 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1733 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1734 | out.AsFpuRegisterPairLow<SRegister>()); |
| 1735 | break; |
| 1736 | } |
| 1737 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1738 | case Primitive::kPrimLong: { |
| 1739 | // Processing a Dex `long-to-double' instruction. |
| 1740 | Register low = in.AsRegisterPairLow<Register>(); |
| 1741 | Register high = in.AsRegisterPairHigh<Register>(); |
| 1742 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 1743 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1744 | Register constant_low = locations->GetTemp(0).AsRegister<Register>(); |
| 1745 | Register constant_high = locations->GetTemp(1).AsRegister<Register>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1746 | SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>(); |
| 1747 | DRegister temp_d = FromLowSToD(temp_s); |
| 1748 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1749 | // out_d = int-to-double(high) |
| 1750 | __ vmovsr(out_s, high); |
| 1751 | __ vcvtdi(out_d, out_s); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1752 | // Using vmovd to load the `k2Pow32EncodingForDouble` constant |
| 1753 | // as an immediate value into `temp_d` does not work, as |
| 1754 | // this instruction only transfers 8 significant bits of its |
| 1755 | // immediate operand. Instead, use two 32-bit core |
| 1756 | // registers to load `k2Pow32EncodingForDouble` into `temp_d`. |
| 1757 | __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble)); |
| 1758 | __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble)); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1759 | __ vmovdrr(temp_d, constant_low, constant_high); |
| 1760 | // out_d = out_d * 2^32 |
| 1761 | __ vmuld(out_d, out_d, temp_d); |
| 1762 | // temp_d = unsigned-to-double(low) |
| 1763 | __ vmovsr(temp_s, low); |
| 1764 | __ vcvtdu(temp_d, temp_s); |
| 1765 | // out_d = out_d + temp_d |
| 1766 | __ vaddd(out_d, out_d, temp_d); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1770 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1771 | // Processing a Dex `float-to-double' instruction. |
| 1772 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1773 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1774 | break; |
| 1775 | |
| 1776 | default: |
| 1777 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1778 | << " to " << result_type; |
| 1779 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1780 | break; |
| 1781 | |
| 1782 | default: |
| 1783 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1784 | << " to " << result_type; |
| 1785 | } |
| 1786 | } |
| 1787 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1788 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1789 | LocationSummary* locations = |
| 1790 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1791 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1792 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1794 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1795 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1796 | break; |
| 1797 | } |
| 1798 | |
| 1799 | case Primitive::kPrimLong: { |
| 1800 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1801 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1802 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1803 | break; |
| 1804 | } |
| 1805 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1806 | case Primitive::kPrimFloat: |
| 1807 | case Primitive::kPrimDouble: { |
| 1808 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1809 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1810 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1811 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1812 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1813 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1814 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1815 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1816 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 1820 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1821 | Location out = locations->Out(); |
| 1822 | Location first = locations->InAt(0); |
| 1823 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1824 | switch (add->GetResultType()) { |
| 1825 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1826 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1827 | __ add(out.AsRegister<Register>(), |
| 1828 | first.AsRegister<Register>(), |
| 1829 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1830 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1831 | __ AddConstant(out.AsRegister<Register>(), |
| 1832 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1833 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1834 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1835 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1836 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimLong: { |
| 1838 | DCHECK(second.IsRegisterPair()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1839 | __ adds(out.AsRegisterPairLow<Register>(), |
| 1840 | first.AsRegisterPairLow<Register>(), |
| 1841 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1842 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 1843 | first.AsRegisterPairHigh<Register>(), |
| 1844 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1845 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1846 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1847 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1848 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1849 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 1850 | first.AsFpuRegister<SRegister>(), |
| 1851 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1852 | break; |
| 1853 | |
| 1854 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1855 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1856 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1857 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1858 | break; |
| 1859 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1860 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1861 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1865 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1866 | LocationSummary* locations = |
| 1867 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1868 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1869 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1871 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1872 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1873 | break; |
| 1874 | } |
| 1875 | |
| 1876 | case Primitive::kPrimLong: { |
| 1877 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1878 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1879 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1880 | break; |
| 1881 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1882 | case Primitive::kPrimFloat: |
| 1883 | case Primitive::kPrimDouble: { |
| 1884 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1885 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1886 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1887 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1888 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1889 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1890 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1891 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 1895 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1896 | Location out = locations->Out(); |
| 1897 | Location first = locations->InAt(0); |
| 1898 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1899 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1900 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1901 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1902 | __ sub(out.AsRegister<Register>(), |
| 1903 | first.AsRegister<Register>(), |
| 1904 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1905 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1906 | __ AddConstant(out.AsRegister<Register>(), |
| 1907 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1908 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1909 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1910 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1911 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1912 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1913 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1914 | DCHECK(second.IsRegisterPair()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1915 | __ subs(out.AsRegisterPairLow<Register>(), |
| 1916 | first.AsRegisterPairLow<Register>(), |
| 1917 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1918 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1919 | first.AsRegisterPairHigh<Register>(), |
| 1920 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1921 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1922 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1923 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1924 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1925 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 1926 | first.AsFpuRegister<SRegister>(), |
| 1927 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1928 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1932 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1933 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1934 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1935 | break; |
| 1936 | } |
| 1937 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1938 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1939 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1940 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1944 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 1945 | LocationSummary* locations = |
| 1946 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1947 | switch (mul->GetResultType()) { |
| 1948 | case Primitive::kPrimInt: |
| 1949 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1951 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1952 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1953 | break; |
| 1954 | } |
| 1955 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1956 | case Primitive::kPrimFloat: |
| 1957 | case Primitive::kPrimDouble: { |
| 1958 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1959 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1960 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1961 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1962 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1963 | |
| 1964 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1965 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 1970 | LocationSummary* locations = mul->GetLocations(); |
| 1971 | Location out = locations->Out(); |
| 1972 | Location first = locations->InAt(0); |
| 1973 | Location second = locations->InAt(1); |
| 1974 | switch (mul->GetResultType()) { |
| 1975 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1976 | __ mul(out.AsRegister<Register>(), |
| 1977 | first.AsRegister<Register>(), |
| 1978 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1979 | break; |
| 1980 | } |
| 1981 | case Primitive::kPrimLong: { |
| 1982 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1983 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1984 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1985 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1986 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 1987 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 1988 | |
| 1989 | // Extra checks to protect caused by the existence of R1_R2. |
| 1990 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 1991 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 1992 | DCHECK_NE(out_hi, in1_lo); |
| 1993 | DCHECK_NE(out_hi, in2_lo); |
| 1994 | |
| 1995 | // input: in1 - 64 bits, in2 - 64 bits |
| 1996 | // output: out |
| 1997 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1998 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1999 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 2000 | |
| 2001 | // IP <- in1.lo * in2.hi |
| 2002 | __ mul(IP, in1_lo, in2_hi); |
| 2003 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2004 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 2005 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 2006 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 2007 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2008 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 2009 | break; |
| 2010 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2011 | |
| 2012 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2013 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 2014 | first.AsFpuRegister<SRegister>(), |
| 2015 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2016 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2020 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2021 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2022 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2023 | break; |
| 2024 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2025 | |
| 2026 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2027 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2031 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2032 | LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong |
| 2033 | ? LocationSummary::kCall |
| 2034 | : LocationSummary::kNoCall; |
| 2035 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2036 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2037 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2038 | case Primitive::kPrimInt: { |
| 2039 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2040 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2041 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2042 | break; |
| 2043 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2044 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2045 | InvokeRuntimeCallingConvention calling_convention; |
| 2046 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2047 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2048 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2049 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2050 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2051 | break; |
| 2052 | } |
| 2053 | case Primitive::kPrimFloat: |
| 2054 | case Primitive::kPrimDouble: { |
| 2055 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2056 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2057 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2058 | break; |
| 2059 | } |
| 2060 | |
| 2061 | default: |
| 2062 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 2067 | LocationSummary* locations = div->GetLocations(); |
| 2068 | Location out = locations->Out(); |
| 2069 | Location first = locations->InAt(0); |
| 2070 | Location second = locations->InAt(1); |
| 2071 | |
| 2072 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2073 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2074 | __ sdiv(out.AsRegister<Register>(), |
| 2075 | first.AsRegister<Register>(), |
| 2076 | second.AsRegister<Register>()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2077 | break; |
| 2078 | } |
| 2079 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2080 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2081 | InvokeRuntimeCallingConvention calling_convention; |
| 2082 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2083 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2084 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2085 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2086 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2087 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2088 | |
| 2089 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2090 | break; |
| 2091 | } |
| 2092 | |
| 2093 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2094 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 2095 | first.AsFpuRegister<SRegister>(), |
| 2096 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2097 | break; |
| 2098 | } |
| 2099 | |
| 2100 | case Primitive::kPrimDouble: { |
| 2101 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2102 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 2103 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 2104 | break; |
| 2105 | } |
| 2106 | |
| 2107 | default: |
| 2108 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2109 | } |
| 2110 | } |
| 2111 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2112 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2113 | Primitive::Type type = rem->GetResultType(); |
| 2114 | LocationSummary::CallKind call_kind = type == Primitive::kPrimInt |
| 2115 | ? LocationSummary::kNoCall |
| 2116 | : LocationSummary::kCall; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2117 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2118 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2119 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2120 | case Primitive::kPrimInt: { |
| 2121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2122 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2123 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2124 | locations->AddTemp(Location::RequiresRegister()); |
| 2125 | break; |
| 2126 | } |
| 2127 | case Primitive::kPrimLong: { |
| 2128 | InvokeRuntimeCallingConvention calling_convention; |
| 2129 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2130 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2131 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2132 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2133 | // The runtime helper puts the output in R2,R3. |
| 2134 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 2135 | break; |
| 2136 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2137 | case Primitive::kPrimFloat: { |
| 2138 | InvokeRuntimeCallingConvention calling_convention; |
| 2139 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 2140 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 2141 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 2142 | break; |
| 2143 | } |
| 2144 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2145 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2146 | InvokeRuntimeCallingConvention calling_convention; |
| 2147 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2148 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 2149 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 2150 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 2151 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2152 | break; |
| 2153 | } |
| 2154 | |
| 2155 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2156 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 2161 | LocationSummary* locations = rem->GetLocations(); |
| 2162 | Location out = locations->Out(); |
| 2163 | Location first = locations->InAt(0); |
| 2164 | Location second = locations->InAt(1); |
| 2165 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2166 | Primitive::Type type = rem->GetResultType(); |
| 2167 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2168 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2169 | Register reg1 = first.AsRegister<Register>(); |
| 2170 | Register reg2 = second.AsRegister<Register>(); |
| 2171 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2172 | |
| 2173 | // temp = reg1 / reg2 (integer division) |
| 2174 | // temp = temp * reg2 |
| 2175 | // dest = reg1 - temp |
| 2176 | __ sdiv(temp, reg1, reg2); |
| 2177 | __ mul(temp, temp, reg2); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2178 | __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2179 | break; |
| 2180 | } |
| 2181 | |
| 2182 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2183 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc()); |
| 2184 | break; |
| 2185 | } |
| 2186 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2187 | case Primitive::kPrimFloat: { |
| 2188 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc()); |
| 2189 | break; |
| 2190 | } |
| 2191 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2192 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2193 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | } |
| 2196 | |
| 2197 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2198 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2202 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2203 | LocationSummary* locations = |
| 2204 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2205 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2206 | if (instruction->HasUses()) { |
| 2207 | locations->SetOut(Location::SameAsFirstInput()); |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2212 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 2213 | codegen_->AddSlowPath(slow_path); |
| 2214 | |
| 2215 | LocationSummary* locations = instruction->GetLocations(); |
| 2216 | Location value = locations->InAt(0); |
| 2217 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2218 | switch (instruction->GetType()) { |
| 2219 | case Primitive::kPrimInt: { |
| 2220 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2221 | __ cmp(value.AsRegister<Register>(), ShifterOperand(0)); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2222 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2223 | } else { |
| 2224 | DCHECK(value.IsConstant()) << value; |
| 2225 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2226 | __ b(slow_path->GetEntryLabel()); |
| 2227 | } |
| 2228 | } |
| 2229 | break; |
| 2230 | } |
| 2231 | case Primitive::kPrimLong: { |
| 2232 | if (value.IsRegisterPair()) { |
| 2233 | __ orrs(IP, |
| 2234 | value.AsRegisterPairLow<Register>(), |
| 2235 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 2236 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2237 | } else { |
| 2238 | DCHECK(value.IsConstant()) << value; |
| 2239 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2240 | __ b(slow_path->GetEntryLabel()); |
| 2241 | } |
| 2242 | } |
| 2243 | break; |
| 2244 | default: |
| 2245 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2246 | } |
| 2247 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2250 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 2251 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2252 | |
| 2253 | LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong |
| 2254 | ? LocationSummary::kCall |
| 2255 | : LocationSummary::kNoCall; |
| 2256 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind); |
| 2257 | |
| 2258 | switch (op->GetResultType()) { |
| 2259 | case Primitive::kPrimInt: { |
| 2260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2261 | locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1))); |
| 2262 | locations->SetOut(Location::RequiresRegister()); |
| 2263 | break; |
| 2264 | } |
| 2265 | case Primitive::kPrimLong: { |
| 2266 | InvokeRuntimeCallingConvention calling_convention; |
| 2267 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2268 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2269 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2270 | // The runtime helper puts the output in R0,R1. |
| 2271 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | } |
| 2274 | default: |
| 2275 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 2280 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2281 | |
| 2282 | LocationSummary* locations = op->GetLocations(); |
| 2283 | Location out = locations->Out(); |
| 2284 | Location first = locations->InAt(0); |
| 2285 | Location second = locations->InAt(1); |
| 2286 | |
| 2287 | Primitive::Type type = op->GetResultType(); |
| 2288 | switch (type) { |
| 2289 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2290 | Register out_reg = out.AsRegister<Register>(); |
| 2291 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2292 | // Arm doesn't mask the shift count so we need to do it ourselves. |
| 2293 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2294 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2295 | __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue)); |
| 2296 | if (op->IsShl()) { |
| 2297 | __ Lsl(out_reg, first_reg, second_reg); |
| 2298 | } else if (op->IsShr()) { |
| 2299 | __ Asr(out_reg, first_reg, second_reg); |
| 2300 | } else { |
| 2301 | __ Lsr(out_reg, first_reg, second_reg); |
| 2302 | } |
| 2303 | } else { |
| 2304 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2305 | uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue); |
| 2306 | if (shift_value == 0) { // arm does not support shifting with 0 immediate. |
| 2307 | __ Mov(out_reg, first_reg); |
| 2308 | } else if (op->IsShl()) { |
| 2309 | __ Lsl(out_reg, first_reg, shift_value); |
| 2310 | } else if (op->IsShr()) { |
| 2311 | __ Asr(out_reg, first_reg, shift_value); |
| 2312 | } else { |
| 2313 | __ Lsr(out_reg, first_reg, shift_value); |
| 2314 | } |
| 2315 | } |
| 2316 | break; |
| 2317 | } |
| 2318 | case Primitive::kPrimLong: { |
| 2319 | // TODO: Inline the assembly instead of calling the runtime. |
| 2320 | InvokeRuntimeCallingConvention calling_convention; |
| 2321 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2322 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2323 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2324 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2325 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2326 | |
| 2327 | int32_t entry_point_offset; |
| 2328 | if (op->IsShl()) { |
| 2329 | entry_point_offset = QUICK_ENTRY_POINT(pShlLong); |
| 2330 | } else if (op->IsShr()) { |
| 2331 | entry_point_offset = QUICK_ENTRY_POINT(pShrLong); |
| 2332 | } else { |
| 2333 | entry_point_offset = QUICK_ENTRY_POINT(pUshrLong); |
| 2334 | } |
| 2335 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2336 | __ blx(LR); |
| 2337 | break; |
| 2338 | } |
| 2339 | default: |
| 2340 | LOG(FATAL) << "Unexpected operation type " << type; |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 2345 | HandleShift(shl); |
| 2346 | } |
| 2347 | |
| 2348 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 2349 | HandleShift(shl); |
| 2350 | } |
| 2351 | |
| 2352 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 2353 | HandleShift(shr); |
| 2354 | } |
| 2355 | |
| 2356 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 2357 | HandleShift(shr); |
| 2358 | } |
| 2359 | |
| 2360 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 2361 | HandleShift(ushr); |
| 2362 | } |
| 2363 | |
| 2364 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 2365 | HandleShift(ushr); |
| 2366 | } |
| 2367 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2368 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2369 | LocationSummary* locations = |
| 2370 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2371 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2372 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2373 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2374 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 2378 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2379 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2380 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2381 | codegen_->InvokeRuntime( |
| 2382 | QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2385 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 2386 | LocationSummary* locations = |
| 2387 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2388 | InvokeRuntimeCallingConvention calling_convention; |
| 2389 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2390 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2391 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2392 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 2396 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2397 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2398 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2399 | codegen_->InvokeRuntime( |
| 2400 | QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2403 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2404 | LocationSummary* locations = |
| 2405 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2406 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2407 | if (location.IsStackSlot()) { |
| 2408 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2409 | } else if (location.IsDoubleStackSlot()) { |
| 2410 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2411 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2412 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2416 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2417 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2418 | } |
| 2419 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2420 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2421 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2422 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2423 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2424 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2427 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 2428 | LocationSummary* locations = not_->GetLocations(); |
| 2429 | Location out = locations->Out(); |
| 2430 | Location in = locations->InAt(0); |
| 2431 | switch (not_->InputAt(0)->GetType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2432 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2433 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2434 | break; |
| 2435 | |
| 2436 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2437 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 2438 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 2439 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 2440 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2445 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2446 | } |
| 2447 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2448 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2449 | LocationSummary* locations = |
| 2450 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2451 | switch (compare->InputAt(0)->GetType()) { |
| 2452 | case Primitive::kPrimLong: { |
| 2453 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2454 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2456 | break; |
| 2457 | } |
| 2458 | case Primitive::kPrimFloat: |
| 2459 | case Primitive::kPrimDouble: { |
| 2460 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2461 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2462 | locations->SetOut(Location::RequiresRegister()); |
| 2463 | break; |
| 2464 | } |
| 2465 | default: |
| 2466 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2467 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2471 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2472 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2473 | Location left = locations->InAt(0); |
| 2474 | Location right = locations->InAt(1); |
| 2475 | |
| 2476 | Label less, greater, done; |
| 2477 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 2478 | switch (type) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2479 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2480 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 2481 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2482 | __ b(&less, LT); |
| 2483 | __ b(&greater, GT); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2484 | // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags. |
| 2485 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2486 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 2487 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2488 | break; |
| 2489 | } |
| 2490 | case Primitive::kPrimFloat: |
| 2491 | case Primitive::kPrimDouble: { |
| 2492 | __ LoadImmediate(out, 0); |
| 2493 | if (type == Primitive::kPrimFloat) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2494 | __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2495 | } else { |
| 2496 | __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()), |
| 2497 | FromLowSToD(right.AsFpuRegisterPairLow<SRegister>())); |
| 2498 | } |
| 2499 | __ vmstat(); // transfer FP status register to ARM APSR. |
| 2500 | __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2501 | break; |
| 2502 | } |
| 2503 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2504 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2505 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2506 | __ b(&done, EQ); |
| 2507 | __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats. |
| 2508 | |
| 2509 | __ Bind(&greater); |
| 2510 | __ LoadImmediate(out, 1); |
| 2511 | __ b(&done); |
| 2512 | |
| 2513 | __ Bind(&less); |
| 2514 | __ LoadImmediate(out, -1); |
| 2515 | |
| 2516 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2517 | } |
| 2518 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2519 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2520 | LocationSummary* locations = |
| 2521 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 2522 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2523 | locations->SetInAt(i, Location::Any()); |
| 2524 | } |
| 2525 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2529 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2530 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2533 | void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 2534 | // TODO (ported from quick): revisit Arm barrier kinds |
| 2535 | DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings |
| 2536 | switch (kind) { |
| 2537 | case MemBarrierKind::kAnyStore: |
| 2538 | case MemBarrierKind::kLoadAny: |
| 2539 | case MemBarrierKind::kAnyAny: { |
| 2540 | flavour = DmbOptions::ISH; |
| 2541 | break; |
| 2542 | } |
| 2543 | case MemBarrierKind::kStoreStore: { |
| 2544 | flavour = DmbOptions::ISHST; |
| 2545 | break; |
| 2546 | } |
| 2547 | default: |
| 2548 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2549 | } |
| 2550 | __ dmb(flavour); |
| 2551 | } |
| 2552 | |
| 2553 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 2554 | uint32_t offset, |
| 2555 | Register out_lo, |
| 2556 | Register out_hi) { |
| 2557 | if (offset != 0) { |
| 2558 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 2559 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 2560 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2561 | } |
| 2562 | __ ldrexd(out_lo, out_hi, addr); |
| 2563 | } |
| 2564 | |
| 2565 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 2566 | uint32_t offset, |
| 2567 | Register value_lo, |
| 2568 | Register value_hi, |
| 2569 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2570 | Register temp2, |
| 2571 | HInstruction* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2572 | Label fail; |
| 2573 | if (offset != 0) { |
| 2574 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 2575 | __ add(IP, addr, ShifterOperand(temp1)); |
| 2576 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2577 | } |
| 2578 | __ Bind(&fail); |
| 2579 | // We need a load followed by store. (The address used in a STREX instruction must |
| 2580 | // be the same as the address in the most recently executed LDREX instruction.) |
| 2581 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2582 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2583 | __ strexd(temp1, value_lo, value_hi, addr); |
| 2584 | __ cmp(temp1, ShifterOperand(0)); |
| 2585 | __ b(&fail, NE); |
| 2586 | } |
| 2587 | |
| 2588 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2589 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2590 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2591 | LocationSummary* locations = |
| 2592 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2594 | locations->SetInAt(1, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2595 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2596 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2597 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2598 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2599 | bool generate_volatile = field_info.IsVolatile() |
| 2600 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2601 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2602 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2603 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 2604 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2605 | locations->AddTemp(Location::RequiresRegister()); |
| 2606 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2607 | } else if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2608 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 2609 | // - registers need to be consecutive |
| 2610 | // - the first register should be even but not R14. |
| 2611 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 2612 | // enable Arm encoding. |
| 2613 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 2614 | |
| 2615 | locations->AddTemp(Location::RequiresRegister()); |
| 2616 | locations->AddTemp(Location::RequiresRegister()); |
| 2617 | if (field_type == Primitive::kPrimDouble) { |
| 2618 | // For doubles we need two more registers to copy the value. |
| 2619 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 2620 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 2621 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2622 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2623 | } |
| 2624 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2625 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
| 2626 | const FieldInfo& field_info) { |
| 2627 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2628 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2629 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2630 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 2631 | Location value = locations->InAt(1); |
| 2632 | |
| 2633 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2634 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2635 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2636 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2637 | |
| 2638 | if (is_volatile) { |
| 2639 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 2640 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2641 | |
| 2642 | switch (field_type) { |
| 2643 | case Primitive::kPrimBoolean: |
| 2644 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2645 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2646 | break; |
| 2647 | } |
| 2648 | |
| 2649 | case Primitive::kPrimShort: |
| 2650 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2651 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2652 | break; |
| 2653 | } |
| 2654 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2655 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2656 | case Primitive::kPrimNot: { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2657 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2658 | break; |
| 2659 | } |
| 2660 | |
| 2661 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2662 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2663 | GenerateWideAtomicStore(base, offset, |
| 2664 | value.AsRegisterPairLow<Register>(), |
| 2665 | value.AsRegisterPairHigh<Register>(), |
| 2666 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2667 | locations->GetTemp(1).AsRegister<Register>(), |
| 2668 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2669 | } else { |
| 2670 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2671 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2672 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2673 | break; |
| 2674 | } |
| 2675 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2677 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2678 | break; |
| 2679 | } |
| 2680 | |
| 2681 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2682 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2683 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2684 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 2685 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 2686 | |
| 2687 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 2688 | |
| 2689 | GenerateWideAtomicStore(base, offset, |
| 2690 | value_reg_lo, |
| 2691 | value_reg_hi, |
| 2692 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2693 | locations->GetTemp(3).AsRegister<Register>(), |
| 2694 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2695 | } else { |
| 2696 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2697 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2698 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2699 | break; |
| 2700 | } |
| 2701 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2702 | case Primitive::kPrimVoid: |
| 2703 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2704 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2705 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2706 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2707 | // Longs and doubles are handled in the switch. |
| 2708 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 2709 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2710 | } |
| 2711 | |
| 2712 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 2713 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2714 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 2715 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>()); |
| 2716 | } |
| 2717 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2718 | if (is_volatile) { |
| 2719 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 2720 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2721 | } |
| 2722 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2723 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 2724 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2725 | LocationSummary* locations = |
| 2726 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2727 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2728 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2729 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2730 | bool generate_volatile = field_info.IsVolatile() |
| 2731 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2732 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2733 | if (generate_volatile) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2734 | // Arm encoding have some additional constraints for ldrexd/strexd: |
| 2735 | // - registers need to be consecutive |
| 2736 | // - the first register should be even but not R14. |
| 2737 | // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever |
| 2738 | // enable Arm encoding. |
| 2739 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 2740 | locations->AddTemp(Location::RequiresRegister()); |
| 2741 | locations->AddTemp(Location::RequiresRegister()); |
| 2742 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2743 | } |
| 2744 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2745 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 2746 | const FieldInfo& field_info) { |
| 2747 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2748 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2749 | LocationSummary* locations = instruction->GetLocations(); |
| 2750 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 2751 | Location out = locations->Out(); |
| 2752 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2753 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2754 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2755 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2756 | |
| 2757 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2758 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2759 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2760 | break; |
| 2761 | } |
| 2762 | |
| 2763 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2764 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2765 | break; |
| 2766 | } |
| 2767 | |
| 2768 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2769 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2770 | break; |
| 2771 | } |
| 2772 | |
| 2773 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2774 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2775 | break; |
| 2776 | } |
| 2777 | |
| 2778 | case Primitive::kPrimInt: |
| 2779 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2780 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2781 | break; |
| 2782 | } |
| 2783 | |
| 2784 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2785 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2786 | GenerateWideAtomicLoad(base, offset, |
| 2787 | out.AsRegisterPairLow<Register>(), |
| 2788 | out.AsRegisterPairHigh<Register>()); |
| 2789 | } else { |
| 2790 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 2791 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2792 | break; |
| 2793 | } |
| 2794 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2795 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2796 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | } |
| 2799 | |
| 2800 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2801 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2802 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2803 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 2804 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 2805 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2806 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2807 | __ vmovdrr(out_reg, lo, hi); |
| 2808 | } else { |
| 2809 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2810 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2811 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2812 | break; |
| 2813 | } |
| 2814 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2815 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2816 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2817 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2818 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2819 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2820 | // Doubles are handled in the switch. |
| 2821 | if (field_type != Primitive::kPrimDouble) { |
| 2822 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2823 | } |
| 2824 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2825 | if (is_volatile) { |
| 2826 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2831 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2832 | } |
| 2833 | |
| 2834 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2835 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2836 | } |
| 2837 | |
| 2838 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2839 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2840 | } |
| 2841 | |
| 2842 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2843 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2844 | } |
| 2845 | |
| 2846 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2847 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2848 | } |
| 2849 | |
| 2850 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2851 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2852 | } |
| 2853 | |
| 2854 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2855 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2856 | } |
| 2857 | |
| 2858 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2859 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2863 | LocationSummary* locations = |
| 2864 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2865 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2866 | if (instruction->HasUses()) { |
| 2867 | locations->SetOut(Location::SameAsFirstInput()); |
| 2868 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2869 | } |
| 2870 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2871 | void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2872 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 2873 | return; |
| 2874 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2875 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2876 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2877 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
| 2878 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2879 | } |
| 2880 | |
| 2881 | void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2882 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2883 | codegen_->AddSlowPath(slow_path); |
| 2884 | |
| 2885 | LocationSummary* locations = instruction->GetLocations(); |
| 2886 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2887 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2888 | __ cmp(obj.AsRegister<Register>(), ShifterOperand(0)); |
| 2889 | __ b(slow_path->GetEntryLabel(), EQ); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2890 | } |
| 2891 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2892 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
| 2893 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 2894 | GenerateImplicitNullCheck(instruction); |
| 2895 | } else { |
| 2896 | GenerateExplicitNullCheck(instruction); |
| 2897 | } |
| 2898 | } |
| 2899 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2900 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2901 | LocationSummary* locations = |
| 2902 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2904 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2905 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 2909 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2910 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2911 | Location index = locations->InAt(1); |
| 2912 | |
| 2913 | switch (instruction->GetType()) { |
| 2914 | case Primitive::kPrimBoolean: { |
| 2915 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2916 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2917 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2918 | size_t offset = |
| 2919 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2920 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 2921 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2922 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2923 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 2924 | } |
| 2925 | break; |
| 2926 | } |
| 2927 | |
| 2928 | case Primitive::kPrimByte: { |
| 2929 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2930 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2931 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2932 | size_t offset = |
| 2933 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2934 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 2935 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2936 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2937 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 2938 | } |
| 2939 | break; |
| 2940 | } |
| 2941 | |
| 2942 | case Primitive::kPrimShort: { |
| 2943 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2944 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2945 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2946 | size_t offset = |
| 2947 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2948 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 2949 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2950 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2951 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 2952 | } |
| 2953 | break; |
| 2954 | } |
| 2955 | |
| 2956 | case Primitive::kPrimChar: { |
| 2957 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2958 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2959 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2960 | size_t offset = |
| 2961 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2962 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 2963 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2964 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2965 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 2966 | } |
| 2967 | break; |
| 2968 | } |
| 2969 | |
| 2970 | case Primitive::kPrimInt: |
| 2971 | case Primitive::kPrimNot: { |
| 2972 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 2973 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2974 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2975 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2976 | size_t offset = |
| 2977 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2978 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2979 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2980 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2981 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 2982 | } |
| 2983 | break; |
| 2984 | } |
| 2985 | |
| 2986 | case Primitive::kPrimLong: { |
| 2987 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2988 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2989 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2990 | size_t offset = |
| 2991 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2992 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2993 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2994 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2995 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2996 | } |
| 2997 | break; |
| 2998 | } |
| 2999 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3000 | case Primitive::kPrimFloat: { |
| 3001 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3002 | Location out = locations->Out(); |
| 3003 | DCHECK(out.IsFpuRegister()); |
| 3004 | if (index.IsConstant()) { |
| 3005 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3006 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset); |
| 3007 | } else { |
| 3008 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3009 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3010 | } |
| 3011 | break; |
| 3012 | } |
| 3013 | |
| 3014 | case Primitive::kPrimDouble: { |
| 3015 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3016 | Location out = locations->Out(); |
| 3017 | DCHECK(out.IsFpuRegisterPair()); |
| 3018 | if (index.IsConstant()) { |
| 3019 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3020 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3021 | } else { |
| 3022 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3023 | __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3024 | } |
| 3025 | break; |
| 3026 | } |
| 3027 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3028 | case Primitive::kPrimVoid: |
| 3029 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3030 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3031 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3032 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3036 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3037 | |
| 3038 | bool needs_write_barrier = |
| 3039 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3040 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3041 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3042 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3043 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3044 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3045 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3046 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3047 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3048 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3049 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3051 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3052 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3053 | |
| 3054 | if (needs_write_barrier) { |
| 3055 | // Temporary registers for the write barrier. |
| 3056 | locations->AddTemp(Location::RequiresRegister()); |
| 3057 | locations->AddTemp(Location::RequiresRegister()); |
| 3058 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3059 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 3063 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3065 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3066 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3067 | bool needs_runtime_call = locations->WillCall(); |
| 3068 | bool needs_write_barrier = |
| 3069 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3070 | |
| 3071 | switch (value_type) { |
| 3072 | case Primitive::kPrimBoolean: |
| 3073 | case Primitive::kPrimByte: { |
| 3074 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3075 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3076 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3077 | size_t offset = |
| 3078 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3079 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 3080 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3081 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3082 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 3083 | } |
| 3084 | break; |
| 3085 | } |
| 3086 | |
| 3087 | case Primitive::kPrimShort: |
| 3088 | case Primitive::kPrimChar: { |
| 3089 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3090 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3091 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3092 | size_t offset = |
| 3093 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3094 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 3095 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3096 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3097 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 3098 | } |
| 3099 | break; |
| 3100 | } |
| 3101 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3102 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3103 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3104 | if (!needs_runtime_call) { |
| 3105 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3106 | Register value = locations->InAt(2).AsRegister<Register>(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3107 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3108 | size_t offset = |
| 3109 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3110 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 3111 | } else { |
| 3112 | DCHECK(index.IsRegister()) << index; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3113 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3114 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 3115 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3116 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3117 | if (needs_write_barrier) { |
| 3118 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3119 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3120 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3121 | codegen_->MarkGCCard(temp, card, obj, value); |
| 3122 | } |
| 3123 | } else { |
| 3124 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3125 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 3126 | instruction, |
| 3127 | instruction->GetDexPc()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3128 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3129 | break; |
| 3130 | } |
| 3131 | |
| 3132 | case Primitive::kPrimLong: { |
| 3133 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3134 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3135 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3136 | size_t offset = |
| 3137 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3138 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3139 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3140 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3141 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3142 | } |
| 3143 | break; |
| 3144 | } |
| 3145 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3146 | case Primitive::kPrimFloat: { |
| 3147 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3148 | Location value = locations->InAt(2); |
| 3149 | DCHECK(value.IsFpuRegister()); |
| 3150 | if (index.IsConstant()) { |
| 3151 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3152 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset); |
| 3153 | } else { |
| 3154 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
| 3155 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 3156 | } |
| 3157 | break; |
| 3158 | } |
| 3159 | |
| 3160 | case Primitive::kPrimDouble: { |
| 3161 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3162 | Location value = locations->InAt(2); |
| 3163 | DCHECK(value.IsFpuRegisterPair()); |
| 3164 | if (index.IsConstant()) { |
| 3165 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3166 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset); |
| 3167 | } else { |
| 3168 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
| 3169 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 3170 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3171 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3175 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3176 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3177 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3178 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3179 | |
| 3180 | // Ints and objects are handled in the switch. |
| 3181 | if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) { |
| 3182 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3183 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3187 | LocationSummary* locations = |
| 3188 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3189 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3190 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 3194 | LocationSummary* locations = instruction->GetLocations(); |
| 3195 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3196 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3197 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3198 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3199 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3203 | LocationSummary* locations = |
| 3204 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3205 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3206 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3207 | if (instruction->HasUses()) { |
| 3208 | locations->SetOut(Location::SameAsFirstInput()); |
| 3209 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3213 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3214 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3215 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3216 | codegen_->AddSlowPath(slow_path); |
| 3217 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3218 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 3219 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3220 | |
| 3221 | __ cmp(index, ShifterOperand(length)); |
| 3222 | __ b(slow_path->GetEntryLabel(), CS); |
| 3223 | } |
| 3224 | |
| 3225 | void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 3226 | Label is_null; |
| 3227 | __ CompareAndBranchIfZero(value, &is_null); |
| 3228 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 3229 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 3230 | __ strb(card, Address(card, temp)); |
| 3231 | __ Bind(&is_null); |
| 3232 | } |
| 3233 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3234 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 3235 | temp->SetLocations(nullptr); |
| 3236 | } |
| 3237 | |
| 3238 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 3239 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3240 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3241 | } |
| 3242 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3243 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3244 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3245 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3249 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3250 | } |
| 3251 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3252 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3253 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3254 | } |
| 3255 | |
| 3256 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3257 | HBasicBlock* block = instruction->GetBlock(); |
| 3258 | if (block->GetLoopInformation() != nullptr) { |
| 3259 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3260 | // The back edge will generate the suspend check. |
| 3261 | return; |
| 3262 | } |
| 3263 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3264 | // The goto will generate the suspend check. |
| 3265 | return; |
| 3266 | } |
| 3267 | GenerateSuspendCheck(instruction, nullptr); |
| 3268 | } |
| 3269 | |
| 3270 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 3271 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3272 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3273 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3274 | codegen_->AddSlowPath(slow_path); |
| 3275 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3276 | __ LoadFromOffset( |
| 3277 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
| 3278 | __ cmp(IP, ShifterOperand(0)); |
| 3279 | // TODO: Figure out the branch offsets and use cbz/cbnz. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3280 | if (successor == nullptr) { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3281 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3282 | __ Bind(slow_path->GetReturnLabel()); |
| 3283 | } else { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 3284 | __ b(codegen_->GetLabelOf(successor), EQ); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3285 | __ b(slow_path->GetEntryLabel()); |
| 3286 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3289 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 3290 | return codegen_->GetAssembler(); |
| 3291 | } |
| 3292 | |
| 3293 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
| 3294 | MoveOperands* move = moves_.Get(index); |
| 3295 | Location source = move->GetSource(); |
| 3296 | Location destination = move->GetDestination(); |
| 3297 | |
| 3298 | if (source.IsRegister()) { |
| 3299 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3300 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3301 | } else { |
| 3302 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3303 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3304 | SP, destination.GetStackIndex()); |
| 3305 | } |
| 3306 | } else if (source.IsStackSlot()) { |
| 3307 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3308 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3309 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3310 | } else if (destination.IsFpuRegister()) { |
| 3311 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3312 | } else { |
| 3313 | DCHECK(destination.IsStackSlot()); |
| 3314 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 3315 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3316 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3317 | } else if (source.IsFpuRegister()) { |
| 3318 | if (destination.IsFpuRegister()) { |
| 3319 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3320 | } else { |
| 3321 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3322 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 3323 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3324 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3325 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 3326 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 3327 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3328 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize)); |
| 3329 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3330 | } else { |
| 3331 | DCHECK(source.IsConstant()) << source; |
| 3332 | HInstruction* constant = source.GetConstant(); |
| 3333 | if (constant->IsIntConstant()) { |
| 3334 | int32_t value = constant->AsIntConstant()->GetValue(); |
| 3335 | if (destination.IsRegister()) { |
| 3336 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 3337 | } else { |
| 3338 | DCHECK(destination.IsStackSlot()); |
| 3339 | __ LoadImmediate(IP, value); |
| 3340 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3341 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3342 | } else if (constant->IsLongConstant()) { |
| 3343 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 3344 | if (destination.IsRegister()) { |
| 3345 | // In the presence of long or double constants, the parallel move resolver will |
| 3346 | // split the move into two, but keeps the same constant for both moves. Here, |
| 3347 | // we use the low or high part depending on which register this move goes to. |
| 3348 | if (destination.reg() % 2 == 0) { |
| 3349 | __ LoadImmediate(destination.AsRegister<Register>(), Low32Bits(value)); |
| 3350 | } else { |
| 3351 | __ LoadImmediate(destination.AsRegister<Register>(), High32Bits(value)); |
| 3352 | } |
| 3353 | } else { |
| 3354 | DCHECK(destination.IsDoubleStackSlot()); |
| 3355 | __ LoadImmediate(IP, Low32Bits(value)); |
| 3356 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3357 | __ LoadImmediate(IP, High32Bits(value)); |
| 3358 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 3359 | } |
| 3360 | } else if (constant->IsDoubleConstant()) { |
| 3361 | double value = constant->AsDoubleConstant()->GetValue(); |
| 3362 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
| 3363 | if (destination.IsFpuRegister()) { |
| 3364 | // In the presence of long or double constants, the parallel move resolver will |
| 3365 | // split the move into two, but keeps the same constant for both moves. Here, |
| 3366 | // we use the low or high part depending on which register this move goes to. |
| 3367 | if (destination.reg() % 2 == 0) { |
| 3368 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), |
| 3369 | bit_cast<float, uint32_t>(Low32Bits(int_value))); |
| 3370 | } else { |
| 3371 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), |
| 3372 | bit_cast<float, uint32_t>(High32Bits(int_value))); |
| 3373 | } |
| 3374 | } else { |
| 3375 | DCHECK(destination.IsDoubleStackSlot()); |
| 3376 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 3377 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3378 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 3379 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 3380 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3381 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3382 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3383 | float value = constant->AsFloatConstant()->GetValue(); |
| 3384 | if (destination.IsFpuRegister()) { |
| 3385 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 3386 | } else { |
| 3387 | DCHECK(destination.IsStackSlot()); |
| 3388 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 3389 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 3390 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3391 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 3396 | __ Mov(IP, reg); |
| 3397 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 3398 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 3399 | } |
| 3400 | |
| 3401 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 3402 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 3403 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 3404 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 3405 | SP, mem1 + stack_offset); |
| 3406 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 3407 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 3408 | SP, mem2 + stack_offset); |
| 3409 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 3410 | } |
| 3411 | |
| 3412 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
| 3413 | MoveOperands* move = moves_.Get(index); |
| 3414 | Location source = move->GetSource(); |
| 3415 | Location destination = move->GetDestination(); |
| 3416 | |
| 3417 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3418 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 3419 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 3420 | __ Mov(IP, source.AsRegister<Register>()); |
| 3421 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 3422 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3423 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3424 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3425 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3426 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3427 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 3428 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3429 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3430 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3431 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3432 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 3433 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 3434 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 3435 | : destination.AsFpuRegister<SRegister>(); |
| 3436 | int mem = source.IsFpuRegister() |
| 3437 | ? destination.GetStackIndex() |
| 3438 | : source.GetStackIndex(); |
| 3439 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 3440 | __ vmovrs(IP, reg); |
| 3441 | __ LoadFromOffset(kLoadWord, IP, SP, mem); |
| 3442 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 3443 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 3444 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 3445 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3446 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 3447 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 3452 | __ Push(static_cast<Register>(reg)); |
| 3453 | } |
| 3454 | |
| 3455 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 3456 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3457 | } |
| 3458 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3459 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3460 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 3461 | ? LocationSummary::kCallOnSlowPath |
| 3462 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3463 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3464 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3465 | locations->SetOut(Location::RequiresRegister()); |
| 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3469 | Register out = cls->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3470 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3471 | DCHECK(!cls->CanCallRuntime()); |
| 3472 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3473 | codegen_->LoadCurrentMethod(out); |
| 3474 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3475 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3476 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3477 | codegen_->LoadCurrentMethod(out); |
| 3478 | __ LoadFromOffset( |
| 3479 | kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); |
| 3480 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3481 | |
| 3482 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 3483 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3484 | codegen_->AddSlowPath(slow_path); |
| 3485 | __ cmp(out, ShifterOperand(0)); |
| 3486 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3487 | if (cls->MustGenerateClinitCheck()) { |
| 3488 | GenerateClassInitializationCheck(slow_path, out); |
| 3489 | } else { |
| 3490 | __ Bind(slow_path->GetExitLabel()); |
| 3491 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 3496 | LocationSummary* locations = |
| 3497 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3498 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3499 | if (check->HasUses()) { |
| 3500 | locations->SetOut(Location::SameAsFirstInput()); |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3505 | // We assume the class is not null. |
| 3506 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 3507 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3508 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3509 | GenerateClassInitializationCheck(slow_path, |
| 3510 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3511 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3512 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3513 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
| 3514 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3515 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 3516 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 3517 | __ b(slow_path->GetEntryLabel(), LT); |
| 3518 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 3519 | // properly. Therefore, we do a memory fence. |
| 3520 | __ dmb(ISH); |
| 3521 | __ Bind(slow_path->GetExitLabel()); |
| 3522 | } |
| 3523 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3524 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 3525 | LocationSummary* locations = |
| 3526 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3527 | locations->SetOut(Location::RequiresRegister()); |
| 3528 | } |
| 3529 | |
| 3530 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
| 3531 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 3532 | codegen_->AddSlowPath(slow_path); |
| 3533 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3534 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3535 | codegen_->LoadCurrentMethod(out); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 3536 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 3537 | __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3538 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 3539 | __ cmp(out, ShifterOperand(0)); |
| 3540 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3541 | __ Bind(slow_path->GetExitLabel()); |
| 3542 | } |
| 3543 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3544 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 3545 | LocationSummary* locations = |
| 3546 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3547 | locations->SetOut(Location::RequiresRegister()); |
| 3548 | } |
| 3549 | |
| 3550 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3551 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3552 | int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 3553 | __ LoadFromOffset(kLoadWord, out, TR, offset); |
| 3554 | __ LoadImmediate(IP, 0); |
| 3555 | __ StoreToOffset(kStoreWord, IP, TR, offset); |
| 3556 | } |
| 3557 | |
| 3558 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 3559 | LocationSummary* locations = |
| 3560 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3561 | InvokeRuntimeCallingConvention calling_convention; |
| 3562 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3563 | } |
| 3564 | |
| 3565 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 3566 | codegen_->InvokeRuntime( |
| 3567 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc()); |
| 3568 | } |
| 3569 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3570 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3571 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 3572 | ? LocationSummary::kNoCall |
| 3573 | : LocationSummary::kCallOnSlowPath; |
| 3574 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3575 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3576 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3577 | locations->SetOut(Location::RequiresRegister()); |
| 3578 | } |
| 3579 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3580 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3581 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3582 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3583 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3584 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3585 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3586 | Label done, zero; |
| 3587 | SlowPathCodeARM* slow_path = nullptr; |
| 3588 | |
| 3589 | // Return 0 if `obj` is null. |
| 3590 | // TODO: avoid this check if we know obj is not null. |
| 3591 | __ cmp(obj, ShifterOperand(0)); |
| 3592 | __ b(&zero, EQ); |
| 3593 | // Compare the class of `obj` with `cls`. |
| 3594 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
| 3595 | __ cmp(out, ShifterOperand(cls)); |
| 3596 | if (instruction->IsClassFinal()) { |
| 3597 | // Classes must be equal for the instanceof to succeed. |
| 3598 | __ b(&zero, NE); |
| 3599 | __ LoadImmediate(out, 1); |
| 3600 | __ b(&done); |
| 3601 | } else { |
| 3602 | // If the classes are not equal, we go into a slow path. |
| 3603 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3604 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3605 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3606 | codegen_->AddSlowPath(slow_path); |
| 3607 | __ b(slow_path->GetEntryLabel(), NE); |
| 3608 | __ LoadImmediate(out, 1); |
| 3609 | __ b(&done); |
| 3610 | } |
| 3611 | __ Bind(&zero); |
| 3612 | __ LoadImmediate(out, 0); |
| 3613 | if (slow_path != nullptr) { |
| 3614 | __ Bind(slow_path->GetExitLabel()); |
| 3615 | } |
| 3616 | __ Bind(&done); |
| 3617 | } |
| 3618 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3619 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
| 3620 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3621 | instruction, LocationSummary::kCallOnSlowPath); |
| 3622 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3623 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3624 | locations->AddTemp(Location::RequiresRegister()); |
| 3625 | } |
| 3626 | |
| 3627 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
| 3628 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3629 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3630 | Register cls = locations->InAt(1).AsRegister<Register>(); |
| 3631 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3632 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3633 | |
| 3634 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 3635 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3636 | codegen_->AddSlowPath(slow_path); |
| 3637 | |
| 3638 | // TODO: avoid this check if we know obj is not null. |
| 3639 | __ cmp(obj, ShifterOperand(0)); |
| 3640 | __ b(slow_path->GetExitLabel(), EQ); |
| 3641 | // Compare the class of `obj` with `cls`. |
| 3642 | __ LoadFromOffset(kLoadWord, temp, obj, class_offset); |
| 3643 | __ cmp(temp, ShifterOperand(cls)); |
| 3644 | __ b(slow_path->GetEntryLabel(), NE); |
| 3645 | __ Bind(slow_path->GetExitLabel()); |
| 3646 | } |
| 3647 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3648 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3649 | LocationSummary* locations = |
| 3650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3651 | InvokeRuntimeCallingConvention calling_convention; |
| 3652 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3653 | } |
| 3654 | |
| 3655 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3656 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 3657 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 3658 | instruction, |
| 3659 | instruction->GetDexPc()); |
| 3660 | } |
| 3661 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3662 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3663 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3664 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3665 | |
| 3666 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3667 | LocationSummary* locations = |
| 3668 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3669 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3670 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3671 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3672 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3673 | Location::OutputOverlap output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong) |
| 3674 | ? Location::kOutputOverlap |
| 3675 | : Location::kNoOutputOverlap; |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3676 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
| 3677 | } |
| 3678 | |
| 3679 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 3680 | HandleBitwiseOperation(instruction); |
| 3681 | } |
| 3682 | |
| 3683 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 3684 | HandleBitwiseOperation(instruction); |
| 3685 | } |
| 3686 | |
| 3687 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 3688 | HandleBitwiseOperation(instruction); |
| 3689 | } |
| 3690 | |
| 3691 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3692 | LocationSummary* locations = instruction->GetLocations(); |
| 3693 | |
| 3694 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3695 | Register first = locations->InAt(0).AsRegister<Register>(); |
| 3696 | Register second = locations->InAt(1).AsRegister<Register>(); |
| 3697 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3698 | if (instruction->IsAnd()) { |
| 3699 | __ and_(out, first, ShifterOperand(second)); |
| 3700 | } else if (instruction->IsOr()) { |
| 3701 | __ orr(out, first, ShifterOperand(second)); |
| 3702 | } else { |
| 3703 | DCHECK(instruction->IsXor()); |
| 3704 | __ eor(out, first, ShifterOperand(second)); |
| 3705 | } |
| 3706 | } else { |
| 3707 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3708 | Location first = locations->InAt(0); |
| 3709 | Location second = locations->InAt(1); |
| 3710 | Location out = locations->Out(); |
| 3711 | if (instruction->IsAnd()) { |
| 3712 | __ and_(out.AsRegisterPairLow<Register>(), |
| 3713 | first.AsRegisterPairLow<Register>(), |
| 3714 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3715 | __ and_(out.AsRegisterPairHigh<Register>(), |
| 3716 | first.AsRegisterPairHigh<Register>(), |
| 3717 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3718 | } else if (instruction->IsOr()) { |
| 3719 | __ orr(out.AsRegisterPairLow<Register>(), |
| 3720 | first.AsRegisterPairLow<Register>(), |
| 3721 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3722 | __ orr(out.AsRegisterPairHigh<Register>(), |
| 3723 | first.AsRegisterPairHigh<Register>(), |
| 3724 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3725 | } else { |
| 3726 | DCHECK(instruction->IsXor()); |
| 3727 | __ eor(out.AsRegisterPairLow<Register>(), |
| 3728 | first.AsRegisterPairLow<Register>(), |
| 3729 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3730 | __ eor(out.AsRegisterPairHigh<Register>(), |
| 3731 | first.AsRegisterPairHigh<Register>(), |
| 3732 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3733 | } |
| 3734 | } |
| 3735 | } |
| 3736 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3737 | } // namespace arm |
| 3738 | } // namespace art |