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