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" |
| 18 | #include "utils/assembler.h" |
| 19 | #include "utils/arm/assembler_arm.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 20 | #include "utils/arm/managed_register_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 21 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 23 | #include "mirror/array.h" |
| 24 | #include "mirror/art_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "thread.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 26 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 27 | #define __ reinterpret_cast<ArmAssembler*>(GetAssembler())-> |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 28 | |
| 29 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 30 | |
| 31 | arm::ArmManagedRegister Location::AsArm() const { |
| 32 | return reg().AsArm(); |
| 33 | } |
| 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace arm { |
| 36 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 37 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 38 | static constexpr int kCurrentMethodStackOffset = 0; |
| 39 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 40 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 41 | stream << ArmManagedRegister::FromCoreRegister(Register(reg)); |
| 42 | } |
| 43 | |
| 44 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 45 | stream << ArmManagedRegister::FromDRegister(DRegister(reg)); |
| 46 | } |
| 47 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 48 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph) |
| 49 | : CodeGenerator(graph, kNumberOfRegIds), |
| 50 | location_builder_(graph, this), |
| 51 | instruction_visitor_(graph, this) {} |
| 52 | |
| 53 | static bool* GetBlockedRegisterPairs(bool* blocked_registers) { |
| 54 | return blocked_registers + kNumberOfAllocIds; |
| 55 | } |
| 56 | |
| 57 | ManagedRegister CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type, |
| 58 | bool* blocked_registers) const { |
| 59 | switch (type) { |
| 60 | case Primitive::kPrimLong: { |
| 61 | size_t reg = AllocateFreeRegisterInternal( |
| 62 | GetBlockedRegisterPairs(blocked_registers), kNumberOfRegisterPairs); |
| 63 | ArmManagedRegister pair = |
| 64 | ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
| 65 | blocked_registers[pair.AsRegisterPairLow()] = true; |
| 66 | blocked_registers[pair.AsRegisterPairHigh()] = true; |
| 67 | return pair; |
| 68 | } |
| 69 | |
| 70 | case Primitive::kPrimByte: |
| 71 | case Primitive::kPrimBoolean: |
| 72 | case Primitive::kPrimChar: |
| 73 | case Primitive::kPrimShort: |
| 74 | case Primitive::kPrimInt: |
| 75 | case Primitive::kPrimNot: { |
| 76 | size_t reg = AllocateFreeRegisterInternal(blocked_registers, kNumberOfCoreRegisters); |
| 77 | return ArmManagedRegister::FromCoreRegister(static_cast<Register>(reg)); |
| 78 | } |
| 79 | |
| 80 | case Primitive::kPrimFloat: |
| 81 | case Primitive::kPrimDouble: |
| 82 | LOG(FATAL) << "Unimplemented register type " << type; |
| 83 | |
| 84 | case Primitive::kPrimVoid: |
| 85 | LOG(FATAL) << "Unreachable type " << type; |
| 86 | } |
| 87 | |
| 88 | return ManagedRegister::NoRegister(); |
| 89 | } |
| 90 | |
| 91 | void CodeGeneratorARM::SetupBlockedRegisters(bool* blocked_registers) const { |
| 92 | bool* blocked_register_pairs = GetBlockedRegisterPairs(blocked_registers); |
| 93 | |
| 94 | // Don't allocate the dalvik style register pair passing. |
| 95 | blocked_register_pairs[R1_R2] = true; |
| 96 | |
| 97 | // Stack register, LR and PC are always reserved. |
| 98 | blocked_registers[SP] = true; |
| 99 | blocked_registers[LR] = true; |
| 100 | blocked_registers[PC] = true; |
| 101 | |
| 102 | // Reserve R4 for suspend check. |
| 103 | blocked_registers[R4] = true; |
| 104 | blocked_register_pairs[R4_R5] = true; |
| 105 | |
| 106 | // Reserve thread register. |
| 107 | blocked_registers[TR] = true; |
| 108 | |
| 109 | // TODO: We currently don't use Quick's callee saved registers. |
| 110 | blocked_registers[R5] = true; |
| 111 | blocked_registers[R6] = true; |
| 112 | blocked_registers[R7] = true; |
| 113 | blocked_registers[R8] = true; |
| 114 | blocked_registers[R10] = true; |
| 115 | blocked_registers[R11] = true; |
| 116 | blocked_register_pairs[R6_R7] = true; |
| 117 | } |
| 118 | |
| 119 | size_t CodeGeneratorARM::GetNumberOfRegisters() const { |
| 120 | return kNumberOfRegIds; |
| 121 | } |
| 122 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 123 | static Location ArmCoreLocation(Register reg) { |
| 124 | return Location::RegisterLocation(ArmManagedRegister::FromCoreRegister(reg)); |
| 125 | } |
| 126 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 127 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 128 | : HGraphVisitor(graph), |
| 129 | assembler_(codegen->GetAssembler()), |
| 130 | codegen_(codegen) {} |
| 131 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 132 | void CodeGeneratorARM::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 133 | core_spill_mask_ |= (1 << LR); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 134 | __ PushList((1 << LR)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 135 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 136 | SetFrameSize(RoundUp( |
| 137 | (GetGraph()->GetMaximumNumberOfOutVRegs() + GetGraph()->GetNumberOfVRegs()) * kVRegSize |
| 138 | + kVRegSize // filler |
| 139 | + kArmWordSize // Art method |
| 140 | + kNumberOfPushedRegistersAtEntry * kArmWordSize, |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 141 | kStackAlignment)); |
| 142 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 143 | __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 144 | __ str(R0, Address(SP, 0)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 148 | __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 149 | __ PopList((1 << PC)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void CodeGeneratorARM::Bind(Label* label) { |
| 153 | __ Bind(label); |
| 154 | } |
| 155 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 156 | int32_t CodeGeneratorARM::GetStackSlot(HLocal* local) const { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 157 | uint16_t reg_number = local->GetRegNumber(); |
| 158 | uint16_t number_of_vregs = GetGraph()->GetNumberOfVRegs(); |
| 159 | uint16_t number_of_in_vregs = GetGraph()->GetNumberOfInVRegs(); |
| 160 | if (reg_number >= number_of_vregs - number_of_in_vregs) { |
| 161 | // Local is a parameter of the method. It is stored in the caller's frame. |
| 162 | return GetFrameSize() + kArmWordSize // ART method |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 163 | + (reg_number - number_of_vregs + number_of_in_vregs) * kVRegSize; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 164 | } else { |
| 165 | // Local is a temporary in this method. It is stored in this method's frame. |
| 166 | return GetFrameSize() - (kNumberOfPushedRegistersAtEntry * kArmWordSize) |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 167 | - kVRegSize // filler. |
| 168 | - (number_of_vregs * kVRegSize) |
| 169 | + (reg_number * kVRegSize); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 170 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 173 | Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const { |
| 174 | switch (load->GetType()) { |
| 175 | case Primitive::kPrimLong: |
| 176 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 177 | break; |
| 178 | |
| 179 | case Primitive::kPrimInt: |
| 180 | case Primitive::kPrimNot: |
| 181 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 182 | |
| 183 | case Primitive::kPrimFloat: |
| 184 | case Primitive::kPrimDouble: |
| 185 | LOG(FATAL) << "Unimplemented type " << load->GetType(); |
| 186 | |
| 187 | case Primitive::kPrimBoolean: |
| 188 | case Primitive::kPrimByte: |
| 189 | case Primitive::kPrimChar: |
| 190 | case Primitive::kPrimShort: |
| 191 | case Primitive::kPrimVoid: |
| 192 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 193 | } |
| 194 | |
| 195 | LOG(FATAL) << "Unreachable"; |
| 196 | return Location(); |
| 197 | } |
| 198 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 199 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 200 | switch (type) { |
| 201 | case Primitive::kPrimBoolean: |
| 202 | case Primitive::kPrimByte: |
| 203 | case Primitive::kPrimChar: |
| 204 | case Primitive::kPrimShort: |
| 205 | case Primitive::kPrimInt: |
| 206 | case Primitive::kPrimNot: { |
| 207 | uint32_t index = gp_index_++; |
| 208 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 209 | return ArmCoreLocation(calling_convention.GetRegisterAt(index)); |
| 210 | } else { |
| 211 | return Location::StackSlot(calling_convention.GetStackOffsetOf(index, kArmWordSize)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 212 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 213 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 214 | |
| 215 | case Primitive::kPrimLong: { |
| 216 | uint32_t index = gp_index_; |
| 217 | gp_index_ += 2; |
| 218 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 219 | return Location::RegisterLocation(ArmManagedRegister::FromRegisterPair( |
| 220 | calling_convention.GetRegisterPairAt(index))); |
| 221 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
| 222 | return Location::QuickParameter(index); |
| 223 | } else { |
| 224 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index, kArmWordSize)); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | case Primitive::kPrimDouble: |
| 229 | case Primitive::kPrimFloat: |
| 230 | LOG(FATAL) << "Unimplemented parameter type " << type; |
| 231 | break; |
| 232 | |
| 233 | case Primitive::kPrimVoid: |
| 234 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 235 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 236 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 237 | return Location(); |
| 238 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 239 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 240 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 241 | if (source.Equals(destination)) { |
| 242 | return; |
| 243 | } |
| 244 | if (destination.IsRegister()) { |
| 245 | if (source.IsRegister()) { |
| 246 | __ Mov(destination.AsArm().AsCoreRegister(), source.AsArm().AsCoreRegister()); |
| 247 | } else { |
| 248 | __ ldr(destination.AsArm().AsCoreRegister(), Address(SP, source.GetStackIndex())); |
| 249 | } |
| 250 | } else { |
| 251 | DCHECK(destination.IsStackSlot()); |
| 252 | if (source.IsRegister()) { |
| 253 | __ str(source.AsArm().AsCoreRegister(), Address(SP, destination.GetStackIndex())); |
| 254 | } else { |
| 255 | __ ldr(R0, Address(SP, source.GetStackIndex())); |
| 256 | __ str(R0, Address(SP, destination.GetStackIndex())); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 262 | if (source.Equals(destination)) { |
| 263 | return; |
| 264 | } |
| 265 | if (destination.IsRegister()) { |
| 266 | if (source.IsRegister()) { |
| 267 | __ Mov(destination.AsArm().AsRegisterPairLow(), source.AsArm().AsRegisterPairLow()); |
| 268 | __ Mov(destination.AsArm().AsRegisterPairHigh(), source.AsArm().AsRegisterPairHigh()); |
| 269 | } else if (source.IsQuickParameter()) { |
| 270 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 271 | InvokeDexCallingConvention calling_convention; |
| 272 | __ Mov(destination.AsArm().AsRegisterPairLow(), |
| 273 | calling_convention.GetRegisterAt(argument_index)); |
| 274 | __ ldr(destination.AsArm().AsRegisterPairHigh(), |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 275 | Address(SP, calling_convention.GetStackOffsetOf(argument_index + 1, kArmWordSize) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 276 | } else { |
| 277 | DCHECK(source.IsDoubleStackSlot()); |
| 278 | if (destination.AsArm().AsRegisterPair() == R1_R2) { |
| 279 | __ ldr(R1, Address(SP, source.GetStackIndex())); |
| 280 | __ ldr(R2, Address(SP, source.GetHighStackIndex(kArmWordSize))); |
| 281 | } else { |
| 282 | __ LoadFromOffset(kLoadWordPair, destination.AsArm().AsRegisterPairLow(), |
| 283 | SP, source.GetStackIndex()); |
| 284 | } |
| 285 | } |
| 286 | } else if (destination.IsQuickParameter()) { |
| 287 | InvokeDexCallingConvention calling_convention; |
| 288 | uint32_t argument_index = destination.GetQuickParameterIndex(); |
| 289 | if (source.IsRegister()) { |
| 290 | __ Mov(calling_convention.GetRegisterAt(argument_index), source.AsArm().AsRegisterPairLow()); |
| 291 | __ str(source.AsArm().AsRegisterPairHigh(), |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 292 | Address(SP, calling_convention.GetStackOffsetOf(argument_index + 1, kArmWordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 293 | } else { |
| 294 | DCHECK(source.IsDoubleStackSlot()); |
| 295 | __ ldr(calling_convention.GetRegisterAt(argument_index), Address(SP, source.GetStackIndex())); |
| 296 | __ ldr(R0, Address(SP, source.GetHighStackIndex(kArmWordSize))); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 297 | __ str(R0, Address(SP, calling_convention.GetStackOffsetOf(argument_index + 1, kArmWordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 298 | } |
| 299 | } else { |
| 300 | DCHECK(destination.IsDoubleStackSlot()); |
| 301 | if (source.IsRegister()) { |
| 302 | if (source.AsArm().AsRegisterPair() == R1_R2) { |
| 303 | __ str(R1, Address(SP, destination.GetStackIndex())); |
| 304 | __ str(R2, Address(SP, destination.GetHighStackIndex(kArmWordSize))); |
| 305 | } else { |
| 306 | __ StoreToOffset(kStoreWordPair, source.AsArm().AsRegisterPairLow(), |
| 307 | SP, destination.GetStackIndex()); |
| 308 | } |
| 309 | } else if (source.IsQuickParameter()) { |
| 310 | InvokeDexCallingConvention calling_convention; |
| 311 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 312 | __ str(calling_convention.GetRegisterAt(argument_index), |
| 313 | Address(SP, destination.GetStackIndex())); |
| 314 | __ ldr(R0, |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 315 | Address(SP, calling_convention.GetStackOffsetOf(argument_index + 1, kArmWordSize) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 316 | __ str(R0, Address(SP, destination.GetHighStackIndex(kArmWordSize))); |
| 317 | } else { |
| 318 | DCHECK(source.IsDoubleStackSlot()); |
| 319 | __ ldr(R0, Address(SP, source.GetStackIndex())); |
| 320 | __ str(R0, Address(SP, destination.GetStackIndex())); |
| 321 | __ ldr(R0, Address(SP, source.GetHighStackIndex(kArmWordSize))); |
| 322 | __ str(R0, Address(SP, destination.GetHighStackIndex(kArmWordSize))); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 327 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
| 328 | if (instruction->AsIntConstant() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 329 | int32_t value = instruction->AsIntConstant()->GetValue(); |
| 330 | if (location.IsRegister()) { |
| 331 | __ LoadImmediate(location.AsArm().AsCoreRegister(), value); |
| 332 | } else { |
| 333 | __ LoadImmediate(R0, value); |
| 334 | __ str(R0, Address(SP, location.GetStackIndex())); |
| 335 | } |
| 336 | } else if (instruction->AsLongConstant() != nullptr) { |
| 337 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 338 | if (location.IsRegister()) { |
| 339 | __ LoadImmediate(location.AsArm().AsRegisterPairLow(), Low32Bits(value)); |
| 340 | __ LoadImmediate(location.AsArm().AsRegisterPairHigh(), High32Bits(value)); |
| 341 | } else { |
| 342 | __ LoadImmediate(R0, Low32Bits(value)); |
| 343 | __ str(R0, Address(SP, location.GetStackIndex())); |
| 344 | __ LoadImmediate(R0, High32Bits(value)); |
| 345 | __ str(R0, Address(SP, location.GetHighStackIndex(kArmWordSize))); |
| 346 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 347 | } else if (instruction->AsLoadLocal() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 348 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
| 349 | switch (instruction->GetType()) { |
| 350 | case Primitive::kPrimBoolean: |
| 351 | case Primitive::kPrimByte: |
| 352 | case Primitive::kPrimChar: |
| 353 | case Primitive::kPrimShort: |
| 354 | case Primitive::kPrimInt: |
| 355 | case Primitive::kPrimNot: |
| 356 | Move32(location, Location::StackSlot(stack_slot)); |
| 357 | break; |
| 358 | |
| 359 | case Primitive::kPrimLong: |
| 360 | Move64(location, Location::DoubleStackSlot(stack_slot)); |
| 361 | break; |
| 362 | |
| 363 | default: |
| 364 | LOG(FATAL) << "Unimplemented type " << instruction->GetType(); |
| 365 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 366 | } else { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 367 | // This can currently only happen when the instruction that requests the move |
| 368 | // is the next to be compiled. |
| 369 | DCHECK_EQ(instruction->GetNext(), move_for); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 370 | switch (instruction->GetType()) { |
| 371 | case Primitive::kPrimBoolean: |
| 372 | case Primitive::kPrimByte: |
| 373 | case Primitive::kPrimChar: |
| 374 | case Primitive::kPrimShort: |
| 375 | case Primitive::kPrimNot: |
| 376 | case Primitive::kPrimInt: |
| 377 | Move32(location, instruction->GetLocations()->Out()); |
| 378 | break; |
| 379 | |
| 380 | case Primitive::kPrimLong: |
| 381 | Move64(location, instruction->GetLocations()->Out()); |
| 382 | break; |
| 383 | |
| 384 | default: |
| 385 | LOG(FATAL) << "Unimplemented type " << instruction->GetType(); |
| 386 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
| 390 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 391 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 394 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 395 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 396 | if (GetGraph()->GetExitBlock() == successor) { |
| 397 | codegen_->GenerateFrameExit(); |
| 398 | } else if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| 399 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 403 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 404 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 407 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 408 | if (kIsDebugBuild) { |
| 409 | __ Comment("Unreachable"); |
| 410 | __ bkpt(0); |
| 411 | } |
| 412 | } |
| 413 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 414 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 415 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 416 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 417 | if_instr->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 420 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 421 | // TODO: Generate the input as a condition, instead of materializing in a register. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 422 | __ cmp(if_instr->GetLocations()->InAt(0).AsArm().AsCoreRegister(), ShifterOperand(0)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 423 | __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()), EQ); |
| 424 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfTrueSuccessor())) { |
| 425 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | void LocationsBuilderARM::VisitEqual(HEqual* equal) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 430 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(equal); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 431 | locations->SetInAt(0, Location::RequiresRegister()); |
| 432 | locations->SetInAt(1, Location::RequiresRegister()); |
| 433 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 434 | equal->SetLocations(locations); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 437 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* equal) { |
| 438 | LocationSummary* locations = equal->GetLocations(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 439 | __ teq(locations->InAt(0).AsArm().AsCoreRegister(), |
| 440 | ShifterOperand(locations->InAt(1).AsArm().AsCoreRegister())); |
| 441 | __ mov(locations->Out().AsArm().AsCoreRegister(), ShifterOperand(1), EQ); |
| 442 | __ mov(locations->Out().AsArm().AsCoreRegister(), ShifterOperand(0), NE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 446 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 449 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 450 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 453 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 454 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 457 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 458 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 462 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 463 | switch (store->InputAt(1)->GetType()) { |
| 464 | case Primitive::kPrimBoolean: |
| 465 | case Primitive::kPrimByte: |
| 466 | case Primitive::kPrimChar: |
| 467 | case Primitive::kPrimShort: |
| 468 | case Primitive::kPrimInt: |
| 469 | case Primitive::kPrimNot: |
| 470 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 471 | break; |
| 472 | |
| 473 | case Primitive::kPrimLong: |
| 474 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 475 | break; |
| 476 | |
| 477 | default: |
| 478 | LOG(FATAL) << "Unimplemented local type " << store->InputAt(1)->GetType(); |
| 479 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 480 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 483 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 487 | constant->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 490 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 491 | // Will be generated at use site. |
| 492 | } |
| 493 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 494 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
| 495 | constant->SetLocations(nullptr); |
| 496 | } |
| 497 | |
| 498 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) { |
| 499 | // Will be generated at use site. |
| 500 | } |
| 501 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 502 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 503 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 506 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
| 507 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 510 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 511 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 512 | switch (ret->InputAt(0)->GetType()) { |
| 513 | case Primitive::kPrimBoolean: |
| 514 | case Primitive::kPrimByte: |
| 515 | case Primitive::kPrimChar: |
| 516 | case Primitive::kPrimShort: |
| 517 | case Primitive::kPrimInt: |
| 518 | case Primitive::kPrimNot: |
| 519 | locations->SetInAt(0, ArmCoreLocation(R0)); |
| 520 | break; |
| 521 | |
| 522 | case Primitive::kPrimLong: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 523 | locations->SetInAt( |
| 524 | 0, Location::RegisterLocation(ArmManagedRegister::FromRegisterPair(R0_R1))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 525 | break; |
| 526 | |
| 527 | default: |
| 528 | LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType(); |
| 529 | } |
| 530 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 531 | ret->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 534 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 535 | if (kIsDebugBuild) { |
| 536 | switch (ret->InputAt(0)->GetType()) { |
| 537 | case Primitive::kPrimBoolean: |
| 538 | case Primitive::kPrimByte: |
| 539 | case Primitive::kPrimChar: |
| 540 | case Primitive::kPrimShort: |
| 541 | case Primitive::kPrimInt: |
| 542 | case Primitive::kPrimNot: |
| 543 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsArm().AsCoreRegister(), R0); |
| 544 | break; |
| 545 | |
| 546 | case Primitive::kPrimLong: |
| 547 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsArm().AsRegisterPair(), R0_R1); |
| 548 | break; |
| 549 | |
| 550 | default: |
| 551 | LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType(); |
| 552 | } |
| 553 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 554 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 557 | void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 558 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(invoke); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 559 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 560 | |
| 561 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 562 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 563 | HInstruction* input = invoke->InputAt(i); |
| 564 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 565 | } |
| 566 | |
| 567 | switch (invoke->GetType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 568 | case Primitive::kPrimBoolean: |
| 569 | case Primitive::kPrimByte: |
| 570 | case Primitive::kPrimChar: |
| 571 | case Primitive::kPrimShort: |
| 572 | case Primitive::kPrimInt: |
| 573 | case Primitive::kPrimNot: |
| 574 | locations->SetOut(ArmCoreLocation(R0)); |
| 575 | break; |
| 576 | |
| 577 | case Primitive::kPrimLong: |
| 578 | locations->SetOut(Location::RegisterLocation(ArmManagedRegister::FromRegisterPair(R0_R1))); |
| 579 | break; |
| 580 | |
| 581 | case Primitive::kPrimVoid: |
| 582 | break; |
| 583 | |
| 584 | case Primitive::kPrimDouble: |
| 585 | case Primitive::kPrimFloat: |
| 586 | LOG(FATAL) << "Unimplemented return type " << invoke->GetType(); |
| 587 | break; |
| 588 | } |
| 589 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 590 | invoke->SetLocations(locations); |
| 591 | } |
| 592 | |
| 593 | void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 594 | __ ldr(reg, Address(SP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 598 | Register temp = invoke->GetLocations()->GetTemp(0).AsArm().AsCoreRegister(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 599 | size_t index_in_cache = mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 600 | invoke->GetIndexInDexCache() * kArmWordSize; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 601 | |
| 602 | // TODO: Implement all kinds of calls: |
| 603 | // 1) boot -> boot |
| 604 | // 2) app -> boot |
| 605 | // 3) app -> app |
| 606 | // |
| 607 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 608 | |
| 609 | // temp = method; |
| 610 | LoadCurrentMethod(temp); |
| 611 | // temp = temp->dex_cache_resolved_methods_; |
| 612 | __ ldr(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 613 | // temp = temp[index_in_cache] |
| 614 | __ ldr(temp, Address(temp, index_in_cache)); |
| 615 | // LR = temp[offset_of_quick_compiled_code] |
| 616 | __ ldr(LR, Address(temp, |
| 617 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 618 | // LR() |
| 619 | __ blx(LR); |
| 620 | |
| 621 | codegen_->RecordPcInfo(invoke->GetDexPc()); |
| 622 | } |
| 623 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 624 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
| 625 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(add); |
| 626 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 627 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 628 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 629 | locations->SetInAt(0, Location::RequiresRegister()); |
| 630 | locations->SetInAt(1, Location::RequiresRegister()); |
| 631 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 632 | break; |
| 633 | } |
| 634 | |
| 635 | case Primitive::kPrimBoolean: |
| 636 | case Primitive::kPrimByte: |
| 637 | case Primitive::kPrimChar: |
| 638 | case Primitive::kPrimShort: |
| 639 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 640 | break; |
| 641 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 642 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 643 | LOG(FATAL) << "Unimplemented add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 644 | } |
| 645 | add->SetLocations(locations); |
| 646 | } |
| 647 | |
| 648 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 649 | LocationSummary* locations = add->GetLocations(); |
| 650 | switch (add->GetResultType()) { |
| 651 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 652 | __ add(locations->Out().AsArm().AsCoreRegister(), |
| 653 | locations->InAt(0).AsArm().AsCoreRegister(), |
| 654 | ShifterOperand(locations->InAt(1).AsArm().AsCoreRegister())); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 655 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 656 | |
| 657 | case Primitive::kPrimLong: |
| 658 | __ adds(locations->Out().AsArm().AsRegisterPairLow(), |
| 659 | locations->InAt(0).AsArm().AsRegisterPairLow(), |
| 660 | ShifterOperand(locations->InAt(1).AsArm().AsRegisterPairLow())); |
| 661 | __ adc(locations->Out().AsArm().AsRegisterPairHigh(), |
| 662 | locations->InAt(0).AsArm().AsRegisterPairHigh(), |
| 663 | ShifterOperand(locations->InAt(1).AsArm().AsRegisterPairHigh())); |
| 664 | break; |
| 665 | |
| 666 | case Primitive::kPrimBoolean: |
| 667 | case Primitive::kPrimByte: |
| 668 | case Primitive::kPrimChar: |
| 669 | case Primitive::kPrimShort: |
| 670 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 671 | break; |
| 672 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 673 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 674 | LOG(FATAL) << "Unimplemented add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 678 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
| 679 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(sub); |
| 680 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 681 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 682 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 683 | locations->SetInAt(0, Location::RequiresRegister()); |
| 684 | locations->SetInAt(1, Location::RequiresRegister()); |
| 685 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 686 | break; |
| 687 | } |
| 688 | |
| 689 | case Primitive::kPrimBoolean: |
| 690 | case Primitive::kPrimByte: |
| 691 | case Primitive::kPrimChar: |
| 692 | case Primitive::kPrimShort: |
| 693 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 694 | break; |
| 695 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 696 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 697 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 698 | } |
| 699 | sub->SetLocations(locations); |
| 700 | } |
| 701 | |
| 702 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 703 | LocationSummary* locations = sub->GetLocations(); |
| 704 | switch (sub->GetResultType()) { |
| 705 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 706 | __ sub(locations->Out().AsArm().AsCoreRegister(), |
| 707 | locations->InAt(0).AsArm().AsCoreRegister(), |
| 708 | ShifterOperand(locations->InAt(1).AsArm().AsCoreRegister())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 709 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 710 | |
| 711 | case Primitive::kPrimLong: |
| 712 | __ subs(locations->Out().AsArm().AsRegisterPairLow(), |
| 713 | locations->InAt(0).AsArm().AsRegisterPairLow(), |
| 714 | ShifterOperand(locations->InAt(1).AsArm().AsRegisterPairLow())); |
| 715 | __ sbc(locations->Out().AsArm().AsRegisterPairHigh(), |
| 716 | locations->InAt(0).AsArm().AsRegisterPairHigh(), |
| 717 | ShifterOperand(locations->InAt(1).AsArm().AsRegisterPairHigh())); |
| 718 | break; |
| 719 | |
| 720 | case Primitive::kPrimBoolean: |
| 721 | case Primitive::kPrimByte: |
| 722 | case Primitive::kPrimChar: |
| 723 | case Primitive::kPrimShort: |
| 724 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 725 | break; |
| 726 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 727 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 728 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 732 | static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1 }; |
| 733 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 734 | arraysize(kRuntimeParameterCoreRegisters); |
| 735 | |
| 736 | class InvokeRuntimeCallingConvention : public CallingConvention<Register> { |
| 737 | public: |
| 738 | InvokeRuntimeCallingConvention() |
| 739 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 740 | kRuntimeParameterCoreRegistersLength) {} |
| 741 | |
| 742 | private: |
| 743 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 744 | }; |
| 745 | |
| 746 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
| 747 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 748 | InvokeRuntimeCallingConvention calling_convention; |
| 749 | locations->AddTemp(ArmCoreLocation(calling_convention.GetRegisterAt(0))); |
| 750 | locations->AddTemp(ArmCoreLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 751 | locations->SetOut(ArmCoreLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 752 | instruction->SetLocations(locations); |
| 753 | } |
| 754 | |
| 755 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 756 | InvokeRuntimeCallingConvention calling_convention; |
| 757 | LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
| 758 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
| 759 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 760 | int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value(); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 761 | __ ldr(LR, Address(TR, offset)); |
| 762 | __ blx(LR); |
| 763 | |
| 764 | codegen_->RecordPcInfo(instruction->GetDexPc()); |
| 765 | } |
| 766 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 767 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
| 768 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 769 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 770 | if (location.IsStackSlot()) { |
| 771 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 772 | } else if (location.IsDoubleStackSlot()) { |
| 773 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 774 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 775 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 776 | instruction->SetLocations(locations); |
| 777 | } |
| 778 | |
| 779 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 780 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 783 | void LocationsBuilderARM::VisitNot(HNot* instruction) { |
| 784 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 786 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 787 | instruction->SetLocations(locations); |
| 788 | } |
| 789 | |
| 790 | void InstructionCodeGeneratorARM::VisitNot(HNot* instruction) { |
| 791 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 792 | __ eor(locations->Out().AsArm().AsCoreRegister(), |
| 793 | locations->InAt(0).AsArm().AsCoreRegister(), ShifterOperand(1)); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 794 | } |
| 795 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 796 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
| 797 | LOG(FATAL) << "Unimplemented"; |
| 798 | } |
| 799 | |
| 800 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) { |
| 801 | LOG(FATAL) << "Unimplemented"; |
| 802 | } |
| 803 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 804 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) { |
| 805 | LOG(FATAL) << "Unimplemented"; |
| 806 | } |
| 807 | |
| 808 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
| 809 | LOG(FATAL) << "Unimplemented"; |
| 810 | } |
| 811 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 812 | } // namespace arm |
| 813 | } // namespace art |