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