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 | |
| 1134 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1135 | HandleInvoke(invoke); |
| 1136 | } |
| 1137 | |
| 1138 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1139 | LocationSummary* locations = |
| 1140 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1141 | locations->AddTemp(Location::RegisterLocation(R0)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1142 | |
| 1143 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1144 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1145 | HInstruction* input = invoke->InputAt(i); |
| 1146 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1147 | } |
| 1148 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1149 | locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1152 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1153 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1154 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1155 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1156 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1157 | LocationSummary* locations = invoke->GetLocations(); |
| 1158 | Location receiver = locations->InAt(0); |
| 1159 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1160 | // temp = object->GetClass(); |
| 1161 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1162 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
| 1163 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1164 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1165 | __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1166 | } |
| 1167 | // temp = temp->GetMethodAt(method_offset); |
| 1168 | uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1169 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1170 | // LR = temp->GetEntryPoint(); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1171 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1172 | // LR(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1173 | __ blx(LR); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1174 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1175 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1178 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 1179 | LocationSummary* locations = |
| 1180 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1181 | switch (neg->GetResultType()) { |
| 1182 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1183 | case Primitive::kPrimLong: { |
| 1184 | bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1185 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1186 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1187 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1188 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1189 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1190 | case Primitive::kPrimFloat: |
| 1191 | case Primitive::kPrimDouble: |
| 1192 | LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType(); |
| 1193 | break; |
| 1194 | |
| 1195 | default: |
| 1196 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 1201 | LocationSummary* locations = neg->GetLocations(); |
| 1202 | Location out = locations->Out(); |
| 1203 | Location in = locations->InAt(0); |
| 1204 | switch (neg->GetResultType()) { |
| 1205 | case Primitive::kPrimInt: |
| 1206 | DCHECK(in.IsRegister()); |
Roland Levillain | b762d2e | 2014-10-22 10:11:06 +0100 | [diff] [blame] | 1207 | __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1208 | break; |
| 1209 | |
| 1210 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1211 | DCHECK(in.IsRegisterPair()); |
| 1212 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 1213 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 1214 | in.AsRegisterPairLow<Register>(), |
| 1215 | ShifterOperand(0)); |
| 1216 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 1217 | // instruction here, as it does not exist in the Thumb-2 |
| 1218 | // instruction set. We use the following approach |
| 1219 | // using SBC and SUB instead. |
| 1220 | // |
| 1221 | // out.hi = -C |
| 1222 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1223 | out.AsRegisterPairHigh<Register>(), |
| 1224 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 1225 | // out.hi = out.hi - in.hi |
| 1226 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 1227 | out.AsRegisterPairHigh<Register>(), |
| 1228 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 1229 | break; |
| 1230 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1231 | case Primitive::kPrimFloat: |
| 1232 | case Primitive::kPrimDouble: |
| 1233 | LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType(); |
| 1234 | break; |
| 1235 | |
| 1236 | default: |
| 1237 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1238 | } |
| 1239 | } |
| 1240 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1241 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1242 | LocationSummary* locations = |
| 1243 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1244 | Primitive::Type result_type = conversion->GetResultType(); |
| 1245 | Primitive::Type input_type = conversion->GetInputType(); |
| 1246 | switch (result_type) { |
| 1247 | case Primitive::kPrimLong: |
| 1248 | switch (input_type) { |
| 1249 | case Primitive::kPrimByte: |
| 1250 | case Primitive::kPrimShort: |
| 1251 | case Primitive::kPrimInt: |
| 1252 | // int-to-long conversion. |
| 1253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1254 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1255 | break; |
| 1256 | |
| 1257 | case Primitive::kPrimFloat: |
| 1258 | case Primitive::kPrimDouble: |
| 1259 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1260 | << result_type << " not yet implemented"; |
| 1261 | break; |
| 1262 | |
| 1263 | default: |
| 1264 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1265 | << " to " << result_type; |
| 1266 | } |
| 1267 | break; |
| 1268 | |
| 1269 | case Primitive::kPrimInt: |
| 1270 | case Primitive::kPrimFloat: |
| 1271 | case Primitive::kPrimDouble: |
| 1272 | LOG(FATAL) << "Type conversion from " << input_type |
| 1273 | << " to " << result_type << " not yet implemented"; |
| 1274 | break; |
| 1275 | |
| 1276 | default: |
| 1277 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1278 | << " to " << result_type; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 1283 | LocationSummary* locations = conversion->GetLocations(); |
| 1284 | Location out = locations->Out(); |
| 1285 | Location in = locations->InAt(0); |
| 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 | DCHECK(out.IsRegisterPair()); |
| 1296 | DCHECK(in.IsRegister()); |
| 1297 | __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>()); |
| 1298 | // Sign extension. |
| 1299 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 1300 | out.AsRegisterPairLow<Register>(), |
| 1301 | 31); |
| 1302 | break; |
| 1303 | |
| 1304 | case Primitive::kPrimFloat: |
| 1305 | case Primitive::kPrimDouble: |
| 1306 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1307 | << result_type << " not yet implemented"; |
| 1308 | break; |
| 1309 | |
| 1310 | default: |
| 1311 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1312 | << " to " << result_type; |
| 1313 | } |
| 1314 | break; |
| 1315 | |
| 1316 | case Primitive::kPrimInt: |
| 1317 | case Primitive::kPrimFloat: |
| 1318 | case Primitive::kPrimDouble: |
| 1319 | LOG(FATAL) << "Type conversion from " << input_type |
| 1320 | << " to " << result_type << " not yet implemented"; |
| 1321 | break; |
| 1322 | |
| 1323 | default: |
| 1324 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1325 | << " to " << result_type; |
| 1326 | } |
| 1327 | } |
| 1328 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1329 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1330 | LocationSummary* locations = |
| 1331 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1332 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1333 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1334 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1335 | bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong); |
| 1336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1337 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 1338 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1342 | case Primitive::kPrimFloat: |
| 1343 | case Primitive::kPrimDouble: { |
| 1344 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1345 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1346 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1347 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1348 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1349 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1350 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1351 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1352 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 1356 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1357 | Location out = locations->Out(); |
| 1358 | Location first = locations->InAt(0); |
| 1359 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1360 | switch (add->GetResultType()) { |
| 1361 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1362 | if (second.IsRegister()) { |
| 1363 | __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1364 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1365 | __ AddConstant(out.As<Register>(), |
| 1366 | first.As<Register>(), |
| 1367 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1368 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1369 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1370 | |
| 1371 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1372 | __ adds(out.AsRegisterPairLow<Register>(), |
| 1373 | first.AsRegisterPairLow<Register>(), |
| 1374 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1375 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 1376 | first.AsRegisterPairHigh<Register>(), |
| 1377 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1378 | break; |
| 1379 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1380 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1381 | __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1382 | break; |
| 1383 | |
| 1384 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1385 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1386 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1387 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1388 | break; |
| 1389 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1390 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1391 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1395 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1396 | LocationSummary* locations = |
| 1397 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1398 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1399 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1400 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1401 | bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong); |
| 1402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1403 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 1404 | locations->SetOut(Location::RequiresRegister(), output_overlaps); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1405 | break; |
| 1406 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1407 | case Primitive::kPrimFloat: |
| 1408 | case Primitive::kPrimDouble: { |
| 1409 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1410 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1411 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1412 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1413 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1414 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1415 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1416 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 1420 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1421 | Location out = locations->Out(); |
| 1422 | Location first = locations->InAt(0); |
| 1423 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1424 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1425 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1426 | if (second.IsRegister()) { |
| 1427 | __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1428 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1429 | __ AddConstant(out.As<Register>(), |
| 1430 | first.As<Register>(), |
| 1431 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1432 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1433 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1434 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1435 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1436 | case Primitive::kPrimLong: { |
| 1437 | __ subs(out.AsRegisterPairLow<Register>(), |
| 1438 | first.AsRegisterPairLow<Register>(), |
| 1439 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 1440 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 1441 | first.AsRegisterPairHigh<Register>(), |
| 1442 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1443 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1444 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1445 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1446 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1447 | __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1448 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1452 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1453 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1454 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1455 | break; |
| 1456 | } |
| 1457 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1458 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1459 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1460 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1464 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 1465 | LocationSummary* locations = |
| 1466 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1467 | switch (mul->GetResultType()) { |
| 1468 | case Primitive::kPrimInt: |
| 1469 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1470 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1471 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1472 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1473 | break; |
| 1474 | } |
| 1475 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1476 | case Primitive::kPrimFloat: |
| 1477 | case Primitive::kPrimDouble: { |
| 1478 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1479 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1480 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1481 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1482 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1483 | |
| 1484 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1485 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 1490 | LocationSummary* locations = mul->GetLocations(); |
| 1491 | Location out = locations->Out(); |
| 1492 | Location first = locations->InAt(0); |
| 1493 | Location second = locations->InAt(1); |
| 1494 | switch (mul->GetResultType()) { |
| 1495 | case Primitive::kPrimInt: { |
| 1496 | __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>()); |
| 1497 | break; |
| 1498 | } |
| 1499 | case Primitive::kPrimLong: { |
| 1500 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1501 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1502 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1503 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1504 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 1505 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 1506 | |
| 1507 | // Extra checks to protect caused by the existence of R1_R2. |
| 1508 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 1509 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 1510 | DCHECK_NE(out_hi, in1_lo); |
| 1511 | DCHECK_NE(out_hi, in2_lo); |
| 1512 | |
| 1513 | // input: in1 - 64 bits, in2 - 64 bits |
| 1514 | // output: out |
| 1515 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1516 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1517 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 1518 | |
| 1519 | // IP <- in1.lo * in2.hi |
| 1520 | __ mul(IP, in1_lo, in2_hi); |
| 1521 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1522 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 1523 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 1524 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 1525 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1526 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 1527 | break; |
| 1528 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1529 | |
| 1530 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1531 | __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1532 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1536 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1537 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1538 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1539 | break; |
| 1540 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1541 | |
| 1542 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1543 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1547 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
| 1548 | LocationSummary* locations = |
| 1549 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1550 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1551 | case Primitive::kPrimInt: { |
| 1552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1553 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1554 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1555 | break; |
| 1556 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1557 | case Primitive::kPrimLong: { |
| 1558 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1559 | break; |
| 1560 | } |
| 1561 | case Primitive::kPrimFloat: |
| 1562 | case Primitive::kPrimDouble: { |
| 1563 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1564 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1565 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1566 | break; |
| 1567 | } |
| 1568 | |
| 1569 | default: |
| 1570 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 1575 | LocationSummary* locations = div->GetLocations(); |
| 1576 | Location out = locations->Out(); |
| 1577 | Location first = locations->InAt(0); |
| 1578 | Location second = locations->InAt(1); |
| 1579 | |
| 1580 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1581 | case Primitive::kPrimInt: { |
| 1582 | __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>()); |
| 1583 | break; |
| 1584 | } |
| 1585 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1586 | case Primitive::kPrimLong: { |
| 1587 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1588 | break; |
| 1589 | } |
| 1590 | |
| 1591 | case Primitive::kPrimFloat: { |
| 1592 | __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>()); |
| 1593 | break; |
| 1594 | } |
| 1595 | |
| 1596 | case Primitive::kPrimDouble: { |
| 1597 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 1598 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 1599 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 1600 | break; |
| 1601 | } |
| 1602 | |
| 1603 | default: |
| 1604 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1605 | } |
| 1606 | } |
| 1607 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1608 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1609 | LocationSummary* locations = |
| 1610 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1612 | if (instruction->HasUses()) { |
| 1613 | locations->SetOut(Location::SameAsFirstInput()); |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1618 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
| 1619 | codegen_->AddSlowPath(slow_path); |
| 1620 | |
| 1621 | LocationSummary* locations = instruction->GetLocations(); |
| 1622 | Location value = locations->InAt(0); |
| 1623 | |
| 1624 | DCHECK(value.IsRegister()) << value; |
| 1625 | __ cmp(value.As<Register>(), ShifterOperand(0)); |
| 1626 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1627 | } |
| 1628 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1629 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1630 | LocationSummary* locations = |
| 1631 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1632 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1633 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1634 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1635 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 1639 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1640 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1641 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1642 | codegen_->InvokeRuntime( |
| 1643 | QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1646 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 1647 | LocationSummary* locations = |
| 1648 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1649 | InvokeRuntimeCallingConvention calling_convention; |
| 1650 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1651 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1652 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1653 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1654 | } |
| 1655 | |
| 1656 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
| 1657 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1658 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1659 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1660 | codegen_->InvokeRuntime( |
| 1661 | QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1662 | } |
| 1663 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1664 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1665 | LocationSummary* locations = |
| 1666 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1667 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1668 | if (location.IsStackSlot()) { |
| 1669 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1670 | } else if (location.IsDoubleStackSlot()) { |
| 1671 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1672 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1673 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1677 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1678 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1679 | } |
| 1680 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1681 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1682 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1683 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1684 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1685 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1686 | } |
| 1687 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1688 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 1689 | LocationSummary* locations = not_->GetLocations(); |
| 1690 | Location out = locations->Out(); |
| 1691 | Location in = locations->InAt(0); |
| 1692 | switch (not_->InputAt(0)->GetType()) { |
| 1693 | case Primitive::kPrimBoolean: |
| 1694 | __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1)); |
| 1695 | break; |
| 1696 | |
| 1697 | case Primitive::kPrimInt: |
| 1698 | __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>())); |
| 1699 | break; |
| 1700 | |
| 1701 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1702 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 1703 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 1704 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 1705 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1706 | break; |
| 1707 | |
| 1708 | default: |
| 1709 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1710 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1711 | } |
| 1712 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1713 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1714 | LocationSummary* locations = |
| 1715 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1716 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1717 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1718 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1722 | LocationSummary* locations = compare->GetLocations(); |
| 1723 | switch (compare->InputAt(0)->GetType()) { |
| 1724 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1725 | Register output = locations->Out().As<Register>(); |
| 1726 | Location left = locations->InAt(0); |
| 1727 | Location right = locations->InAt(1); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1728 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1729 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1730 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1731 | __ b(&less, LT); |
| 1732 | __ b(&greater, GT); |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1733 | // Do LoadImmediate before any `cmp`, as LoadImmediate might affect |
| 1734 | // the status flags. |
| 1735 | __ LoadImmediate(output, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1736 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1737 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1738 | __ b(&done, EQ); |
| 1739 | __ b(&less, CC); |
| 1740 | |
| 1741 | __ Bind(&greater); |
| 1742 | __ LoadImmediate(output, 1); |
| 1743 | __ b(&done); |
| 1744 | |
| 1745 | __ Bind(&less); |
| 1746 | __ LoadImmediate(output, -1); |
| 1747 | |
| 1748 | __ Bind(&done); |
| 1749 | break; |
| 1750 | } |
| 1751 | default: |
| 1752 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1753 | } |
| 1754 | } |
| 1755 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1756 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1757 | LocationSummary* locations = |
| 1758 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1759 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1760 | locations->SetInAt(i, Location::Any()); |
| 1761 | } |
| 1762 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1766 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1767 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1768 | } |
| 1769 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1770 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1771 | LocationSummary* locations = |
| 1772 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1773 | bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot; |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1774 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1775 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1776 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1777 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1778 | locations->AddTemp(Location::RequiresRegister()); |
| 1779 | locations->AddTemp(Location::RequiresRegister()); |
| 1780 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1784 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1785 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1786 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1787 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1788 | |
| 1789 | switch (field_type) { |
| 1790 | case Primitive::kPrimBoolean: |
| 1791 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1792 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1793 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 1794 | break; |
| 1795 | } |
| 1796 | |
| 1797 | case Primitive::kPrimShort: |
| 1798 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1799 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1800 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 1801 | break; |
| 1802 | } |
| 1803 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1804 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1805 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1806 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1807 | __ StoreToOffset(kStoreWord, value, obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1808 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1809 | Register temp = locations->GetTemp(0).As<Register>(); |
| 1810 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1811 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1812 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1813 | break; |
| 1814 | } |
| 1815 | |
| 1816 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1817 | Location value = locations->InAt(1); |
| 1818 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1819 | break; |
| 1820 | } |
| 1821 | |
| 1822 | case Primitive::kPrimFloat: |
| 1823 | case Primitive::kPrimDouble: |
| 1824 | LOG(FATAL) << "Unimplemented register type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1825 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1826 | case Primitive::kPrimVoid: |
| 1827 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1828 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1833 | LocationSummary* locations = |
| 1834 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1835 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1836 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1840 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1841 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1842 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1843 | |
| 1844 | switch (instruction->GetType()) { |
| 1845 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1846 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1847 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1848 | break; |
| 1849 | } |
| 1850 | |
| 1851 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1852 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1853 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 1854 | break; |
| 1855 | } |
| 1856 | |
| 1857 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1858 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1859 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 1860 | break; |
| 1861 | } |
| 1862 | |
| 1863 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1864 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1865 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 1866 | break; |
| 1867 | } |
| 1868 | |
| 1869 | case Primitive::kPrimInt: |
| 1870 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1871 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1872 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1873 | break; |
| 1874 | } |
| 1875 | |
| 1876 | case Primitive::kPrimLong: { |
| 1877 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1878 | Location out = locations->Out(); |
| 1879 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1880 | break; |
| 1881 | } |
| 1882 | |
| 1883 | case Primitive::kPrimFloat: |
| 1884 | case Primitive::kPrimDouble: |
| 1885 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1886 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1887 | case Primitive::kPrimVoid: |
| 1888 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1889 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1894 | LocationSummary* locations = |
| 1895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1896 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1897 | if (instruction->HasUses()) { |
| 1898 | locations->SetOut(Location::SameAsFirstInput()); |
| 1899 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1903 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1904 | codegen_->AddSlowPath(slow_path); |
| 1905 | |
| 1906 | LocationSummary* locations = instruction->GetLocations(); |
| 1907 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1908 | |
| 1909 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1910 | __ cmp(obj.As<Register>(), ShifterOperand(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1911 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1912 | } else { |
| 1913 | DCHECK(obj.IsConstant()) << obj; |
| 1914 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1915 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1916 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1917 | } |
| 1918 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1919 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1920 | LocationSummary* locations = |
| 1921 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1923 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1924 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 1928 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1929 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1930 | Location index = locations->InAt(1); |
| 1931 | |
| 1932 | switch (instruction->GetType()) { |
| 1933 | case Primitive::kPrimBoolean: { |
| 1934 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1935 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1936 | if (index.IsConstant()) { |
| 1937 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1938 | __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset); |
| 1939 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1940 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1941 | __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset); |
| 1942 | } |
| 1943 | break; |
| 1944 | } |
| 1945 | |
| 1946 | case Primitive::kPrimByte: { |
| 1947 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1948 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1949 | if (index.IsConstant()) { |
| 1950 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1951 | __ LoadFromOffset(kLoadSignedByte, out, obj, offset); |
| 1952 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1953 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1954 | __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset); |
| 1955 | } |
| 1956 | break; |
| 1957 | } |
| 1958 | |
| 1959 | case Primitive::kPrimShort: { |
| 1960 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1961 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1962 | if (index.IsConstant()) { |
| 1963 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1964 | __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset); |
| 1965 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1966 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1967 | __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset); |
| 1968 | } |
| 1969 | break; |
| 1970 | } |
| 1971 | |
| 1972 | case Primitive::kPrimChar: { |
| 1973 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1974 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1975 | if (index.IsConstant()) { |
| 1976 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1977 | __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset); |
| 1978 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1979 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1980 | __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset); |
| 1981 | } |
| 1982 | break; |
| 1983 | } |
| 1984 | |
| 1985 | case Primitive::kPrimInt: |
| 1986 | case Primitive::kPrimNot: { |
| 1987 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1988 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1989 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1990 | if (index.IsConstant()) { |
| 1991 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1992 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 1993 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1994 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1995 | __ LoadFromOffset(kLoadWord, out, IP, data_offset); |
| 1996 | } |
| 1997 | break; |
| 1998 | } |
| 1999 | |
| 2000 | case Primitive::kPrimLong: { |
| 2001 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2002 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2003 | if (index.IsConstant()) { |
| 2004 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2005 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2006 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2007 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); |
| 2008 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2009 | } |
| 2010 | break; |
| 2011 | } |
| 2012 | |
| 2013 | case Primitive::kPrimFloat: |
| 2014 | case Primitive::kPrimDouble: |
| 2015 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2016 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2017 | case Primitive::kPrimVoid: |
| 2018 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2019 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2024 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2025 | bool is_object = value_type == Primitive::kPrimNot; |
| 2026 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2027 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2028 | if (is_object) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2029 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2030 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2031 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2032 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2033 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2035 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2036 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2037 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 2041 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2042 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2043 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2044 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2045 | |
| 2046 | switch (value_type) { |
| 2047 | case Primitive::kPrimBoolean: |
| 2048 | case Primitive::kPrimByte: { |
| 2049 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2050 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2051 | if (index.IsConstant()) { |
| 2052 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 2053 | __ StoreToOffset(kStoreByte, value, obj, offset); |
| 2054 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2055 | __ add(IP, obj, ShifterOperand(index.As<Register>())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2056 | __ StoreToOffset(kStoreByte, value, IP, data_offset); |
| 2057 | } |
| 2058 | break; |
| 2059 | } |
| 2060 | |
| 2061 | case Primitive::kPrimShort: |
| 2062 | case Primitive::kPrimChar: { |
| 2063 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2064 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2065 | if (index.IsConstant()) { |
| 2066 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 2067 | __ StoreToOffset(kStoreHalfword, value, obj, offset); |
| 2068 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2069 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2070 | __ StoreToOffset(kStoreHalfword, value, IP, data_offset); |
| 2071 | } |
| 2072 | break; |
| 2073 | } |
| 2074 | |
| 2075 | case Primitive::kPrimInt: { |
| 2076 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2077 | Register value = locations->InAt(2).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2078 | if (index.IsConstant()) { |
| 2079 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2080 | __ StoreToOffset(kStoreWord, value, obj, offset); |
| 2081 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2082 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2083 | __ StoreToOffset(kStoreWord, value, IP, data_offset); |
| 2084 | } |
| 2085 | break; |
| 2086 | } |
| 2087 | |
| 2088 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2089 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2090 | break; |
| 2091 | } |
| 2092 | |
| 2093 | case Primitive::kPrimLong: { |
| 2094 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2095 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2096 | if (index.IsConstant()) { |
| 2097 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2098 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2099 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2100 | __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8)); |
| 2101 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2102 | } |
| 2103 | break; |
| 2104 | } |
| 2105 | |
| 2106 | case Primitive::kPrimFloat: |
| 2107 | case Primitive::kPrimDouble: |
| 2108 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2109 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2110 | case Primitive::kPrimVoid: |
| 2111 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2112 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2117 | LocationSummary* locations = |
| 2118 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2119 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2120 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 2124 | LocationSummary* locations = instruction->GetLocations(); |
| 2125 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2126 | Register obj = locations->InAt(0).As<Register>(); |
| 2127 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2128 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 2129 | } |
| 2130 | |
| 2131 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2132 | LocationSummary* locations = |
| 2133 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2134 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2135 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2136 | if (instruction->HasUses()) { |
| 2137 | locations->SetOut(Location::SameAsFirstInput()); |
| 2138 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2142 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2143 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2144 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2145 | codegen_->AddSlowPath(slow_path); |
| 2146 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2147 | Register index = locations->InAt(0).As<Register>(); |
| 2148 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2149 | |
| 2150 | __ cmp(index, ShifterOperand(length)); |
| 2151 | __ b(slow_path->GetEntryLabel(), CS); |
| 2152 | } |
| 2153 | |
| 2154 | void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 2155 | Label is_null; |
| 2156 | __ CompareAndBranchIfZero(value, &is_null); |
| 2157 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value()); |
| 2158 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 2159 | __ strb(card, Address(card, temp)); |
| 2160 | __ Bind(&is_null); |
| 2161 | } |
| 2162 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2163 | void LocationsBuilderARM::VisitTemporary(HTemporary* temp) { |
| 2164 | temp->SetLocations(nullptr); |
| 2165 | } |
| 2166 | |
| 2167 | void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) { |
| 2168 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2169 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2170 | } |
| 2171 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2172 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2173 | UNUSED(instruction); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2174 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2178 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2179 | } |
| 2180 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2181 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2182 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2183 | } |
| 2184 | |
| 2185 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2186 | HBasicBlock* block = instruction->GetBlock(); |
| 2187 | if (block->GetLoopInformation() != nullptr) { |
| 2188 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2189 | // The back edge will generate the suspend check. |
| 2190 | return; |
| 2191 | } |
| 2192 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2193 | // The goto will generate the suspend check. |
| 2194 | return; |
| 2195 | } |
| 2196 | GenerateSuspendCheck(instruction, nullptr); |
| 2197 | } |
| 2198 | |
| 2199 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2200 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2201 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2202 | new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2203 | codegen_->AddSlowPath(slow_path); |
| 2204 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2205 | __ LoadFromOffset( |
| 2206 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value()); |
| 2207 | __ cmp(IP, ShifterOperand(0)); |
| 2208 | // TODO: Figure out the branch offsets and use cbz/cbnz. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2209 | if (successor == nullptr) { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2210 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2211 | __ Bind(slow_path->GetReturnLabel()); |
| 2212 | } else { |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 2213 | __ b(codegen_->GetLabelOf(successor), EQ); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2214 | __ b(slow_path->GetEntryLabel()); |
| 2215 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2218 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 2219 | return codegen_->GetAssembler(); |
| 2220 | } |
| 2221 | |
| 2222 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
| 2223 | MoveOperands* move = moves_.Get(index); |
| 2224 | Location source = move->GetSource(); |
| 2225 | Location destination = move->GetDestination(); |
| 2226 | |
| 2227 | if (source.IsRegister()) { |
| 2228 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2229 | __ Mov(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2230 | } else { |
| 2231 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2232 | __ StoreToOffset(kStoreWord, source.As<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2233 | SP, destination.GetStackIndex()); |
| 2234 | } |
| 2235 | } else if (source.IsStackSlot()) { |
| 2236 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2237 | __ LoadFromOffset(kLoadWord, destination.As<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2238 | SP, source.GetStackIndex()); |
| 2239 | } else { |
| 2240 | DCHECK(destination.IsStackSlot()); |
| 2241 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2242 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 2243 | } |
| 2244 | } else { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2245 | DCHECK(source.IsConstant()); |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 2246 | DCHECK(source.GetConstant()->IsIntConstant()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2247 | int32_t value = source.GetConstant()->AsIntConstant()->GetValue(); |
| 2248 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2249 | __ LoadImmediate(destination.As<Register>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2250 | } else { |
| 2251 | DCHECK(destination.IsStackSlot()); |
| 2252 | __ LoadImmediate(IP, value); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2253 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2254 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 2259 | __ Mov(IP, reg); |
| 2260 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 2261 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 2262 | } |
| 2263 | |
| 2264 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 2265 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 2266 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 2267 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 2268 | SP, mem1 + stack_offset); |
| 2269 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 2270 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 2271 | SP, mem2 + stack_offset); |
| 2272 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 2273 | } |
| 2274 | |
| 2275 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
| 2276 | MoveOperands* move = moves_.Get(index); |
| 2277 | Location source = move->GetSource(); |
| 2278 | Location destination = move->GetDestination(); |
| 2279 | |
| 2280 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2281 | DCHECK_NE(source.As<Register>(), IP); |
| 2282 | DCHECK_NE(destination.As<Register>(), IP); |
| 2283 | __ Mov(IP, source.As<Register>()); |
| 2284 | __ Mov(source.As<Register>(), destination.As<Register>()); |
| 2285 | __ Mov(destination.As<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2286 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2287 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2288 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2289 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2290 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 2291 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 2292 | } else { |
| 2293 | LOG(FATAL) << "Unimplemented"; |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 2298 | __ Push(static_cast<Register>(reg)); |
| 2299 | } |
| 2300 | |
| 2301 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 2302 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2303 | } |
| 2304 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2305 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2306 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2307 | ? LocationSummary::kCallOnSlowPath |
| 2308 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2309 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2310 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2311 | locations->SetOut(Location::RequiresRegister()); |
| 2312 | } |
| 2313 | |
| 2314 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) { |
| 2315 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 2316 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2317 | DCHECK(!cls->CanCallRuntime()); |
| 2318 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2319 | codegen_->LoadCurrentMethod(out); |
| 2320 | __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()); |
| 2321 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2322 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2323 | codegen_->LoadCurrentMethod(out); |
| 2324 | __ LoadFromOffset( |
| 2325 | kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()); |
| 2326 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2327 | |
| 2328 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 2329 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2330 | codegen_->AddSlowPath(slow_path); |
| 2331 | __ cmp(out, ShifterOperand(0)); |
| 2332 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2333 | if (cls->MustGenerateClinitCheck()) { |
| 2334 | GenerateClassInitializationCheck(slow_path, out); |
| 2335 | } else { |
| 2336 | __ Bind(slow_path->GetExitLabel()); |
| 2337 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 2342 | LocationSummary* locations = |
| 2343 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2344 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2345 | if (check->HasUses()) { |
| 2346 | locations->SetOut(Location::SameAsFirstInput()); |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2351 | // We assume the class is not null. |
| 2352 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
| 2353 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2354 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2355 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 2356 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2357 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2358 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
| 2359 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2360 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 2361 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 2362 | __ b(slow_path->GetEntryLabel(), LT); |
| 2363 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 2364 | // properly. Therefore, we do a memory fence. |
| 2365 | __ dmb(ISH); |
| 2366 | __ Bind(slow_path->GetExitLabel()); |
| 2367 | } |
| 2368 | |
| 2369 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2370 | LocationSummary* locations = |
| 2371 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2373 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2374 | } |
| 2375 | |
| 2376 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2377 | LocationSummary* locations = instruction->GetLocations(); |
| 2378 | Register cls = locations->InAt(0).As<Register>(); |
| 2379 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2380 | |
| 2381 | switch (instruction->GetType()) { |
| 2382 | case Primitive::kPrimBoolean: { |
| 2383 | Register out = locations->Out().As<Register>(); |
| 2384 | __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset); |
| 2385 | break; |
| 2386 | } |
| 2387 | |
| 2388 | case Primitive::kPrimByte: { |
| 2389 | Register out = locations->Out().As<Register>(); |
| 2390 | __ LoadFromOffset(kLoadSignedByte, out, cls, offset); |
| 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | case Primitive::kPrimShort: { |
| 2395 | Register out = locations->Out().As<Register>(); |
| 2396 | __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset); |
| 2397 | break; |
| 2398 | } |
| 2399 | |
| 2400 | case Primitive::kPrimChar: { |
| 2401 | Register out = locations->Out().As<Register>(); |
| 2402 | __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset); |
| 2403 | break; |
| 2404 | } |
| 2405 | |
| 2406 | case Primitive::kPrimInt: |
| 2407 | case Primitive::kPrimNot: { |
| 2408 | Register out = locations->Out().As<Register>(); |
| 2409 | __ LoadFromOffset(kLoadWord, out, cls, offset); |
| 2410 | break; |
| 2411 | } |
| 2412 | |
| 2413 | case Primitive::kPrimLong: { |
| 2414 | // TODO: support volatile. |
| 2415 | Location out = locations->Out(); |
| 2416 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset); |
| 2417 | break; |
| 2418 | } |
| 2419 | |
| 2420 | case Primitive::kPrimFloat: |
| 2421 | case Primitive::kPrimDouble: |
| 2422 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 2423 | UNREACHABLE(); |
| 2424 | case Primitive::kPrimVoid: |
| 2425 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2426 | UNREACHABLE(); |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2431 | LocationSummary* locations = |
| 2432 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2433 | bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot; |
| 2434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2435 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2436 | // Temporary registers for the write barrier. |
| 2437 | if (is_object_type) { |
| 2438 | locations->AddTemp(Location::RequiresRegister()); |
| 2439 | locations->AddTemp(Location::RequiresRegister()); |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2444 | LocationSummary* locations = instruction->GetLocations(); |
| 2445 | Register cls = locations->InAt(0).As<Register>(); |
| 2446 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2447 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2448 | |
| 2449 | switch (field_type) { |
| 2450 | case Primitive::kPrimBoolean: |
| 2451 | case Primitive::kPrimByte: { |
| 2452 | Register value = locations->InAt(1).As<Register>(); |
| 2453 | __ StoreToOffset(kStoreByte, value, cls, offset); |
| 2454 | break; |
| 2455 | } |
| 2456 | |
| 2457 | case Primitive::kPrimShort: |
| 2458 | case Primitive::kPrimChar: { |
| 2459 | Register value = locations->InAt(1).As<Register>(); |
| 2460 | __ StoreToOffset(kStoreHalfword, value, cls, offset); |
| 2461 | break; |
| 2462 | } |
| 2463 | |
| 2464 | case Primitive::kPrimInt: |
| 2465 | case Primitive::kPrimNot: { |
| 2466 | Register value = locations->InAt(1).As<Register>(); |
| 2467 | __ StoreToOffset(kStoreWord, value, cls, offset); |
| 2468 | if (field_type == Primitive::kPrimNot) { |
| 2469 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2470 | Register card = locations->GetTemp(1).As<Register>(); |
| 2471 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2472 | } |
| 2473 | break; |
| 2474 | } |
| 2475 | |
| 2476 | case Primitive::kPrimLong: { |
| 2477 | Location value = locations->InAt(1); |
| 2478 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset); |
| 2479 | break; |
| 2480 | } |
| 2481 | |
| 2482 | case Primitive::kPrimFloat: |
| 2483 | case Primitive::kPrimDouble: |
| 2484 | LOG(FATAL) << "Unimplemented register type " << field_type; |
| 2485 | UNREACHABLE(); |
| 2486 | case Primitive::kPrimVoid: |
| 2487 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2488 | UNREACHABLE(); |
| 2489 | } |
| 2490 | } |
| 2491 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2492 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
| 2493 | LocationSummary* locations = |
| 2494 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2495 | locations->SetOut(Location::RequiresRegister()); |
| 2496 | } |
| 2497 | |
| 2498 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) { |
| 2499 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 2500 | codegen_->AddSlowPath(slow_path); |
| 2501 | |
| 2502 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2503 | codegen_->LoadCurrentMethod(out); |
| 2504 | __ LoadFromOffset( |
| 2505 | kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value()); |
| 2506 | __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 2507 | __ cmp(out, ShifterOperand(0)); |
| 2508 | __ b(slow_path->GetEntryLabel(), EQ); |
| 2509 | __ Bind(slow_path->GetExitLabel()); |
| 2510 | } |
| 2511 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame^] | 2512 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 2513 | LocationSummary* locations = |
| 2514 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2515 | locations->SetOut(Location::RequiresRegister()); |
| 2516 | } |
| 2517 | |
| 2518 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
| 2519 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2520 | int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value(); |
| 2521 | __ LoadFromOffset(kLoadWord, out, TR, offset); |
| 2522 | __ LoadImmediate(IP, 0); |
| 2523 | __ StoreToOffset(kStoreWord, IP, TR, offset); |
| 2524 | } |
| 2525 | |
| 2526 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 2527 | LocationSummary* locations = |
| 2528 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2529 | InvokeRuntimeCallingConvention calling_convention; |
| 2530 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2531 | } |
| 2532 | |
| 2533 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
| 2534 | codegen_->InvokeRuntime( |
| 2535 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc()); |
| 2536 | } |
| 2537 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2538 | } // namespace arm |
| 2539 | } // namespace art |