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