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