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