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 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 19 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 20 | #include "gc/accounting/card_table.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 21 | #include "mirror/array-inl.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 22 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 23 | #include "mirror/class.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 24 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 25 | #include "utils/arm/assembler_arm.h" |
| 26 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame^] | 27 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 28 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 29 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 31 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | namespace arm { |
| 33 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 34 | static DRegister FromLowSToD(SRegister reg) { |
| 35 | DCHECK_EQ(reg % 2, 0); |
| 36 | return static_cast<DRegister>(reg / 2); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | static constexpr bool kExplicitStackOverflowCheck = false; |
| 40 | |
| 41 | static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7 |
| 42 | static constexpr int kCurrentMethodStackOffset = 0; |
| 43 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 }; |
| 45 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 46 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 47 | static constexpr SRegister kRuntimeParameterFpuRegisters[] = { }; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 48 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 49 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 50 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | public: |
| 52 | InvokeRuntimeCallingConvention() |
| 53 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 54 | kRuntimeParameterCoreRegistersLength, |
| 55 | kRuntimeParameterFpuRegisters, |
| 56 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 60 | }; |
| 61 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | #define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 63 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 65 | class SlowPathCodeARM : public SlowPathCode { |
| 66 | public: |
| 67 | SlowPathCodeARM() : entry_label_(), exit_label_() {} |
| 68 | |
| 69 | Label* GetEntryLabel() { return &entry_label_; } |
| 70 | Label* GetExitLabel() { return &exit_label_; } |
| 71 | |
| 72 | private: |
| 73 | Label entry_label_; |
| 74 | Label exit_label_; |
| 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM); |
| 77 | }; |
| 78 | |
| 79 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 81 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | |
| 83 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 84 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 86 | arm_codegen->InvokeRuntime( |
| 87 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 91 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 92 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 93 | }; |
| 94 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
| 96 | public: |
| 97 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 98 | |
| 99 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 100 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 101 | __ Bind(GetEntryLabel()); |
| 102 | arm_codegen->InvokeRuntime( |
| 103 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc()); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | HDivZeroCheck* const instruction_; |
| 108 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 109 | }; |
| 110 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 111 | class StackOverflowCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 112 | public: |
| 113 | StackOverflowCheckSlowPathARM() {} |
| 114 | |
| 115 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 116 | __ Bind(GetEntryLabel()); |
| 117 | __ LoadFromOffset(kLoadWord, PC, TR, |
| 118 | QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value()); |
| 119 | } |
| 120 | |
| 121 | private: |
| 122 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM); |
| 123 | }; |
| 124 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 125 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 126 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 127 | explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
| 128 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 129 | |
| 130 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 133 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 134 | arm_codegen->InvokeRuntime( |
| 135 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 136 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 137 | if (successor_ == nullptr) { |
| 138 | __ b(GetReturnLabel()); |
| 139 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 140 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 141 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | Label* GetReturnLabel() { |
| 145 | DCHECK(successor_ == nullptr); |
| 146 | return &return_label_; |
| 147 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | |
| 149 | private: |
| 150 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | // If not null, the block to branch to after the suspend check. |
| 152 | HBasicBlock* const successor_; |
| 153 | |
| 154 | // 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] | 155 | Label return_label_; |
| 156 | |
| 157 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 158 | }; |
| 159 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 160 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 162 | BoundsCheckSlowPathARM(HBoundsCheck* instruction, |
| 163 | Location index_location, |
| 164 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 165 | : instruction_(instruction), |
| 166 | index_location_(index_location), |
| 167 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 168 | |
| 169 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 170 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | __ Bind(GetEntryLabel()); |
| 172 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 173 | arm_codegen->Move32( |
| 174 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 175 | arm_codegen->Move32( |
| 176 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_); |
| 177 | arm_codegen->InvokeRuntime( |
| 178 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 182 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | const Location index_location_; |
| 184 | const Location length_location_; |
| 185 | |
| 186 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 187 | }; |
| 188 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 189 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 190 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 191 | LoadClassSlowPathARM(HLoadClass* cls, |
| 192 | HInstruction* at, |
| 193 | uint32_t dex_pc, |
| 194 | bool do_clinit) |
| 195 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 196 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 197 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 198 | |
| 199 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 200 | LocationSummary* locations = at_->GetLocations(); |
| 201 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 202 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 203 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 204 | codegen->SaveLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 206 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 207 | __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 208 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | int32_t entry_point_offset = do_clinit_ |
| 210 | ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 211 | : QUICK_ENTRY_POINT(pInitializeType); |
| 212 | arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_); |
| 213 | |
| 214 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 215 | Location out = locations->Out(); |
| 216 | if (out.IsValid()) { |
| 217 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 218 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 219 | } |
| 220 | codegen->RestoreLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 221 | __ b(GetExitLabel()); |
| 222 | } |
| 223 | |
| 224 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 225 | // The class this slow path will load. |
| 226 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // The instruction where this slow path is happening. |
| 229 | // (Might be the load class or an initialization check). |
| 230 | HInstruction* const at_; |
| 231 | |
| 232 | // The dex PC of `at_`. |
| 233 | const uint32_t dex_pc_; |
| 234 | |
| 235 | // Whether to initialize the class. |
| 236 | const bool do_clinit_; |
| 237 | |
| 238 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | }; |
| 240 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 241 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 242 | public: |
| 243 | explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {} |
| 244 | |
| 245 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 246 | LocationSummary* locations = instruction_->GetLocations(); |
| 247 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 248 | |
| 249 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 250 | __ Bind(GetEntryLabel()); |
| 251 | codegen->SaveLiveRegisters(locations); |
| 252 | |
| 253 | InvokeRuntimeCallingConvention calling_convention; |
| 254 | arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0)); |
| 255 | __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex()); |
| 256 | arm_codegen->InvokeRuntime( |
| 257 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc()); |
| 258 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 259 | |
| 260 | codegen->RestoreLiveRegisters(locations); |
| 261 | __ b(GetExitLabel()); |
| 262 | } |
| 263 | |
| 264 | private: |
| 265 | HLoadString* const instruction_; |
| 266 | |
| 267 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 268 | }; |
| 269 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
| 271 | public: |
| 272 | explicit TypeCheckSlowPathARM(HTypeCheck* instruction, Location object_class) |
| 273 | : instruction_(instruction), |
| 274 | object_class_(object_class) {} |
| 275 | |
| 276 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 277 | LocationSummary* locations = instruction_->GetLocations(); |
| 278 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 279 | |
| 280 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 281 | __ Bind(GetEntryLabel()); |
| 282 | codegen->SaveLiveRegisters(locations); |
| 283 | |
| 284 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 285 | // move resolver. |
| 286 | InvokeRuntimeCallingConvention calling_convention; |
| 287 | MoveOperands move1(locations->InAt(1), |
| 288 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 289 | nullptr); |
| 290 | MoveOperands move2(object_class_, |
| 291 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 292 | nullptr); |
| 293 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 294 | parallel_move.AddMove(&move1); |
| 295 | parallel_move.AddMove(&move2); |
| 296 | arm_codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 297 | |
| 298 | arm_codegen->InvokeRuntime( |
| 299 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, instruction_->GetDexPc()); |
| 300 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 301 | |
| 302 | codegen->RestoreLiveRegisters(locations); |
| 303 | __ b(GetExitLabel()); |
| 304 | } |
| 305 | |
| 306 | private: |
| 307 | HTypeCheck* const instruction_; |
| 308 | const Location object_class_; |
| 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 | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 364 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph) |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 365 | : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 366 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 367 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 368 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 369 | move_resolver_(graph->GetArena(), this), |
| 370 | assembler_(true) {} |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 371 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 372 | size_t CodeGeneratorARM::FrameEntrySpillSize() const { |
| 373 | return kNumberOfPushedRegistersAtEntry * kArmWordSize; |
| 374 | } |
| 375 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 376 | Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 377 | switch (type) { |
| 378 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 379 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 380 | ArmManagedRegister pair = |
| 381 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 382 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 383 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
| 384 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 385 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 386 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 387 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 388 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | case Primitive::kPrimByte: |
| 392 | case Primitive::kPrimBoolean: |
| 393 | case Primitive::kPrimChar: |
| 394 | case Primitive::kPrimShort: |
| 395 | case Primitive::kPrimInt: |
| 396 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 397 | int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 398 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 399 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 400 | ArmManagedRegister current = |
| 401 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 402 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 403 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 404 | } |
| 405 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 406 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 409 | case Primitive::kPrimFloat: { |
| 410 | int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 411 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 412 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 413 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 414 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 415 | int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters); |
| 416 | DCHECK_EQ(reg % 2, 0); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 417 | return Location::FpuRegisterPairLocation(reg, reg + 1); |
| 418 | } |
| 419 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 420 | case Primitive::kPrimVoid: |
| 421 | LOG(FATAL) << "Unreachable type " << type; |
| 422 | } |
| 423 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 424 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 425 | } |
| 426 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 427 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 428 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 429 | blocked_register_pairs_[R1_R2] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 430 | |
| 431 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 432 | blocked_core_registers_[SP] = true; |
| 433 | blocked_core_registers_[LR] = true; |
| 434 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 435 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 436 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 437 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 438 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 439 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 440 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 441 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 442 | // TODO: We currently don't use Quick's callee saved registers. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 443 | // We always save and restore R6 and R7 to make sure we can use three |
| 444 | // register pairs for long operations. |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 445 | blocked_core_registers_[R4] = true; |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 446 | blocked_core_registers_[R5] = true; |
| 447 | blocked_core_registers_[R8] = true; |
| 448 | blocked_core_registers_[R10] = true; |
| 449 | blocked_core_registers_[R11] = true; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 450 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 451 | blocked_fpu_registers_[S16] = true; |
| 452 | blocked_fpu_registers_[S17] = true; |
| 453 | blocked_fpu_registers_[S18] = true; |
| 454 | blocked_fpu_registers_[S19] = true; |
| 455 | blocked_fpu_registers_[S20] = true; |
| 456 | blocked_fpu_registers_[S21] = true; |
| 457 | blocked_fpu_registers_[S22] = true; |
| 458 | blocked_fpu_registers_[S23] = true; |
Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 459 | blocked_fpu_registers_[S24] = true; |
| 460 | blocked_fpu_registers_[S25] = true; |
| 461 | blocked_fpu_registers_[S26] = true; |
| 462 | blocked_fpu_registers_[S27] = true; |
| 463 | blocked_fpu_registers_[S28] = true; |
| 464 | blocked_fpu_registers_[S29] = true; |
| 465 | blocked_fpu_registers_[S30] = true; |
| 466 | blocked_fpu_registers_[S31] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 467 | |
| 468 | UpdateBlockedPairRegisters(); |
| 469 | } |
| 470 | |
| 471 | void CodeGeneratorARM::UpdateBlockedPairRegisters() const { |
| 472 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 473 | ArmManagedRegister current = |
| 474 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 475 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 476 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 477 | blocked_register_pairs_[i] = true; |
| 478 | } |
| 479 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 482 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 483 | : HGraphVisitor(graph), |
| 484 | assembler_(codegen->GetAssembler()), |
| 485 | codegen_(codegen) {} |
| 486 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 487 | void CodeGeneratorARM::GenerateFrameEntry() { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 488 | bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 489 | if (!skip_overflow_check) { |
| 490 | if (kExplicitStackOverflowCheck) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 491 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 492 | AddSlowPath(slow_path); |
| 493 | |
| 494 | __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value()); |
| 495 | __ cmp(SP, ShifterOperand(IP)); |
| 496 | __ b(slow_path->GetEntryLabel(), CC); |
| 497 | } else { |
| 498 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 499 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 500 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 504 | core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7); |
| 505 | __ PushList(1 << LR | 1 << R6 | 1 << R7); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 506 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 507 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 508 | __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize)); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 509 | __ StoreToOffset(kStoreWord, R0, SP, 0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 513 | __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 514 | __ PopList(1 << PC | 1 << R6 | 1 << R7); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 517 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
| 518 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 521 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 522 | switch (load->GetType()) { |
| 523 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 524 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 525 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 526 | break; |
| 527 | |
| 528 | case Primitive::kPrimInt: |
| 529 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 530 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 531 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 532 | |
| 533 | case Primitive::kPrimBoolean: |
| 534 | case Primitive::kPrimByte: |
| 535 | case Primitive::kPrimChar: |
| 536 | case Primitive::kPrimShort: |
| 537 | case Primitive::kPrimVoid: |
| 538 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 539 | } |
| 540 | |
| 541 | LOG(FATAL) << "Unreachable"; |
| 542 | return Location(); |
| 543 | } |
| 544 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 545 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 546 | switch (type) { |
| 547 | case Primitive::kPrimBoolean: |
| 548 | case Primitive::kPrimByte: |
| 549 | case Primitive::kPrimChar: |
| 550 | case Primitive::kPrimShort: |
| 551 | case Primitive::kPrimInt: |
| 552 | case Primitive::kPrimNot: { |
| 553 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 554 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 555 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 556 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 557 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 558 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 559 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 560 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 561 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 562 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 563 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 564 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 565 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 566 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 567 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 568 | ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair( |
| 569 | calling_convention.GetRegisterPairAt(index)); |
| 570 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 571 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 572 | return Location::QuickParameter(index, stack_index); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 573 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 574 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | case Primitive::kPrimFloat: { |
| 579 | uint32_t stack_index = stack_index_++; |
| 580 | if (float_index_ % 2 == 0) { |
| 581 | float_index_ = std::max(double_index_, float_index_); |
| 582 | } |
| 583 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 584 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 585 | } else { |
| 586 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | case Primitive::kPrimDouble: { |
| 591 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 592 | uint32_t stack_index = stack_index_; |
| 593 | stack_index_ += 2; |
| 594 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 595 | uint32_t index = double_index_; |
| 596 | double_index_ += 2; |
| 597 | return Location::FpuRegisterPairLocation( |
| 598 | calling_convention.GetFpuRegisterAt(index), |
| 599 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 600 | } else { |
| 601 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 605 | case Primitive::kPrimVoid: |
| 606 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 607 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 608 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 609 | return Location(); |
| 610 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 611 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 612 | Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) { |
| 613 | switch (type) { |
| 614 | case Primitive::kPrimBoolean: |
| 615 | case Primitive::kPrimByte: |
| 616 | case Primitive::kPrimChar: |
| 617 | case Primitive::kPrimShort: |
| 618 | case Primitive::kPrimInt: |
| 619 | case Primitive::kPrimNot: { |
| 620 | return Location::RegisterLocation(R0); |
| 621 | } |
| 622 | |
| 623 | case Primitive::kPrimFloat: { |
| 624 | return Location::FpuRegisterLocation(S0); |
| 625 | } |
| 626 | |
| 627 | case Primitive::kPrimLong: { |
| 628 | return Location::RegisterPairLocation(R0, R1); |
| 629 | } |
| 630 | |
| 631 | case Primitive::kPrimDouble: { |
| 632 | return Location::FpuRegisterPairLocation(S0, S1); |
| 633 | } |
| 634 | |
| 635 | case Primitive::kPrimVoid: |
| 636 | return Location(); |
| 637 | } |
| 638 | UNREACHABLE(); |
| 639 | return Location(); |
| 640 | } |
| 641 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 642 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 643 | if (source.Equals(destination)) { |
| 644 | return; |
| 645 | } |
| 646 | if (destination.IsRegister()) { |
| 647 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 648 | __ Mov(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 649 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 650 | __ vmovrs(destination.As<Register>(), source.As<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 651 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 652 | __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 653 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 654 | } else if (destination.IsFpuRegister()) { |
| 655 | if (source.IsRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 656 | __ vmovsr(destination.As<SRegister>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 657 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 658 | __ vmovs(destination.As<SRegister>(), source.As<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 659 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 660 | __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 661 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 662 | } else { |
| 663 | DCHECK(destination.IsStackSlot()); |
| 664 | if (source.IsRegister()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 665 | __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 666 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 667 | __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 668 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 669 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 670 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 671 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 677 | if (source.Equals(destination)) { |
| 678 | return; |
| 679 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 680 | if (destination.IsRegisterPair()) { |
| 681 | if (source.IsRegisterPair()) { |
| 682 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 683 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 684 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 685 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 686 | } else if (source.IsQuickParameter()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 687 | uint16_t register_index = source.GetQuickParameterRegisterIndex(); |
| 688 | uint16_t stack_index = source.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 689 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 690 | __ Mov(destination.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 691 | calling_convention.GetRegisterAt(register_index)); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 692 | __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 693 | SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 694 | } else { |
| 695 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 696 | if (destination.AsRegisterPairLow<Register>() == R1) { |
| 697 | DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 698 | __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex()); |
| 699 | __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 700 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 701 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 702 | SP, source.GetStackIndex()); |
| 703 | } |
| 704 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 705 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 706 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 707 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 708 | SP, |
| 709 | source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 710 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 711 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 712 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 713 | } else if (destination.IsQuickParameter()) { |
| 714 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 715 | uint16_t register_index = destination.GetQuickParameterRegisterIndex(); |
| 716 | uint16_t stack_index = destination.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 717 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 718 | __ Mov(calling_convention.GetRegisterAt(register_index), |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 719 | source.AsRegisterPairLow<Register>()); |
| 720 | __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 721 | SP, calling_convention.GetStackOffsetOf(stack_index + 1)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 722 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 723 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 724 | } else { |
| 725 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 726 | __ LoadFromOffset( |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 727 | kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 728 | __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 729 | __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 730 | } |
| 731 | } else { |
| 732 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 733 | if (source.IsRegisterPair()) { |
| 734 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 735 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 736 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 737 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 738 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 739 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 740 | SP, destination.GetStackIndex()); |
| 741 | } |
| 742 | } else if (source.IsQuickParameter()) { |
| 743 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 744 | uint16_t register_index = source.GetQuickParameterRegisterIndex(); |
| 745 | uint16_t stack_index = source.GetQuickParameterStackIndex(); |
| 746 | __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index), |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 747 | SP, destination.GetStackIndex()); |
| 748 | __ LoadFromOffset(kLoadWord, R0, |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 749 | SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 750 | __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 751 | } else if (source.IsFpuRegisterPair()) { |
| 752 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 753 | SP, |
| 754 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 755 | } else { |
| 756 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 757 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 758 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 759 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize)); |
| 760 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | } |
| 764 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 765 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 766 | LocationSummary* locations = instruction->GetLocations(); |
| 767 | if (locations != nullptr && locations->Out().Equals(location)) { |
| 768 | return; |
| 769 | } |
| 770 | |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 771 | if (instruction->IsIntConstant()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 772 | int32_t value = instruction->AsIntConstant()->GetValue(); |
| 773 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 774 | __ LoadImmediate(location.As<Register>(), value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 775 | } else { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 776 | DCHECK(location.IsStackSlot()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 777 | __ LoadImmediate(IP, value); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 778 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 779 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 780 | } else if (instruction->IsLongConstant()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 781 | int64_t value = instruction->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 782 | if (location.IsRegisterPair()) { |
| 783 | __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 784 | __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 785 | } else { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 786 | DCHECK(location.IsDoubleStackSlot()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 787 | __ LoadImmediate(IP, Low32Bits(value)); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 788 | __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 789 | __ LoadImmediate(IP, High32Bits(value)); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 790 | __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 791 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 792 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 793 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 794 | switch (instruction->GetType()) { |
| 795 | case Primitive::kPrimBoolean: |
| 796 | case Primitive::kPrimByte: |
| 797 | case Primitive::kPrimChar: |
| 798 | case Primitive::kPrimShort: |
| 799 | case Primitive::kPrimInt: |
| 800 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 801 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 802 | Move32(location, Location::StackSlot(stack_slot)); |
| 803 | break; |
| 804 | |
| 805 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 806 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 807 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 808 | break; |
| 809 | |
| 810 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 811 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 812 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 813 | } else if (instruction->IsTemporary()) { |
| 814 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 815 | Move32(location, temp_location); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 816 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 817 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 818 | switch (instruction->GetType()) { |
| 819 | case Primitive::kPrimBoolean: |
| 820 | case Primitive::kPrimByte: |
| 821 | case Primitive::kPrimChar: |
| 822 | case Primitive::kPrimShort: |
| 823 | case Primitive::kPrimNot: |
| 824 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 825 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 826 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 830 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 831 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 832 | break; |
| 833 | |
| 834 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 835 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 836 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 840 | void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset, |
| 841 | HInstruction* instruction, |
| 842 | uint32_t dex_pc) { |
| 843 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 844 | __ blx(LR); |
| 845 | RecordPcInfo(instruction, dex_pc); |
| 846 | DCHECK(instruction->IsSuspendCheck() |
| 847 | || instruction->IsBoundsCheck() |
| 848 | || instruction->IsNullCheck() |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 849 | || instruction->IsDivZeroCheck() |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 850 | || !IsLeafMethod()); |
| 851 | } |
| 852 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 853 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 854 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 857 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 858 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 859 | DCHECK(!successor->IsExitBlock()); |
| 860 | |
| 861 | HBasicBlock* block = got->GetBlock(); |
| 862 | HInstruction* previous = got->GetPrevious(); |
| 863 | |
| 864 | HLoopInformation* info = block->GetLoopInformation(); |
| 865 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 866 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 867 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 868 | return; |
| 869 | } |
| 870 | |
| 871 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 872 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 873 | } |
| 874 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 875 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 879 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 880 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 883 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 884 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 885 | if (kIsDebugBuild) { |
| 886 | __ Comment("Unreachable"); |
| 887 | __ bkpt(0); |
| 888 | } |
| 889 | } |
| 890 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 891 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 892 | LocationSummary* locations = |
| 893 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 894 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 895 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 896 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 897 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 898 | } |
| 899 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 900 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 901 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 902 | if (cond->IsIntConstant()) { |
| 903 | // Constant condition, statically compared against 1. |
| 904 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 905 | if (cond_value == 1) { |
| 906 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 907 | if_instr->IfTrueSuccessor())) { |
| 908 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 909 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 910 | return; |
| 911 | } else { |
| 912 | DCHECK_EQ(cond_value, 0); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 913 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 914 | } else { |
| 915 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 916 | // Condition has been materialized, compare the output to 0 |
| 917 | DCHECK(if_instr->GetLocations()->InAt(0).IsRegister()); |
| 918 | __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(), |
| 919 | ShifterOperand(0)); |
| 920 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE); |
| 921 | } else { |
| 922 | // Condition has not been materialized, use its inputs as the |
| 923 | // comparison and its condition as the branch condition. |
| 924 | LocationSummary* locations = cond->GetLocations(); |
| 925 | if (locations->InAt(1).IsRegister()) { |
| 926 | __ cmp(locations->InAt(0).As<Register>(), |
| 927 | ShifterOperand(locations->InAt(1).As<Register>())); |
| 928 | } else { |
| 929 | DCHECK(locations->InAt(1).IsConstant()); |
| 930 | int32_t value = |
| 931 | locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 932 | ShifterOperand operand; |
| 933 | if (ShifterOperand::CanHoldArm(value, &operand)) { |
| 934 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value)); |
| 935 | } else { |
| 936 | Register temp = IP; |
| 937 | __ LoadImmediate(temp, value); |
| 938 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp)); |
| 939 | } |
| 940 | } |
| 941 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), |
| 942 | ARMCondition(cond->AsCondition()->GetCondition())); |
| 943 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 944 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 945 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 946 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 947 | __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 951 | |
| 952 | void LocationsBuilderARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 953 | LocationSummary* locations = |
| 954 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 955 | locations->SetInAt(0, Location::RequiresRegister()); |
| 956 | locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 957 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 958 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 959 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 962 | void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 963 | if (!comp->NeedsMaterialization()) return; |
| 964 | |
| 965 | LocationSummary* locations = comp->GetLocations(); |
| 966 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 967 | __ cmp(locations->InAt(0).As<Register>(), |
| 968 | ShifterOperand(locations->InAt(1).As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 969 | } else { |
| 970 | DCHECK(locations->InAt(1).IsConstant()); |
| 971 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 972 | ShifterOperand operand; |
| 973 | if (ShifterOperand::CanHoldArm(value, &operand)) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 974 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 975 | } else { |
| 976 | Register temp = IP; |
| 977 | __ LoadImmediate(temp, value); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 978 | __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 979 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 980 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 981 | __ it(ARMCondition(comp->GetCondition()), kItElse); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 982 | __ mov(locations->Out().As<Register>(), ShifterOperand(1), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 983 | ARMCondition(comp->GetCondition())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 984 | __ mov(locations->Out().As<Register>(), ShifterOperand(0), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 985 | ARMOppositeCondition(comp->GetCondition())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
| 989 | VisitCondition(comp); |
| 990 | } |
| 991 | |
| 992 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
| 993 | VisitCondition(comp); |
| 994 | } |
| 995 | |
| 996 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
| 997 | VisitCondition(comp); |
| 998 | } |
| 999 | |
| 1000 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
| 1001 | VisitCondition(comp); |
| 1002 | } |
| 1003 | |
| 1004 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
| 1005 | VisitCondition(comp); |
| 1006 | } |
| 1007 | |
| 1008 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
| 1009 | VisitCondition(comp); |
| 1010 | } |
| 1011 | |
| 1012 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1013 | VisitCondition(comp); |
| 1014 | } |
| 1015 | |
| 1016 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1017 | VisitCondition(comp); |
| 1018 | } |
| 1019 | |
| 1020 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1021 | VisitCondition(comp); |
| 1022 | } |
| 1023 | |
| 1024 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
| 1025 | VisitCondition(comp); |
| 1026 | } |
| 1027 | |
| 1028 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1029 | VisitCondition(comp); |
| 1030 | } |
| 1031 | |
| 1032 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1033 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1037 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1040 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 1041 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1044 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1045 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1048 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1049 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1050 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1054 | LocationSummary* locations = |
| 1055 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1056 | switch (store->InputAt(1)->GetType()) { |
| 1057 | case Primitive::kPrimBoolean: |
| 1058 | case Primitive::kPrimByte: |
| 1059 | case Primitive::kPrimChar: |
| 1060 | case Primitive::kPrimShort: |
| 1061 | case Primitive::kPrimInt: |
| 1062 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1063 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1064 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1065 | break; |
| 1066 | |
| 1067 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1068 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1069 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1070 | break; |
| 1071 | |
| 1072 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1073 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1074 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1077 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1078 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1082 | LocationSummary* locations = |
| 1083 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1084 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1087 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1088 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1089 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1092 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1093 | LocationSummary* locations = |
| 1094 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1095 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 1099 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1100 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1103 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1104 | LocationSummary* locations = |
| 1105 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1106 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1107 | } |
| 1108 | |
| 1109 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) { |
| 1110 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1111 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1115 | LocationSummary* locations = |
| 1116 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1117 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1118 | } |
| 1119 | |
| 1120 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1121 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1122 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1125 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1126 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1129 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1130 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1131 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1134 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1135 | LocationSummary* locations = |
| 1136 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1137 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1140 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1141 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1142 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1145 | void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1146 | HandleInvoke(invoke); |
| 1147 | } |
| 1148 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1149 | void CodeGeneratorARM::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1150 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1154 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1155 | |
| 1156 | // TODO: Implement all kinds of calls: |
| 1157 | // 1) boot -> boot |
| 1158 | // 2) app -> boot |
| 1159 | // 3) app -> app |
| 1160 | // |
| 1161 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1162 | |
| 1163 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1164 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1165 | // temp = temp->dex_cache_resolved_methods_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1166 | __ LoadFromOffset( |
| 1167 | kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1168 | // temp = temp[index_in_cache] |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1169 | __ LoadFromOffset( |
| 1170 | kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache())); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1171 | // LR = temp[offset_of_quick_compiled_code] |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1172 | __ LoadFromOffset(kLoadWord, LR, temp, |
| 1173 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1174 | // LR() |
| 1175 | __ blx(LR); |
| 1176 | |
| 1177 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1178 | DCHECK(!codegen_->IsLeafMethod()); |
| 1179 | } |
| 1180 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1181 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1182 | LocationSummary* locations = |
| 1183 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1184 | locations->AddTemp(Location::RegisterLocation(R0)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1185 | |
| 1186 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1187 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1188 | HInstruction* input = invoke->InputAt(i); |
| 1189 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1190 | } |
| 1191 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1192 | locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1195 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1196 | HandleInvoke(invoke); |
| 1197 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1198 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1199 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1200 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1201 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1202 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1203 | LocationSummary* locations = invoke->GetLocations(); |
| 1204 | Location receiver = locations->InAt(0); |
| 1205 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1206 | // temp = object->GetClass(); |
| 1207 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1208 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1209 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1210 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1211 | __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1212 | } |
| 1213 | // temp = temp->GetMethodAt(method_offset); |
| 1214 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1215 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1216 | // LR = temp->GetEntryPoint(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1217 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1218 | // LR(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1219 | __ blx(LR); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1220 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1221 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1224 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1225 | HandleInvoke(invoke); |
| 1226 | // Add the hidden argument. |
| 1227 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 1228 | } |
| 1229 | |
| 1230 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1231 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1232 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
| 1233 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1234 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1235 | LocationSummary* locations = invoke->GetLocations(); |
| 1236 | Location receiver = locations->InAt(0); |
| 1237 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1238 | |
| 1239 | // Set the hidden argument. |
| 1240 | __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex()); |
| 1241 | |
| 1242 | // temp = object->GetClass(); |
| 1243 | if (receiver.IsStackSlot()) { |
| 1244 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1245 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 1246 | } else { |
| 1247 | __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); |
| 1248 | } |
| 1249 | // temp = temp->GetImtEntryAt(method_offset); |
| 1250 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(); |
| 1251 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 1252 | // LR = temp->GetEntryPoint(); |
| 1253 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 1254 | // LR(); |
| 1255 | __ blx(LR); |
| 1256 | DCHECK(!codegen_->IsLeafMethod()); |
| 1257 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1258 | } |
| 1259 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1260 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1261 | LocationSummary* locations = |
| 1262 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1263 | switch (neg->GetResultType()) { |
| 1264 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1265 | case Primitive::kPrimLong: { |
| 1266 | bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1267 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1268 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1269 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1270 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1271 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1272 | case Primitive::kPrimFloat: |
| 1273 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1274 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1275 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1276 | break; |
| 1277 | |
| 1278 | default: |
| 1279 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1284 | LocationSummary* locations = neg->GetLocations(); |
| 1285 | Location out = locations->Out(); |
| 1286 | Location in = locations->InAt(0); |
| 1287 | switch (neg->GetResultType()) { |
| 1288 | case Primitive::kPrimInt: |
| 1289 | DCHECK(in.IsRegister()); |
Roland Levillain | b762d2e | 2014-10-22 10:11:06 +0100 | [diff] [blame] | 1290 | __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1291 | break; |
| 1292 | |
| 1293 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1294 | DCHECK(in.IsRegisterPair()); |
| 1295 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1296 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1297 | in.AsRegisterPairLow<Register>(), |
| 1298 | ShifterOperand(0)); |
| 1299 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1300 | // instruction here, as it does not exist in the Thumb-2 |
| 1301 | // instruction set. We use the following approach |
| 1302 | // using SBC and SUB instead. |
| 1303 | // |
| 1304 | // out.hi = -C |
| 1305 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1306 | out.AsRegisterPairHigh<Register>(), |
| 1307 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1308 | // out.hi = out.hi - in.hi |
| 1309 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1310 | out.AsRegisterPairHigh<Register>(), |
| 1311 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1312 | break; |
| 1313 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1314 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1315 | DCHECK(in.IsFpuRegister()); |
| 1316 | __ vnegs(out.As<SRegister>(), in.As<SRegister>()); |
| 1317 | break; |
| 1318 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1319 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1320 | DCHECK(in.IsFpuRegisterPair()); |
| 1321 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1322 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1323 | break; |
| 1324 | |
| 1325 | default: |
| 1326 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1330 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1331 | LocationSummary* locations = |
| 1332 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1333 | Primitive::Type result_type = conversion->GetResultType(); |
| 1334 | Primitive::Type input_type = conversion->GetInputType(); |
| 1335 | switch (result_type) { |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame^] | 1336 | case Primitive::kPrimInt: |
| 1337 | switch (input_type) { |
| 1338 | case Primitive::kPrimLong: |
| 1339 | // long-to-int conversion. |
| 1340 | locations->SetInAt(0, Location::Any()); |
| 1341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1342 | break; |
| 1343 | |
| 1344 | case Primitive::kPrimFloat: |
| 1345 | case Primitive::kPrimDouble: |
| 1346 | LOG(FATAL) << "Type conversion from " << input_type |
| 1347 | << " to " << result_type << " not yet implemented"; |
| 1348 | break; |
| 1349 | |
| 1350 | default: |
| 1351 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1352 | << " to " << result_type; |
| 1353 | } |
| 1354 | break; |
| 1355 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1356 | case Primitive::kPrimLong: |
| 1357 | switch (input_type) { |
| 1358 | case Primitive::kPrimByte: |
| 1359 | case Primitive::kPrimShort: |
| 1360 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1361 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1362 | // int-to-long conversion. |
| 1363 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1364 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1365 | break; |
| 1366 | |
| 1367 | case Primitive::kPrimFloat: |
| 1368 | case Primitive::kPrimDouble: |
| 1369 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1370 | << result_type << " not yet implemented"; |
| 1371 | break; |
| 1372 | |
| 1373 | default: |
| 1374 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1375 | << " to " << result_type; |
| 1376 | } |
| 1377 | break; |
| 1378 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1379 | case Primitive::kPrimFloat: |
| 1380 | case Primitive::kPrimDouble: |
| 1381 | LOG(FATAL) << "Type conversion from " << input_type |
| 1382 | << " to " << result_type << " not yet implemented"; |
| 1383 | break; |
| 1384 | |
| 1385 | default: |
| 1386 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1387 | << " to " << result_type; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1392 | LocationSummary* locations = conversion->GetLocations(); |
| 1393 | Location out = locations->Out(); |
| 1394 | Location in = locations->InAt(0); |
| 1395 | Primitive::Type result_type = conversion->GetResultType(); |
| 1396 | Primitive::Type input_type = conversion->GetInputType(); |
| 1397 | switch (result_type) { |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame^] | 1398 | case Primitive::kPrimInt: |
| 1399 | switch (input_type) { |
| 1400 | case Primitive::kPrimLong: |
| 1401 | // long-to-int conversion. |
| 1402 | DCHECK(out.IsRegister()); |
| 1403 | if (in.IsRegisterPair()) { |
| 1404 | __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>()); |
| 1405 | } else if (in.IsDoubleStackSlot()) { |
| 1406 | __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex()); |
| 1407 | } else { |
| 1408 | DCHECK(in.IsConstant()); |
| 1409 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1410 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 1411 | __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value)); |
| 1412 | } |
| 1413 | break; |
| 1414 | |
| 1415 | case Primitive::kPrimFloat: |
| 1416 | case Primitive::kPrimDouble: |
| 1417 | LOG(FATAL) << "Type conversion from " << input_type |
| 1418 | << " to " << result_type << " not yet implemented"; |
| 1419 | break; |
| 1420 | |
| 1421 | default: |
| 1422 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1423 | << " to " << result_type; |
| 1424 | } |
| 1425 | break; |
| 1426 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1427 | case Primitive::kPrimLong: |
| 1428 | switch (input_type) { |
| 1429 | case Primitive::kPrimByte: |
| 1430 | case Primitive::kPrimShort: |
| 1431 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1432 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1433 | // int-to-long conversion. |
| 1434 | DCHECK(out.IsRegisterPair()); |
| 1435 | DCHECK(in.IsRegister()); |
| 1436 | __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>()); |
| 1437 | // Sign extension. |
| 1438 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 1439 | out.AsRegisterPairLow<Register>(), |
| 1440 | 31); |
| 1441 | break; |
| 1442 | |
| 1443 | case Primitive::kPrimFloat: |
| 1444 | case Primitive::kPrimDouble: |
| 1445 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1446 | << result_type << " not yet implemented"; |
| 1447 | break; |
| 1448 | |
| 1449 | default: |
| 1450 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1451 | << " to " << result_type; |
| 1452 | } |
| 1453 | break; |
| 1454 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1455 | case Primitive::kPrimFloat: |
| 1456 | case Primitive::kPrimDouble: |
| 1457 | LOG(FATAL) << "Type conversion from " << input_type |
| 1458 | << " to " << result_type << " not yet implemented"; |
| 1459 | break; |
| 1460 | |
| 1461 | default: |
| 1462 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1463 | << " to " << result_type; |
| 1464 | } |
| 1465 | } |
| 1466 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1467 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1468 | LocationSummary* locations = |
| 1469 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1470 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1471 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1472 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1473 | bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong); |
| 1474 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1475 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 1476 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1477 | break; |
| 1478 | } |
| 1479 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1480 | case Primitive::kPrimFloat: |
| 1481 | case Primitive::kPrimDouble: { |
| 1482 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1483 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1484 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1485 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1486 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1487 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1488 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1489 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1490 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 1494 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1495 | Location out = locations->Out(); |
| 1496 | Location first = locations->InAt(0); |
| 1497 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1498 | switch (add->GetResultType()) { |
| 1499 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1500 | if (second.IsRegister()) { |
| 1501 | __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1502 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1503 | __ AddConstant(out.As<Register>(), |
| 1504 | first.As<Register>(), |
| 1505 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1506 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1507 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1508 | |
| 1509 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1510 | __ adds(out.AsRegisterPairLow<Register>(), |
| 1511 | first.AsRegisterPairLow<Register>(), |
| 1512 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1513 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 1514 | first.AsRegisterPairHigh<Register>(), |
| 1515 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1516 | break; |
| 1517 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1518 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1519 | __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1520 | break; |
| 1521 | |
| 1522 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1523 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1524 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1525 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1526 | break; |
| 1527 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1528 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1529 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1533 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1534 | LocationSummary* locations = |
| 1535 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1536 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1537 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1538 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1539 | bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong); |
| 1540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1541 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 1542 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1543 | break; |
| 1544 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1545 | case Primitive::kPrimFloat: |
| 1546 | case Primitive::kPrimDouble: { |
| 1547 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1548 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1549 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1550 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1551 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1552 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1553 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1554 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 1558 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1559 | Location out = locations->Out(); |
| 1560 | Location first = locations->InAt(0); |
| 1561 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1562 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1563 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1564 | if (second.IsRegister()) { |
| 1565 | __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1566 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1567 | __ AddConstant(out.As<Register>(), |
| 1568 | first.As<Register>(), |
| 1569 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1570 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1571 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1572 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1573 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1574 | case Primitive::kPrimLong: { |
| 1575 | __ subs(out.AsRegisterPairLow<Register>(), |
| 1576 | first.AsRegisterPairLow<Register>(), |
| 1577 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1578 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1579 | first.AsRegisterPairHigh<Register>(), |
| 1580 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1581 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1582 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1583 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1584 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1585 | __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1586 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1590 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1591 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1592 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1593 | break; |
| 1594 | } |
| 1595 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1596 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1597 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1598 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1602 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 1603 | LocationSummary* locations = |
| 1604 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1605 | switch (mul->GetResultType()) { |
| 1606 | case Primitive::kPrimInt: |
| 1607 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1608 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1609 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1611 | break; |
| 1612 | } |
| 1613 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1614 | case Primitive::kPrimFloat: |
| 1615 | case Primitive::kPrimDouble: { |
| 1616 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1617 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1618 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1619 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1620 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1621 | |
| 1622 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1623 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 1628 | LocationSummary* locations = mul->GetLocations(); |
| 1629 | Location out = locations->Out(); |
| 1630 | Location first = locations->InAt(0); |
| 1631 | Location second = locations->InAt(1); |
| 1632 | switch (mul->GetResultType()) { |
| 1633 | case Primitive::kPrimInt: { |
| 1634 | __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>()); |
| 1635 | break; |
| 1636 | } |
| 1637 | case Primitive::kPrimLong: { |
| 1638 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1639 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1640 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1641 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1642 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 1643 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 1644 | |
| 1645 | // Extra checks to protect caused by the existence of R1_R2. |
| 1646 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 1647 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 1648 | DCHECK_NE(out_hi, in1_lo); |
| 1649 | DCHECK_NE(out_hi, in2_lo); |
| 1650 | |
| 1651 | // input: in1 - 64 bits, in2 - 64 bits |
| 1652 | // output: out |
| 1653 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1654 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1655 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 1656 | |
| 1657 | // IP <- in1.lo * in2.hi |
| 1658 | __ mul(IP, in1_lo, in2_hi); |
| 1659 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1660 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 1661 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 1662 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 1663 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1664 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 1665 | break; |
| 1666 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1667 | |
| 1668 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1669 | __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1670 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1674 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1675 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1676 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1677 | break; |
| 1678 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1679 | |
| 1680 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1681 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1685 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
| 1686 | LocationSummary* locations = |
| 1687 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1688 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1689 | case Primitive::kPrimInt: { |
| 1690 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1691 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1692 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1693 | break; |
| 1694 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1695 | case Primitive::kPrimLong: { |
| 1696 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1697 | break; |
| 1698 | } |
| 1699 | case Primitive::kPrimFloat: |
| 1700 | case Primitive::kPrimDouble: { |
| 1701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1702 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1703 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1704 | break; |
| 1705 | } |
| 1706 | |
| 1707 | default: |
| 1708 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 1713 | LocationSummary* locations = div->GetLocations(); |
| 1714 | Location out = locations->Out(); |
| 1715 | Location first = locations->InAt(0); |
| 1716 | Location second = locations->InAt(1); |
| 1717 | |
| 1718 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1719 | case Primitive::kPrimInt: { |
| 1720 | __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>()); |
| 1721 | break; |
| 1722 | } |
| 1723 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1724 | case Primitive::kPrimLong: { |
| 1725 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1726 | break; |
| 1727 | } |
| 1728 | |
| 1729 | case Primitive::kPrimFloat: { |
| 1730 | __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
| 1731 | break; |
| 1732 | } |
| 1733 | |
| 1734 | case Primitive::kPrimDouble: { |
| 1735 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1736 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1737 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 1738 | break; |
| 1739 | } |
| 1740 | |
| 1741 | default: |
| 1742 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1743 | } |
| 1744 | } |
| 1745 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1746 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1747 | LocationSummary* locations = |
| 1748 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1750 | if (instruction->HasUses()) { |
| 1751 | locations->SetOut(Location::SameAsFirstInput()); |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1756 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 1757 | codegen_->AddSlowPath(slow_path); |
| 1758 | |
| 1759 | LocationSummary* locations = instruction->GetLocations(); |
| 1760 | Location value = locations->InAt(0); |
| 1761 | |
| 1762 | DCHECK(value.IsRegister()) << value; |
| 1763 | __ cmp(value.As<Register>(), ShifterOperand(0)); |
| 1764 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1765 | } |
| 1766 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1767 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1768 | LocationSummary* locations = |
| 1769 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1770 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1771 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1772 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1773 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 1777 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1778 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1779 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1780 | codegen_->InvokeRuntime( |
| 1781 | QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1782 | } |
| 1783 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1784 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 1785 | LocationSummary* locations = |
| 1786 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1787 | InvokeRuntimeCallingConvention calling_convention; |
| 1788 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1789 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1790 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1791 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1792 | } |
| 1793 | |
| 1794 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 1795 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1796 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1797 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1798 | codegen_->InvokeRuntime( |
| 1799 | QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1800 | } |
| 1801 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1802 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1803 | LocationSummary* locations = |
| 1804 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1805 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1806 | if (location.IsStackSlot()) { |
| 1807 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1808 | } else if (location.IsDoubleStackSlot()) { |
| 1809 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1810 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1811 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1815 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1816 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1817 | } |
| 1818 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1819 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1820 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1821 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1823 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1824 | } |
| 1825 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1826 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 1827 | LocationSummary* locations = not_->GetLocations(); |
| 1828 | Location out = locations->Out(); |
| 1829 | Location in = locations->InAt(0); |
| 1830 | switch (not_->InputAt(0)->GetType()) { |
| 1831 | case Primitive::kPrimBoolean: |
| 1832 | __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1)); |
| 1833 | break; |
| 1834 | |
| 1835 | case Primitive::kPrimInt: |
| 1836 | __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>())); |
| 1837 | break; |
| 1838 | |
| 1839 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1840 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 1841 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 1842 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 1843 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1844 | break; |
| 1845 | |
| 1846 | default: |
| 1847 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1848 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1851 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1852 | LocationSummary* locations = |
| 1853 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1854 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1855 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1856 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1860 | LocationSummary* locations = compare->GetLocations(); |
| 1861 | switch (compare->InputAt(0)->GetType()) { |
| 1862 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1863 | Register output = locations->Out().As<Register>(); |
| 1864 | Location left = locations->InAt(0); |
| 1865 | Location right = locations->InAt(1); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1866 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1867 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1868 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1869 | __ b(&less, LT); |
| 1870 | __ b(&greater, GT); |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1871 | // Do LoadImmediate before any `cmp`, as LoadImmediate might affect |
| 1872 | // the status flags. |
| 1873 | __ LoadImmediate(output, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1874 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1875 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1876 | __ b(&done, EQ); |
| 1877 | __ b(&less, CC); |
| 1878 | |
| 1879 | __ Bind(&greater); |
| 1880 | __ LoadImmediate(output, 1); |
| 1881 | __ b(&done); |
| 1882 | |
| 1883 | __ Bind(&less); |
| 1884 | __ LoadImmediate(output, -1); |
| 1885 | |
| 1886 | __ Bind(&done); |
| 1887 | break; |
| 1888 | } |
| 1889 | default: |
| 1890 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1891 | } |
| 1892 | } |
| 1893 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1894 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1895 | LocationSummary* locations = |
| 1896 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1897 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1898 | locations->SetInAt(i, Location::Any()); |
| 1899 | } |
| 1900 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1904 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1905 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1906 | } |
| 1907 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1908 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1909 | LocationSummary* locations = |
| 1910 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1911 | bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot; |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1913 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1914 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1915 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1916 | locations->AddTemp(Location::RequiresRegister()); |
| 1917 | locations->AddTemp(Location::RequiresRegister()); |
| 1918 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1922 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1923 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1924 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1925 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1926 | |
| 1927 | switch (field_type) { |
| 1928 | case Primitive::kPrimBoolean: |
| 1929 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1930 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1931 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 1932 | break; |
| 1933 | } |
| 1934 | |
| 1935 | case Primitive::kPrimShort: |
| 1936 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1937 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1938 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 1939 | break; |
| 1940 | } |
| 1941 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1942 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1943 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1944 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1945 | __ StoreToOffset(kStoreWord, value, obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1946 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1947 | Register temp = locations->GetTemp(0).As<Register>(); |
| 1948 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1949 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1950 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1951 | break; |
| 1952 | } |
| 1953 | |
| 1954 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1955 | Location value = locations->InAt(1); |
| 1956 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1957 | break; |
| 1958 | } |
| 1959 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1960 | case Primitive::kPrimFloat: { |
| 1961 | SRegister value = locations->InAt(1).As<SRegister>(); |
| 1962 | __ StoreSToOffset(value, obj, offset); |
| 1963 | break; |
| 1964 | } |
| 1965 | |
| 1966 | case Primitive::kPrimDouble: { |
| 1967 | DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()); |
| 1968 | __ StoreDToOffset(value, obj, offset); |
| 1969 | break; |
| 1970 | } |
| 1971 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1972 | case Primitive::kPrimVoid: |
| 1973 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1974 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1979 | LocationSummary* locations = |
| 1980 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1981 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1982 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1986 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1987 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1988 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1989 | |
| 1990 | switch (instruction->GetType()) { |
| 1991 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1992 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1993 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1994 | break; |
| 1995 | } |
| 1996 | |
| 1997 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1998 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1999 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 2000 | break; |
| 2001 | } |
| 2002 | |
| 2003 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2004 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2005 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 2006 | break; |
| 2007 | } |
| 2008 | |
| 2009 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2010 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2011 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 2012 | break; |
| 2013 | } |
| 2014 | |
| 2015 | case Primitive::kPrimInt: |
| 2016 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2017 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2018 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2019 | break; |
| 2020 | } |
| 2021 | |
| 2022 | case Primitive::kPrimLong: { |
| 2023 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2024 | Location out = locations->Out(); |
| 2025 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2026 | break; |
| 2027 | } |
| 2028 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2029 | case Primitive::kPrimFloat: { |
| 2030 | SRegister out = locations->Out().As<SRegister>(); |
| 2031 | __ LoadSFromOffset(out, obj, offset); |
| 2032 | break; |
| 2033 | } |
| 2034 | |
| 2035 | case Primitive::kPrimDouble: { |
| 2036 | DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()); |
| 2037 | __ LoadDFromOffset(out, obj, offset); |
| 2038 | break; |
| 2039 | } |
| 2040 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2041 | case Primitive::kPrimVoid: |
| 2042 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2043 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2048 | LocationSummary* locations = |
| 2049 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2050 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2051 | if (instruction->HasUses()) { |
| 2052 | locations->SetOut(Location::SameAsFirstInput()); |
| 2053 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2057 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2058 | codegen_->AddSlowPath(slow_path); |
| 2059 | |
| 2060 | LocationSummary* locations = instruction->GetLocations(); |
| 2061 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2062 | |
| 2063 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2064 | __ cmp(obj.As<Register>(), ShifterOperand(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2065 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2066 | } else { |
| 2067 | DCHECK(obj.IsConstant()) << obj; |
| 2068 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2069 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2070 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2073 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2074 | LocationSummary* locations = |
| 2075 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2077 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2078 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 2082 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2083 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2084 | Location index = locations->InAt(1); |
| 2085 | |
| 2086 | switch (instruction->GetType()) { |
| 2087 | case Primitive::kPrimBoolean: { |
| 2088 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2089 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2090 | if (index.IsConstant()) { |
| 2091 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2092 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 2093 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2094 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2095 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 2096 | } |
| 2097 | break; |
| 2098 | } |
| 2099 | |
| 2100 | case Primitive::kPrimByte: { |
| 2101 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2102 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2103 | if (index.IsConstant()) { |
| 2104 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2105 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 2106 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2107 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2108 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 2109 | } |
| 2110 | break; |
| 2111 | } |
| 2112 | |
| 2113 | case Primitive::kPrimShort: { |
| 2114 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2115 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2116 | if (index.IsConstant()) { |
| 2117 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2118 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 2119 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2120 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2121 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 2122 | } |
| 2123 | break; |
| 2124 | } |
| 2125 | |
| 2126 | case Primitive::kPrimChar: { |
| 2127 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2128 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2129 | if (index.IsConstant()) { |
| 2130 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2131 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 2132 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2133 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2134 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 2135 | } |
| 2136 | break; |
| 2137 | } |
| 2138 | |
| 2139 | case Primitive::kPrimInt: |
| 2140 | case Primitive::kPrimNot: { |
| 2141 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 2142 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2143 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2144 | if (index.IsConstant()) { |
| 2145 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2146 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2147 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2148 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2149 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 2150 | } |
| 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | case Primitive::kPrimLong: { |
| 2155 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2156 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2157 | if (index.IsConstant()) { |
| 2158 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2159 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2160 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2161 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); |
| 2162 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2163 | } |
| 2164 | break; |
| 2165 | } |
| 2166 | |
| 2167 | case Primitive::kPrimFloat: |
| 2168 | case Primitive::kPrimDouble: |
| 2169 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2170 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2171 | case Primitive::kPrimVoid: |
| 2172 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2173 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2178 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2179 | bool is_object = value_type == Primitive::kPrimNot; |
| 2180 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2181 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2182 | if (is_object) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2183 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2184 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2185 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2186 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2187 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2189 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2190 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2191 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 2195 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2196 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2197 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2198 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2199 | |
| 2200 | switch (value_type) { |
| 2201 | case Primitive::kPrimBoolean: |
| 2202 | case Primitive::kPrimByte: { |
| 2203 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2204 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2205 | if (index.IsConstant()) { |
| 2206 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2207 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 2208 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2209 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2210 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 2211 | } |
| 2212 | break; |
| 2213 | } |
| 2214 | |
| 2215 | case Primitive::kPrimShort: |
| 2216 | case Primitive::kPrimChar: { |
| 2217 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2218 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2219 | if (index.IsConstant()) { |
| 2220 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2221 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 2222 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2223 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2224 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 2225 | } |
| 2226 | break; |
| 2227 | } |
| 2228 | |
| 2229 | case Primitive::kPrimInt: { |
| 2230 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2231 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2232 | if (index.IsConstant()) { |
| 2233 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2234 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 2235 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2236 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2237 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 2238 | } |
| 2239 | break; |
| 2240 | } |
| 2241 | |
| 2242 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2243 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2244 | break; |
| 2245 | } |
| 2246 | |
| 2247 | case Primitive::kPrimLong: { |
| 2248 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2249 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2250 | if (index.IsConstant()) { |
| 2251 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2252 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2253 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2254 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); |
| 2255 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2256 | } |
| 2257 | break; |
| 2258 | } |
| 2259 | |
| 2260 | case Primitive::kPrimFloat: |
| 2261 | case Primitive::kPrimDouble: |
| 2262 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2263 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2264 | case Primitive::kPrimVoid: |
| 2265 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2266 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2271 | LocationSummary* locations = |
| 2272 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2273 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2274 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 2278 | LocationSummary* locations = instruction->GetLocations(); |
| 2279 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2280 | Register obj = locations->InAt(0).As<Register>(); |
| 2281 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2282 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2283 | } |
| 2284 | |
| 2285 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2286 | LocationSummary* locations = |
| 2287 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2288 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2289 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2290 | if (instruction->HasUses()) { |
| 2291 | locations->SetOut(Location::SameAsFirstInput()); |
| 2292 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2296 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2297 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2298 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2299 | codegen_->AddSlowPath(slow_path); |
| 2300 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2301 | Register index = locations->InAt(0).As<Register>(); |
| 2302 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2303 | |
| 2304 | __ cmp(index, ShifterOperand(length)); |
| 2305 | __ b(slow_path->GetEntryLabel(), CS); |
| 2306 | } |
| 2307 | |
| 2308 | void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 2309 | Label is_null; |
| 2310 | __ CompareAndBranchIfZero(value, &is_null); |
| 2311 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 2312 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 2313 | __ strb(card, Address(card, temp)); |
| 2314 | __ Bind(&is_null); |
| 2315 | } |
| 2316 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2317 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 2318 | temp->SetLocations(nullptr); |
| 2319 | } |
| 2320 | |
| 2321 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 2322 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2323 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2324 | } |
| 2325 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2326 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2327 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2328 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2332 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2333 | } |
| 2334 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2335 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2336 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2337 | } |
| 2338 | |
| 2339 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2340 | HBasicBlock* block = instruction->GetBlock(); |
| 2341 | if (block->GetLoopInformation() != nullptr) { |
| 2342 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2343 | // The back edge will generate the suspend check. |
| 2344 | return; |
| 2345 | } |
| 2346 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2347 | // The goto will generate the suspend check. |
| 2348 | return; |
| 2349 | } |
| 2350 | GenerateSuspendCheck(instruction, nullptr); |
| 2351 | } |
| 2352 | |
| 2353 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2354 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2355 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2356 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2357 | codegen_->AddSlowPath(slow_path); |
| 2358 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2359 | __ LoadFromOffset( |
| 2360 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
| 2361 | __ cmp(IP, ShifterOperand(0)); |
| 2362 | // TODO: Figure out the branch offsets and use cbz/cbnz. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2363 | if (successor == nullptr) { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2364 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2365 | __ Bind(slow_path->GetReturnLabel()); |
| 2366 | } else { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2367 | __ b(codegen_->GetLabelOf(successor), EQ); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2368 | __ b(slow_path->GetEntryLabel()); |
| 2369 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2370 | } |
| 2371 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2372 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 2373 | return codegen_->GetAssembler(); |
| 2374 | } |
| 2375 | |
| 2376 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
| 2377 | MoveOperands* move = moves_.Get(index); |
| 2378 | Location source = move->GetSource(); |
| 2379 | Location destination = move->GetDestination(); |
| 2380 | |
| 2381 | if (source.IsRegister()) { |
| 2382 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2383 | __ Mov(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2384 | } else { |
| 2385 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2386 | __ StoreToOffset(kStoreWord, source.As<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2387 | SP, destination.GetStackIndex()); |
| 2388 | } |
| 2389 | } else if (source.IsStackSlot()) { |
| 2390 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2391 | __ LoadFromOffset(kLoadWord, destination.As<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2392 | SP, source.GetStackIndex()); |
| 2393 | } else { |
| 2394 | DCHECK(destination.IsStackSlot()); |
| 2395 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2396 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 2397 | } |
| 2398 | } else { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2399 | DCHECK(source.IsConstant()); |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 2400 | DCHECK(source.GetConstant()->IsIntConstant()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2401 | int32_t value = source.GetConstant()->AsIntConstant()->GetValue(); |
| 2402 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2403 | __ LoadImmediate(destination.As<Register>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2404 | } else { |
| 2405 | DCHECK(destination.IsStackSlot()); |
| 2406 | __ LoadImmediate(IP, value); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2407 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2408 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 2413 | __ Mov(IP, reg); |
| 2414 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 2415 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 2416 | } |
| 2417 | |
| 2418 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 2419 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 2420 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 2421 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 2422 | SP, mem1 + stack_offset); |
| 2423 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 2424 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 2425 | SP, mem2 + stack_offset); |
| 2426 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 2427 | } |
| 2428 | |
| 2429 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
| 2430 | MoveOperands* move = moves_.Get(index); |
| 2431 | Location source = move->GetSource(); |
| 2432 | Location destination = move->GetDestination(); |
| 2433 | |
| 2434 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2435 | DCHECK_NE(source.As<Register>(), IP); |
| 2436 | DCHECK_NE(destination.As<Register>(), IP); |
| 2437 | __ Mov(IP, source.As<Register>()); |
| 2438 | __ Mov(source.As<Register>(), destination.As<Register>()); |
| 2439 | __ Mov(destination.As<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2440 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2441 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2442 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2443 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2444 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 2445 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 2446 | } else { |
| 2447 | LOG(FATAL) << "Unimplemented"; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 2452 | __ Push(static_cast<Register>(reg)); |
| 2453 | } |
| 2454 | |
| 2455 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 2456 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2457 | } |
| 2458 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2459 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2460 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2461 | ? LocationSummary::kCallOnSlowPath |
| 2462 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2463 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2464 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2465 | locations->SetOut(Location::RequiresRegister()); |
| 2466 | } |
| 2467 | |
| 2468 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
| 2469 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 2470 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2471 | DCHECK(!cls->CanCallRuntime()); |
| 2472 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2473 | codegen_->LoadCurrentMethod(out); |
| 2474 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 2475 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2476 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2477 | codegen_->LoadCurrentMethod(out); |
| 2478 | __ LoadFromOffset( |
| 2479 | kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); |
| 2480 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2481 | |
| 2482 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 2483 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2484 | codegen_->AddSlowPath(slow_path); |
| 2485 | __ cmp(out, ShifterOperand(0)); |
| 2486 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2487 | if (cls->MustGenerateClinitCheck()) { |
| 2488 | GenerateClassInitializationCheck(slow_path, out); |
| 2489 | } else { |
| 2490 | __ Bind(slow_path->GetExitLabel()); |
| 2491 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 2496 | LocationSummary* locations = |
| 2497 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2498 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2499 | if (check->HasUses()) { |
| 2500 | locations->SetOut(Location::SameAsFirstInput()); |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2505 | // We assume the class is not null. |
| 2506 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 2507 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2508 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2509 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 2510 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2511 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2512 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
| 2513 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2514 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 2515 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 2516 | __ b(slow_path->GetEntryLabel(), LT); |
| 2517 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 2518 | // properly. Therefore, we do a memory fence. |
| 2519 | __ dmb(ISH); |
| 2520 | __ Bind(slow_path->GetExitLabel()); |
| 2521 | } |
| 2522 | |
| 2523 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2524 | LocationSummary* locations = |
| 2525 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2527 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2528 | } |
| 2529 | |
| 2530 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2531 | LocationSummary* locations = instruction->GetLocations(); |
| 2532 | Register cls = locations->InAt(0).As<Register>(); |
| 2533 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2534 | |
| 2535 | switch (instruction->GetType()) { |
| 2536 | case Primitive::kPrimBoolean: { |
| 2537 | Register out = locations->Out().As<Register>(); |
| 2538 | __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset); |
| 2539 | break; |
| 2540 | } |
| 2541 | |
| 2542 | case Primitive::kPrimByte: { |
| 2543 | Register out = locations->Out().As<Register>(); |
| 2544 | __ LoadFromOffset(kLoadSignedByte, out, cls, offset); |
| 2545 | break; |
| 2546 | } |
| 2547 | |
| 2548 | case Primitive::kPrimShort: { |
| 2549 | Register out = locations->Out().As<Register>(); |
| 2550 | __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset); |
| 2551 | break; |
| 2552 | } |
| 2553 | |
| 2554 | case Primitive::kPrimChar: { |
| 2555 | Register out = locations->Out().As<Register>(); |
| 2556 | __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset); |
| 2557 | break; |
| 2558 | } |
| 2559 | |
| 2560 | case Primitive::kPrimInt: |
| 2561 | case Primitive::kPrimNot: { |
| 2562 | Register out = locations->Out().As<Register>(); |
| 2563 | __ LoadFromOffset(kLoadWord, out, cls, offset); |
| 2564 | break; |
| 2565 | } |
| 2566 | |
| 2567 | case Primitive::kPrimLong: { |
| 2568 | // TODO: support volatile. |
| 2569 | Location out = locations->Out(); |
| 2570 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset); |
| 2571 | break; |
| 2572 | } |
| 2573 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2574 | case Primitive::kPrimFloat: { |
| 2575 | SRegister out = locations->Out().As<SRegister>(); |
| 2576 | __ LoadSFromOffset(out, cls, offset); |
| 2577 | break; |
| 2578 | } |
| 2579 | |
| 2580 | case Primitive::kPrimDouble: { |
| 2581 | DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()); |
| 2582 | __ LoadDFromOffset(out, cls, offset); |
| 2583 | break; |
| 2584 | } |
| 2585 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2586 | case Primitive::kPrimVoid: |
| 2587 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2588 | UNREACHABLE(); |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2593 | LocationSummary* locations = |
| 2594 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2595 | bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot; |
| 2596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2597 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2598 | // Temporary registers for the write barrier. |
| 2599 | if (is_object_type) { |
| 2600 | locations->AddTemp(Location::RequiresRegister()); |
| 2601 | locations->AddTemp(Location::RequiresRegister()); |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2606 | LocationSummary* locations = instruction->GetLocations(); |
| 2607 | Register cls = locations->InAt(0).As<Register>(); |
| 2608 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2609 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2610 | |
| 2611 | switch (field_type) { |
| 2612 | case Primitive::kPrimBoolean: |
| 2613 | case Primitive::kPrimByte: { |
| 2614 | Register value = locations->InAt(1).As<Register>(); |
| 2615 | __ StoreToOffset(kStoreByte, value, cls, offset); |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | case Primitive::kPrimShort: |
| 2620 | case Primitive::kPrimChar: { |
| 2621 | Register value = locations->InAt(1).As<Register>(); |
| 2622 | __ StoreToOffset(kStoreHalfword, value, cls, offset); |
| 2623 | break; |
| 2624 | } |
| 2625 | |
| 2626 | case Primitive::kPrimInt: |
| 2627 | case Primitive::kPrimNot: { |
| 2628 | Register value = locations->InAt(1).As<Register>(); |
| 2629 | __ StoreToOffset(kStoreWord, value, cls, offset); |
| 2630 | if (field_type == Primitive::kPrimNot) { |
| 2631 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2632 | Register card = locations->GetTemp(1).As<Register>(); |
| 2633 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2634 | } |
| 2635 | break; |
| 2636 | } |
| 2637 | |
| 2638 | case Primitive::kPrimLong: { |
| 2639 | Location value = locations->InAt(1); |
| 2640 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset); |
| 2641 | break; |
| 2642 | } |
| 2643 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimFloat: { |
| 2645 | SRegister value = locations->InAt(1).As<SRegister>(); |
| 2646 | __ StoreSToOffset(value, cls, offset); |
| 2647 | break; |
| 2648 | } |
| 2649 | |
| 2650 | case Primitive::kPrimDouble: { |
| 2651 | DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()); |
| 2652 | __ StoreDToOffset(value, cls, offset); |
| 2653 | break; |
| 2654 | } |
| 2655 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2656 | case Primitive::kPrimVoid: |
| 2657 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2658 | UNREACHABLE(); |
| 2659 | } |
| 2660 | } |
| 2661 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2662 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 2663 | LocationSummary* locations = |
| 2664 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2665 | locations->SetOut(Location::RequiresRegister()); |
| 2666 | } |
| 2667 | |
| 2668 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
| 2669 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 2670 | codegen_->AddSlowPath(slow_path); |
| 2671 | |
| 2672 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2673 | codegen_->LoadCurrentMethod(out); |
| 2674 | __ LoadFromOffset( |
| 2675 | kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value()); |
| 2676 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 2677 | __ cmp(out, ShifterOperand(0)); |
| 2678 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2679 | __ Bind(slow_path->GetExitLabel()); |
| 2680 | } |
| 2681 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2682 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 2683 | LocationSummary* locations = |
| 2684 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2685 | locations->SetOut(Location::RequiresRegister()); |
| 2686 | } |
| 2687 | |
| 2688 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
| 2689 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2690 | int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 2691 | __ LoadFromOffset(kLoadWord, out, TR, offset); |
| 2692 | __ LoadImmediate(IP, 0); |
| 2693 | __ StoreToOffset(kStoreWord, IP, TR, offset); |
| 2694 | } |
| 2695 | |
| 2696 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 2697 | LocationSummary* locations = |
| 2698 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2699 | InvokeRuntimeCallingConvention calling_convention; |
| 2700 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2701 | } |
| 2702 | |
| 2703 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 2704 | codegen_->InvokeRuntime( |
| 2705 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc()); |
| 2706 | } |
| 2707 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2708 | void LocationsBuilderARM::VisitTypeCheck(HTypeCheck* instruction) { |
| 2709 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 2710 | ? LocationSummary::kNoCall |
| 2711 | : LocationSummary::kCallOnSlowPath; |
| 2712 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2714 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2715 | locations->SetOut(Location::RequiresRegister()); |
| 2716 | } |
| 2717 | |
| 2718 | void InstructionCodeGeneratorARM::VisitTypeCheck(HTypeCheck* instruction) { |
| 2719 | LocationSummary* locations = instruction->GetLocations(); |
| 2720 | Register obj = locations->InAt(0).As<Register>(); |
| 2721 | Register cls = locations->InAt(1).As<Register>(); |
| 2722 | Register out = locations->Out().As<Register>(); |
| 2723 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2724 | Label done, zero; |
| 2725 | SlowPathCodeARM* slow_path = nullptr; |
| 2726 | |
| 2727 | // Return 0 if `obj` is null. |
| 2728 | // TODO: avoid this check if we know obj is not null. |
| 2729 | __ cmp(obj, ShifterOperand(0)); |
| 2730 | __ b(&zero, EQ); |
| 2731 | // Compare the class of `obj` with `cls`. |
| 2732 | __ LoadFromOffset(kLoadWord, out, obj, class_offset); |
| 2733 | __ cmp(out, ShifterOperand(cls)); |
| 2734 | if (instruction->IsClassFinal()) { |
| 2735 | // Classes must be equal for the instanceof to succeed. |
| 2736 | __ b(&zero, NE); |
| 2737 | __ LoadImmediate(out, 1); |
| 2738 | __ b(&done); |
| 2739 | } else { |
| 2740 | // If the classes are not equal, we go into a slow path. |
| 2741 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2742 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM( |
| 2743 | instruction, Location::RegisterLocation(out)); |
| 2744 | codegen_->AddSlowPath(slow_path); |
| 2745 | __ b(slow_path->GetEntryLabel(), NE); |
| 2746 | __ LoadImmediate(out, 1); |
| 2747 | __ b(&done); |
| 2748 | } |
| 2749 | __ Bind(&zero); |
| 2750 | __ LoadImmediate(out, 0); |
| 2751 | if (slow_path != nullptr) { |
| 2752 | __ Bind(slow_path->GetExitLabel()); |
| 2753 | } |
| 2754 | __ Bind(&done); |
| 2755 | } |
| 2756 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2757 | } // namespace arm |
| 2758 | } // namespace art |