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