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