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