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