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