blob: aa0972f861a2a1a25f5c169fac4b079d7054f4fa [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2012 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/* This file contains codegen for the X86 ISA */
18
19#include "codegen_x86.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080020
21#include "base/logging.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022#include "dex/quick/mir_to_lir-inl.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080023#include "driver/compiler_driver.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070024#include "gc/accounting/card_table.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010025#include "mirror/art_method.h"
26#include "mirror/object_array-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070027#include "x86_lir.h"
28
29namespace art {
30
Brian Carlstrom7940e442013-07-12 13:46:57 -070031/*
32 * The sparse table in the literal pool is an array of <key,displacement>
33 * pairs.
34 */
Andreas Gampe48971b32014-08-06 10:09:01 -070035void X86Mir2Lir::GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -070036 GenSmallSparseSwitch(mir, table_offset, rl_src);
37}
38
39/*
40 * We override InsertCaseLabel, because the first parameter represents
41 * a basic block id, instead of a dex offset.
42 */
43LIR* X86Mir2Lir::InsertCaseLabel(DexOffset bbid, int keyVal) {
44 LIR* boundary_lir = &block_label_list_[bbid];
45 LIR* res = boundary_lir;
Brian Carlstrom7940e442013-07-12 13:46:57 -070046 if (cu_->verbose) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -070047 // Only pay the expense if we're pretty-printing.
48 LIR* new_label = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocLIR));
49 BasicBlock* bb = mir_graph_->GetBasicBlock(bbid);
50 DCHECK(bb != nullptr);
51 new_label->dalvik_offset = bb->start_offset;;
52 new_label->opcode = kPseudoCaseLabel;
53 new_label->operands[0] = keyVal;
54 new_label->flags.fixup = kFixupLabel;
55 DCHECK(!new_label->flags.use_def_invalid);
56 new_label->u.m.def_mask = &kEncodeAll;
57 InsertLIRAfter(boundary_lir, new_label);
58 res = new_label;
Brian Carlstrom7940e442013-07-12 13:46:57 -070059 }
Chao-ying Fuda96aed2014-10-27 14:42:00 -070060 return res;
61}
62
63void X86Mir2Lir::MarkPackedCaseLabels(Mir2Lir::SwitchTable* tab_rec) {
64 const uint16_t* table = tab_rec->table;
65 const int32_t *targets = reinterpret_cast<const int32_t*>(&table[4]);
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 int entries = table[1];
Chao-ying Fuda96aed2014-10-27 14:42:00 -070067 int low_key = s4FromSwitchData(&table[2]);
Brian Carlstrom7940e442013-07-12 13:46:57 -070068 for (int i = 0; i < entries; i++) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -070069 // The value at targets[i] is a basic block id, instead of a dex offset.
70 tab_rec->targets[i] = InsertCaseLabel(targets[i], i + low_key);
Brian Carlstrom7940e442013-07-12 13:46:57 -070071 }
72}
73
74/*
Chao-ying Fuda96aed2014-10-27 14:42:00 -070075 * We convert and create a new packed switch table that stores
76 * basic block ids to targets[] by examining successor blocks.
77 * Note that the original packed switch table stores dex offsets to targets[].
78 */
79const uint16_t* X86Mir2Lir::ConvertPackedSwitchTable(MIR* mir, const uint16_t* table) {
80 /*
81 * The original packed switch data format:
82 * ushort ident = 0x0100 magic value
83 * ushort size number of entries in the table
84 * int first_key first (and lowest) switch case value
85 * int targets[size] branch targets, relative to switch opcode
86 *
87 * Total size is (4+size*2) 16-bit code units.
88 *
89 * Note that the new packed switch data format is the same as the original
90 * format, except that targets[] are basic block ids.
91 *
92 */
93 BasicBlock* bb = mir_graph_->GetBasicBlock(mir->bb);
94 DCHECK(bb != nullptr);
95 // Get the number of entries.
96 int entries = table[1];
97 const int32_t* as_int32 = reinterpret_cast<const int32_t*>(&table[2]);
98 int32_t starting_key = as_int32[0];
99 // Create a new table.
100 int size = sizeof(uint16_t) * (4 + entries * 2);
101 uint16_t* new_table = reinterpret_cast<uint16_t*>(arena_->Alloc(size, kArenaAllocMisc));
102 // Copy ident, size, and first_key to the new table.
103 memcpy(new_table, table, sizeof(uint16_t) * 4);
104 // Get the new targets.
105 int32_t* new_targets = reinterpret_cast<int32_t*>(&new_table[4]);
106 // Find out targets for each entry.
107 int i = 0;
108 for (SuccessorBlockInfo* successor_block_info : bb->successor_blocks) {
109 DCHECK_EQ(starting_key + i, successor_block_info->key);
110 // Save target basic block id.
111 new_targets[i++] = successor_block_info->block;
112 }
113 DCHECK_EQ(i, entries);
114 return new_table;
115}
116
117/*
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 * Code pattern will look something like:
119 *
120 * mov r_val, ..
121 * call 0
122 * pop r_start_of_method
123 * sub r_start_of_method, ..
124 * mov r_key_reg, r_val
125 * sub r_key_reg, low_key
126 * cmp r_key_reg, size-1 ; bound check
127 * ja done
128 * mov r_disp, [r_start_of_method + r_key_reg * 4 + table_offset]
129 * add r_start_of_method, r_disp
130 * jmp r_start_of_method
131 * done:
132 */
Andreas Gampe48971b32014-08-06 10:09:01 -0700133void X86Mir2Lir::GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -0700134 const uint16_t* old_table = mir_graph_->GetTable(mir, table_offset);
135 const uint16_t* table = ConvertPackedSwitchTable(mir, old_table);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700136 // Add the table to the list - we'll process it later
buzbee0d829482013-10-11 15:24:55 -0700137 SwitchTable* tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000138 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700139 tab_rec->table = table;
140 tab_rec->vaddr = current_dalvik_offset_;
141 int size = table[1];
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700142 tab_rec->targets = static_cast<LIR**>(arena_->Alloc(size * sizeof(LIR*),
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000143 kArenaAllocLIR));
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100144 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700145
146 // Get the switch value
147 rl_src = LoadValue(rl_src, kCoreReg);
Mark Mendell67c39c42014-01-31 17:28:00 -0800148
Brian Carlstrom7940e442013-07-12 13:46:57 -0700149 int low_key = s4FromSwitchData(&table[2]);
buzbee2700f7e2014-03-07 09:46:20 -0800150 RegStorage keyReg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700151 // Remove the bias, if necessary
152 if (low_key == 0) {
buzbee2700f7e2014-03-07 09:46:20 -0800153 keyReg = rl_src.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700154 } else {
155 keyReg = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -0800156 OpRegRegImm(kOpSub, keyReg, rl_src.reg, low_key);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157 }
Mark Mendell27dee8b2014-12-01 19:06:12 -0500158
Brian Carlstrom7940e442013-07-12 13:46:57 -0700159 // Bounds check - if < 0 or >= size continue following switch
Serguei Katkov407a9d22014-07-05 03:09:32 +0700160 OpRegImm(kOpCmp, keyReg, size - 1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161 LIR* branch_over = OpCondBranch(kCondHi, NULL);
162
Mark Mendell27dee8b2014-12-01 19:06:12 -0500163 RegStorage addr_for_jump;
164 if (cu_->target64) {
165 RegStorage table_base = AllocTempWide();
166 // Load the address of the table into table_base.
167 LIR* lea = RawLIR(current_dalvik_offset_, kX86Lea64RM, table_base.GetReg(), kRIPReg,
168 256, 0, WrapPointer(tab_rec));
169 lea->flags.fixup = kFixupSwitchTable;
170 AppendLIR(lea);
171
172 // Load the offset from the table out of the table.
173 addr_for_jump = AllocTempWide();
174 NewLIR5(kX86MovsxdRA, addr_for_jump.GetReg(), table_base.GetReg(), keyReg.GetReg(), 2, 0);
175
176 // Add the offset from the table to the table base.
177 OpRegReg(kOpAdd, addr_for_jump, table_base);
178 } else {
179 // Materialize a pointer to the switch table.
180 RegStorage start_of_method_reg;
181 if (base_of_code_ != nullptr) {
182 // We can use the saved value.
183 RegLocation rl_method = mir_graph_->GetRegLocation(base_of_code_->s_reg_low);
184 rl_method = LoadValue(rl_method, kCoreReg);
185 start_of_method_reg = rl_method.reg;
186 store_method_addr_used_ = true;
187 } else {
188 start_of_method_reg = AllocTempRef();
189 NewLIR1(kX86StartOfMethod, start_of_method_reg.GetReg());
190 }
191 // Load the displacement from the switch table.
192 addr_for_jump = AllocTemp();
193 NewLIR5(kX86PcRelLoadRA, addr_for_jump.GetReg(), start_of_method_reg.GetReg(), keyReg.GetReg(),
194 2, WrapPointer(tab_rec));
195 // Add displacement to start of method.
196 OpRegReg(kOpAdd, addr_for_jump, start_of_method_reg);
197 }
198
Brian Carlstrom7940e442013-07-12 13:46:57 -0700199 // ..and go!
Mark Mendell27dee8b2014-12-01 19:06:12 -0500200 tab_rec->anchor = NewLIR1(kX86JmpR, addr_for_jump.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700201
202 /* branch_over target here */
203 LIR* target = NewLIR0(kPseudoTargetLabel);
204 branch_over->target = target;
205}
206
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700207void X86Mir2Lir::GenMoveException(RegLocation rl_dest) {
buzbee33ae5582014-06-12 14:56:32 -0700208 int ex_offset = cu_->target64 ?
Andreas Gampe2f244e92014-05-08 03:35:25 -0700209 Thread::ExceptionOffset<8>().Int32Value() :
210 Thread::ExceptionOffset<4>().Int32Value();
buzbeea0cd2d72014-06-01 09:33:49 -0700211 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Serguei Katkov407a9d22014-07-05 03:09:32 +0700212 NewLIR2(cu_->target64 ? kX86Mov64RT : kX86Mov32RT, rl_result.reg.GetReg(), ex_offset);
213 NewLIR2(cu_->target64 ? kX86Mov64TI : kX86Mov32TI, ex_offset, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700214 StoreValue(rl_dest, rl_result);
215}
216
Vladimir Markobf535be2014-11-19 18:52:35 +0000217void X86Mir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) {
Serguei Katkov407a9d22014-07-05 03:09:32 +0700218 DCHECK_EQ(tgt_addr_reg.Is64Bit(), cu_->target64);
Serguei Katkov407a9d22014-07-05 03:09:32 +0700219 RegStorage reg_card_base = AllocTempRef();
220 RegStorage reg_card_no = AllocTempRef();
buzbee33ae5582014-06-12 14:56:32 -0700221 int ct_offset = cu_->target64 ?
Andreas Gampe2f244e92014-05-08 03:35:25 -0700222 Thread::CardTableOffset<8>().Int32Value() :
223 Thread::CardTableOffset<4>().Int32Value();
Serguei Katkov407a9d22014-07-05 03:09:32 +0700224 NewLIR2(cu_->target64 ? kX86Mov64RT : kX86Mov32RT, reg_card_base.GetReg(), ct_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700225 OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift);
buzbee2700f7e2014-03-07 09:46:20 -0800226 StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700227 FreeTemp(reg_card_base);
228 FreeTemp(reg_card_no);
229}
230
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700231void X86Mir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232 /*
233 * On entry, rX86_ARG0, rX86_ARG1, rX86_ARG2 are live. Let the register
234 * allocation mechanism know so it doesn't try to use any of them when
235 * expanding the frame or flushing. This leaves the utility
236 * code with no spare temps.
237 */
Ian Rogersb28c1c02014-11-08 11:21:21 -0800238 const RegStorage arg0 = TargetReg32(kArg0);
239 const RegStorage arg1 = TargetReg32(kArg1);
240 const RegStorage arg2 = TargetReg32(kArg2);
241 LockTemp(arg0);
242 LockTemp(arg1);
243 LockTemp(arg2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244
Brian Carlstrom7940e442013-07-12 13:46:57 -0700245 /*
246 * We can safely skip the stack overflow check if we're
247 * a leaf *and* our frame size < fudge factor.
248 */
Ian Rogersb28c1c02014-11-08 11:21:21 -0800249 const InstructionSet isa = cu_->target64 ? kX86_64 : kX86;
Dave Allison648d7112014-07-25 16:15:27 -0700250 bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, isa);
Ian Rogersb28c1c02014-11-08 11:21:21 -0800251 const RegStorage rs_rSP = cu_->target64 ? rs_rX86_SP_64 : rs_rX86_SP_32;
Dave Allison69dfe512014-07-11 17:11:58 +0000252
253 // If we doing an implicit stack overflow check, perform the load immediately
254 // before the stack pointer is decremented and anything is saved.
255 if (!skip_overflow_check &&
256 cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks()) {
257 // Implicit stack overflow check.
258 // test eax,[esp + -overflow]
259 int overflow = GetStackOverflowReservedBytes(isa);
Ian Rogersb28c1c02014-11-08 11:21:21 -0800260 NewLIR3(kX86Test32RM, rs_rAX.GetReg(), rs_rSP.GetReg(), -overflow);
Dave Allison69dfe512014-07-11 17:11:58 +0000261 MarkPossibleStackOverflowException();
262 }
263
264 /* Build frame, return address already on stack */
Ian Rogersb28c1c02014-11-08 11:21:21 -0800265 stack_decrement_ = OpRegImm(kOpSub, rs_rSP, frame_size_ -
Dave Allison69dfe512014-07-11 17:11:58 +0000266 GetInstructionSetPointerSize(cu_->instruction_set));
267
Brian Carlstrom7940e442013-07-12 13:46:57 -0700268 NewLIR0(kPseudoMethodEntry);
269 /* Spill core callee saves */
270 SpillCoreRegs();
Serguei Katkovc3801912014-07-08 17:21:53 +0700271 SpillFPRegs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700272 if (!skip_overflow_check) {
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700273 class StackOverflowSlowPath : public LIRSlowPath {
274 public:
275 StackOverflowSlowPath(Mir2Lir* m2l, LIR* branch, size_t sp_displace)
276 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, nullptr), sp_displace_(sp_displace) {
277 }
278 void Compile() OVERRIDE {
279 m2l_->ResetRegPool();
280 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700281 GenerateTargetLabel(kPseudoThrowTarget);
Ian Rogersb28c1c02014-11-08 11:21:21 -0800282 const RegStorage local_rs_rSP = cu_->target64 ? rs_rX86_SP_64 : rs_rX86_SP_32;
283 m2l_->OpRegImm(kOpAdd, local_rs_rSP, sp_displace_);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700284 m2l_->ClobberCallerSave();
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700285 // Assumes codegen and target are in thumb2 mode.
Andreas Gampe98430592014-07-27 19:44:50 -0700286 m2l_->CallHelper(RegStorage::InvalidReg(), kQuickThrowStackOverflow,
287 false /* MarkSafepointPC */, false /* UseLink */);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700288 }
289
290 private:
291 const size_t sp_displace_;
292 };
Dave Allison69dfe512014-07-11 17:11:58 +0000293 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks()) {
294 // TODO: for large frames we should do something like:
295 // spill ebp
296 // lea ebp, [esp + frame_size]
297 // cmp ebp, fs:[stack_end_]
298 // jcc stack_overflow_exception
299 // mov esp, ebp
300 // in case a signal comes in that's not using an alternate signal stack and the large frame
301 // may have moved us outside of the reserved area at the end of the stack.
302 // cmp rs_rX86_SP, fs:[stack_end_]; jcc throw_slowpath
303 if (cu_->target64) {
Ian Rogersb28c1c02014-11-08 11:21:21 -0800304 OpRegThreadMem(kOpCmp, rs_rX86_SP_64, Thread::StackEndOffset<8>());
Dave Allison69dfe512014-07-11 17:11:58 +0000305 } else {
Ian Rogersb28c1c02014-11-08 11:21:21 -0800306 OpRegThreadMem(kOpCmp, rs_rX86_SP_32, Thread::StackEndOffset<4>());
Dave Allison69dfe512014-07-11 17:11:58 +0000307 }
308 LIR* branch = OpCondBranch(kCondUlt, nullptr);
309 AddSlowPath(
Chao-ying Fue0ccdc02014-06-06 17:32:37 -0700310 new(arena_)StackOverflowSlowPath(this, branch,
311 frame_size_ -
312 GetInstructionSetPointerSize(cu_->instruction_set)));
Dave Allison69dfe512014-07-11 17:11:58 +0000313 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 }
315
316 FlushIns(ArgLocs, rl_method);
317
Mark Mendell67c39c42014-01-31 17:28:00 -0800318 if (base_of_code_ != nullptr) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700319 RegStorage method_start = TargetPtrReg(kArg0);
Mark Mendell67c39c42014-01-31 17:28:00 -0800320 // We have been asked to save the address of the method start for later use.
Chao-ying Fua77ee512014-07-01 17:43:41 -0700321 setup_method_address_[0] = NewLIR1(kX86StartOfMethod, method_start.GetReg());
Mark Mendell67c39c42014-01-31 17:28:00 -0800322 int displacement = SRegOffset(base_of_code_->s_reg_low);
buzbee695d13a2014-04-19 13:32:20 -0700323 // Native pointer - must be natural word size.
Ian Rogersb28c1c02014-11-08 11:21:21 -0800324 setup_method_address_[1] = StoreBaseDisp(rs_rSP, displacement, method_start,
Elena Sayapinadd644502014-07-01 18:39:52 +0700325 cu_->target64 ? k64 : k32, kNotVolatile);
Mark Mendell67c39c42014-01-31 17:28:00 -0800326 }
327
Ian Rogersb28c1c02014-11-08 11:21:21 -0800328 FreeTemp(arg0);
329 FreeTemp(arg1);
330 FreeTemp(arg2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700331}
332
333void X86Mir2Lir::GenExitSequence() {
334 /*
335 * In the exit path, rX86_RET0/rX86_RET1 are live - make sure they aren't
336 * allocated by the register utilities as temps.
337 */
buzbee091cc402014-03-31 10:14:40 -0700338 LockTemp(rs_rX86_RET0);
339 LockTemp(rs_rX86_RET1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700340
341 NewLIR0(kPseudoMethodExit);
342 UnSpillCoreRegs();
Serguei Katkovc3801912014-07-08 17:21:53 +0700343 UnSpillFPRegs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344 /* Remove frame except for return address */
Ian Rogersb28c1c02014-11-08 11:21:21 -0800345 const RegStorage rs_rSP = cu_->target64 ? rs_rX86_SP_64 : rs_rX86_SP_32;
346 stack_increment_ = OpRegImm(kOpAdd, rs_rSP,
347 frame_size_ - GetInstructionSetPointerSize(cu_->instruction_set));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700348 NewLIR0(kX86Ret);
349}
350
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800351void X86Mir2Lir::GenSpecialExitSequence() {
352 NewLIR0(kX86Ret);
353}
354
Dave Allison69dfe512014-07-11 17:11:58 +0000355void X86Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) {
356 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
357 return;
358 }
359 // Implicit null pointer check.
360 // test eax,[arg1+0]
361 NewLIR3(kX86Test32RM, rs_rAX.GetReg(), reg.GetReg(), 0);
362 MarkPossibleNullPointerException(opt_flags);
363}
364
Vladimir Markof4da6752014-08-01 19:04:18 +0100365/*
366 * Bit of a hack here - in the absence of a real scheduling pass,
367 * emit the next instruction in static & direct invoke sequences.
368 */
369static int X86NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
370 int state, const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700371 uint32_t,
Vladimir Markof4da6752014-08-01 19:04:18 +0100372 uintptr_t direct_code, uintptr_t direct_method,
373 InvokeType type) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700374 UNUSED(info, direct_code);
Vladimir Markof4da6752014-08-01 19:04:18 +0100375 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
376 if (direct_method != 0) {
377 switch (state) {
378 case 0: // Get the current Method* [sets kArg0]
379 if (direct_method != static_cast<uintptr_t>(-1)) {
380 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
381 } else {
382 cg->LoadMethodAddress(target_method, type, kArg0);
383 }
384 break;
385 default:
386 return -1;
387 }
388 } else {
389 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
390 switch (state) {
391 case 0: // Get the current Method* [sets kArg0]
392 // TUNING: we can save a reg copy if Method* has been promoted.
393 cg->LoadCurrMethodDirect(arg0_ref);
394 break;
395 case 1: // Get method->dex_cache_resolved_methods_
396 cg->LoadRefDisp(arg0_ref,
397 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
398 arg0_ref,
399 kNotVolatile);
400 break;
401 case 2: // Grab target method*
402 CHECK_EQ(cu->dex_file, target_method.dex_file);
403 cg->LoadRefDisp(arg0_ref,
404 mirror::ObjectArray<mirror::Object>::OffsetOfElement(
405 target_method.dex_method_index).Int32Value(),
406 arg0_ref,
407 kNotVolatile);
408 break;
409 default:
410 return -1;
411 }
412 }
413 return state + 1;
414}
415
416NextCallInsn X86Mir2Lir::GetNextSDCallInsn() {
417 return X86NextSDCallInsn;
418}
419
Brian Carlstrom7940e442013-07-12 13:46:57 -0700420} // namespace art