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