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