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