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