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" |
| 20 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 21 | #include "mirror/array.h" |
| 22 | #include "mirror/art_method.h" |
| 23 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 24 | #define __ reinterpret_cast<ArmAssembler*>(GetAssembler())-> |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | namespace arm { |
| 28 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 29 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 30 | static constexpr int kCurrentMethodStackOffset = 0; |
| 31 | |
| 32 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
| 33 | : HGraphVisitor(graph), |
| 34 | assembler_(codegen->GetAssembler()), |
| 35 | codegen_(codegen) {} |
| 36 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | void CodeGeneratorARM::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 38 | core_spill_mask_ |= (1 << LR); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 39 | __ PushList((1 << LR)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 40 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 41 | // Add the current ART method to the frame size, the return PC, and the filler. |
| 42 | SetFrameSize(RoundUp(( |
| 43 | GetGraph()->GetMaximumNumberOfOutVRegs() + GetGraph()->GetNumberOfVRegs() + 3) * kArmWordSize, |
| 44 | kStackAlignment)); |
| 45 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 46 | __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 47 | __ str(R0, Address(SP, 0)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 51 | __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 52 | __ PopList((1 << PC)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void CodeGeneratorARM::Bind(Label* label) { |
| 56 | __ Bind(label); |
| 57 | } |
| 58 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 59 | int32_t CodeGeneratorARM::GetStackSlot(HLocal* local) const { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 60 | uint16_t reg_number = local->GetRegNumber(); |
| 61 | uint16_t number_of_vregs = GetGraph()->GetNumberOfVRegs(); |
| 62 | uint16_t number_of_in_vregs = GetGraph()->GetNumberOfInVRegs(); |
| 63 | if (reg_number >= number_of_vregs - number_of_in_vregs) { |
| 64 | // Local is a parameter of the method. It is stored in the caller's frame. |
| 65 | return GetFrameSize() + kArmWordSize // ART method |
| 66 | + (reg_number - number_of_vregs + number_of_in_vregs) * kArmWordSize; |
| 67 | } else { |
| 68 | // Local is a temporary in this method. It is stored in this method's frame. |
| 69 | return GetFrameSize() - (kNumberOfPushedRegistersAtEntry * kArmWordSize) |
| 70 | - kArmWordSize // filler. |
| 71 | - (number_of_vregs * kArmWordSize) |
| 72 | + (reg_number * kArmWordSize); |
| 73 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 76 | void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
| 77 | if (instruction->AsIntConstant() != nullptr) { |
| 78 | __ LoadImmediate(location.reg<Register>(), instruction->AsIntConstant()->GetValue()); |
| 79 | } else if (instruction->AsLoadLocal() != nullptr) { |
| 80 | __ LoadFromOffset(kLoadWord, location.reg<Register>(), |
| 81 | SP, GetStackSlot(instruction->AsLoadLocal()->GetLocal())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 82 | } else { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 83 | // This can currently only happen when the instruction that requests the move |
| 84 | // is the next to be compiled. |
| 85 | DCHECK_EQ(instruction->GetNext(), move_for); |
| 86 | __ mov(location.reg<Register>(), |
| 87 | ShifterOperand(instruction->GetLocations()->Out().reg<Register>())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 92 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 95 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 96 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 97 | if (GetGraph()->GetExitBlock() == successor) { |
| 98 | codegen_->GenerateFrameExit(); |
| 99 | } else if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| 100 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 104 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 105 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 108 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 109 | if (kIsDebugBuild) { |
| 110 | __ Comment("Unreachable"); |
| 111 | __ bkpt(0); |
| 112 | } |
| 113 | } |
| 114 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 115 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 116 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 117 | locations->SetInAt(0, Location(R0)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 118 | if_instr->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 121 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 122 | // TODO: Generate the input as a condition, instead of materializing in a register. |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 123 | __ cmp(if_instr->GetLocations()->InAt(0).reg<Register>(), ShifterOperand(0)); |
| 124 | __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()), EQ); |
| 125 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfTrueSuccessor())) { |
| 126 | __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | void LocationsBuilderARM::VisitEqual(HEqual* equal) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 131 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(equal); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 132 | locations->SetInAt(0, Location(R0)); |
| 133 | locations->SetInAt(1, Location(R1)); |
| 134 | locations->SetOut(Location(R0)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 135 | equal->SetLocations(locations); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 138 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* equal) { |
| 139 | LocationSummary* locations = equal->GetLocations(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 140 | __ teq(locations->InAt(0).reg<Register>(), |
| 141 | ShifterOperand(locations->InAt(1).reg<Register>())); |
| 142 | __ mov(locations->Out().reg<Register>(), ShifterOperand(1), EQ); |
| 143 | __ mov(locations->Out().reg<Register>(), ShifterOperand(0), NE); |
| 144 | } |
| 145 | |
| 146 | void LocationsBuilderARM::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 147 | local->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 150 | void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) { |
| 151 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 152 | codegen_->SetFrameSize(codegen_->GetFrameSize() + kArmWordSize); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 155 | void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 156 | load->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 159 | void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 160 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 164 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 165 | locations->SetInAt(1, Location(R0)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 166 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 169 | void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) { |
| 170 | LocationSummary* locations = store->GetLocations(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 171 | __ StoreToOffset(kStoreWord, locations->InAt(1).reg<Register>(), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 172 | SP, codegen_->GetStackSlot(store->GetLocal())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 176 | constant->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 179 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 180 | // Will be generated at use site. |
| 181 | } |
| 182 | |
| 183 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 184 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 187 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) { |
| 188 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 191 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 192 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 193 | locations->SetInAt(0, Location(R0)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 194 | ret->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 197 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) { |
| 198 | DCHECK_EQ(ret->GetLocations()->InAt(0).reg<Register>(), R0); |
| 199 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 202 | static constexpr Register kParameterCoreRegisters[] = { R1, R2, R3 }; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 203 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 204 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 205 | class InvokeDexCallingConvention : public CallingConvention<Register> { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 206 | public: |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 207 | InvokeDexCallingConvention() |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 208 | : CallingConvention(kParameterCoreRegisters, kParameterCoreRegistersLength) {} |
| 209 | |
| 210 | private: |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 211 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | void LocationsBuilderARM::VisitPushArgument(HPushArgument* argument) { |
| 215 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(argument); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 216 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 217 | if (argument->GetArgumentIndex() < calling_convention.GetNumberOfRegisters()) { |
| 218 | Location location = Location(calling_convention.GetRegisterAt(argument->GetArgumentIndex())); |
| 219 | locations->SetInAt(0, location); |
| 220 | locations->SetOut(location); |
| 221 | } else { |
| 222 | locations->SetInAt(0, Location(R0)); |
| 223 | } |
| 224 | argument->SetLocations(locations); |
| 225 | } |
| 226 | |
| 227 | void InstructionCodeGeneratorARM::VisitPushArgument(HPushArgument* argument) { |
| 228 | uint8_t argument_index = argument->GetArgumentIndex(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 229 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 230 | size_t parameter_registers = calling_convention.GetNumberOfRegisters(); |
| 231 | LocationSummary* locations = argument->GetLocations(); |
| 232 | if (argument_index >= parameter_registers) { |
| 233 | uint8_t offset = calling_convention.GetStackOffsetOf(argument_index); |
| 234 | __ StoreToOffset(kStoreWord, locations->InAt(0).reg<Register>(), SP, offset); |
| 235 | } else { |
| 236 | DCHECK_EQ(locations->Out().reg<Register>(), locations->InAt(0).reg<Register>()); |
| 237 | } |
| 238 | } |
| 239 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 240 | void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 241 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(invoke); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 242 | locations->AddTemp(Location(R0)); |
| 243 | invoke->SetLocations(locations); |
| 244 | } |
| 245 | |
| 246 | void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 247 | __ ldr(reg, Address(SP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 251 | Register temp = invoke->GetLocations()->GetTemp(0).reg<Register>(); |
| 252 | size_t index_in_cache = mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 253 | invoke->GetIndexInDexCache() * kArmWordSize; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 254 | |
| 255 | // TODO: Implement all kinds of calls: |
| 256 | // 1) boot -> boot |
| 257 | // 2) app -> boot |
| 258 | // 3) app -> app |
| 259 | // |
| 260 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 261 | |
| 262 | // temp = method; |
| 263 | LoadCurrentMethod(temp); |
| 264 | // temp = temp->dex_cache_resolved_methods_; |
| 265 | __ ldr(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 266 | // temp = temp[index_in_cache] |
| 267 | __ ldr(temp, Address(temp, index_in_cache)); |
| 268 | // LR = temp[offset_of_quick_compiled_code] |
| 269 | __ ldr(LR, Address(temp, |
| 270 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 271 | // LR() |
| 272 | __ blx(LR); |
| 273 | |
| 274 | codegen_->RecordPcInfo(invoke->GetDexPc()); |
| 275 | } |
| 276 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 277 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
| 278 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(add); |
| 279 | switch (add->GetResultType()) { |
| 280 | case Primitive::kPrimInt: { |
| 281 | locations->SetInAt(0, Location(R0)); |
| 282 | locations->SetInAt(1, Location(R1)); |
| 283 | locations->SetOut(Location(R0)); |
| 284 | break; |
| 285 | } |
| 286 | default: |
| 287 | LOG(FATAL) << "Unimplemented"; |
| 288 | } |
| 289 | add->SetLocations(locations); |
| 290 | } |
| 291 | |
| 292 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 293 | LocationSummary* locations = add->GetLocations(); |
| 294 | switch (add->GetResultType()) { |
| 295 | case Primitive::kPrimInt: |
| 296 | __ add(locations->Out().reg<Register>(), |
| 297 | locations->InAt(0).reg<Register>(), |
| 298 | ShifterOperand(locations->InAt(1).reg<Register>())); |
| 299 | break; |
| 300 | default: |
| 301 | LOG(FATAL) << "Unimplemented"; |
| 302 | } |
| 303 | } |
| 304 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 305 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
| 306 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(sub); |
| 307 | switch (sub->GetResultType()) { |
| 308 | case Primitive::kPrimInt: { |
| 309 | locations->SetInAt(0, Location(R0)); |
| 310 | locations->SetInAt(1, Location(R1)); |
| 311 | locations->SetOut(Location(R0)); |
| 312 | break; |
| 313 | } |
| 314 | default: |
| 315 | LOG(FATAL) << "Unimplemented"; |
| 316 | } |
| 317 | sub->SetLocations(locations); |
| 318 | } |
| 319 | |
| 320 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 321 | LocationSummary* locations = sub->GetLocations(); |
| 322 | switch (sub->GetResultType()) { |
| 323 | case Primitive::kPrimInt: |
| 324 | __ sub(locations->Out().reg<Register>(), |
| 325 | locations->InAt(0).reg<Register>(), |
| 326 | ShifterOperand(locations->InAt(1).reg<Register>())); |
| 327 | break; |
| 328 | default: |
| 329 | LOG(FATAL) << "Unimplemented"; |
| 330 | } |
| 331 | } |
| 332 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 333 | static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1 }; |
| 334 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 335 | arraysize(kRuntimeParameterCoreRegisters); |
| 336 | |
| 337 | class InvokeRuntimeCallingConvention : public CallingConvention<Register> { |
| 338 | public: |
| 339 | InvokeRuntimeCallingConvention() |
| 340 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 341 | kRuntimeParameterCoreRegistersLength) {} |
| 342 | |
| 343 | private: |
| 344 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 345 | }; |
| 346 | |
| 347 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
| 348 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 349 | locations->SetOut(Location(R0)); |
| 350 | instruction->SetLocations(locations); |
| 351 | } |
| 352 | |
| 353 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
| 354 | InvokeRuntimeCallingConvention calling_convention; |
| 355 | LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
| 356 | __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex()); |
| 357 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 358 | int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value(); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 359 | __ ldr(LR, Address(TR, offset)); |
| 360 | __ blx(LR); |
| 361 | |
| 362 | codegen_->RecordPcInfo(instruction->GetDexPc()); |
| 363 | } |
| 364 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 365 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
| 366 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 367 | InvokeDexCallingConvention calling_convention; |
| 368 | uint32_t argument_index = instruction->GetIndex(); |
| 369 | if (argument_index < calling_convention.GetNumberOfRegisters()) { |
| 370 | locations->SetOut(Location(calling_convention.GetRegisterAt(argument_index))); |
| 371 | } else { |
| 372 | locations->SetOut(Location(R0)); |
| 373 | } |
| 374 | instruction->SetLocations(locations); |
| 375 | } |
| 376 | |
| 377 | void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) { |
| 378 | LocationSummary* locations = instruction->GetLocations(); |
| 379 | InvokeDexCallingConvention calling_convention; |
| 380 | uint8_t argument_index = instruction->GetIndex(); |
| 381 | if (argument_index >= calling_convention.GetNumberOfRegisters()) { |
| 382 | uint8_t offset = calling_convention.GetStackOffsetOf(argument_index); |
| 383 | __ ldr(locations->Out().reg<Register>(), Address(SP, offset + codegen_->GetFrameSize())); |
| 384 | } |
| 385 | } |
| 386 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 387 | } // namespace arm |
| 388 | } // namespace art |