blob: d9471f6fd1bd9d22346399d49f9283bced6aed66 [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 Mips ISA */
18
19#include "codegen_mips.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080020
Andreas Gampe0b9203e2015-01-22 20:39:27 -080021#include "base/logging.h"
22#include "dex/mir_graph.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "dex/quick/mir_to_lir-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070024#include "entrypoints/quick/quick_entrypoints.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070025#include "gc/accounting/card_table.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070026#include "mips_lir.h"
Andreas Gamped500b532015-01-16 22:09:55 -080027#include "mirror/art_method.h"
28#include "mirror/object_array-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029
30namespace art {
31
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070032bool MipsMir2Lir::GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special) {
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -080033 // TODO
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070034 UNUSED(bb, mir, special);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -080035 return false;
Brian Carlstrom7940e442013-07-12 13:46:57 -070036}
37
38/*
39 * The lack of pc-relative loads on Mips presents somewhat of a challenge
40 * for our PIC switch table strategy. To materialize the current location
buzbee2700f7e2014-03-07 09:46:20 -080041 * we'll do a dummy JAL and reference our tables using rRA as the
42 * base register. Note that rRA will be used both as the base to
Brian Carlstrom7940e442013-07-12 13:46:57 -070043 * locate the switch table data and as the reference base for the switch
44 * target offsets stored in the table. We'll use a special pseudo-instruction
45 * to represent the jal and trigger the construction of the
46 * switch table offsets (which will happen after final assembly and all
47 * labels are fixed).
48 *
49 * The test loop will look something like:
50 *
buzbee2700f7e2014-03-07 09:46:20 -080051 * ori r_end, rZERO, #table_size ; size in bytes
52 * jal BaseLabel ; stores "return address" (BaseLabel) in rRA
Brian Carlstrom7940e442013-07-12 13:46:57 -070053 * nop ; opportunistically fill
54 * BaseLabel:
buzbee2700f7e2014-03-07 09:46:20 -080055 * addiu r_base, rRA, <table> - <BaseLabel> ; table relative to BaseLabel
56 addu r_end, r_end, r_base ; end of table
Brian Carlstrom7940e442013-07-12 13:46:57 -070057 * lw r_val, [rSP, v_reg_off] ; Test Value
58 * loop:
buzbee2700f7e2014-03-07 09:46:20 -080059 * beq r_base, r_end, done
60 * lw r_key, 0(r_base)
61 * addu r_base, 8
Brian Carlstrom7940e442013-07-12 13:46:57 -070062 * bne r_val, r_key, loop
buzbee2700f7e2014-03-07 09:46:20 -080063 * lw r_disp, -4(r_base)
64 * addu rRA, r_disp
Andreas Gampe8d365912015-01-13 11:32:32 -080065 * jalr rZERO, rRA
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 * done:
67 *
68 */
Andreas Gampe48971b32014-08-06 10:09:01 -070069void MipsMir2Lir::GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070070 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -070071 // Add the table to the list - we'll process it later
buzbee0d829482013-10-11 15:24:55 -070072 SwitchTable* tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000073 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Chao-ying Fu72f53af2014-11-11 16:48:40 -080074 tab_rec->switch_mir = mir;
Brian Carlstrom7940e442013-07-12 13:46:57 -070075 tab_rec->table = table;
76 tab_rec->vaddr = current_dalvik_offset_;
77 int elements = table[1];
Vladimir Markoe39c54e2014-09-22 14:50:02 +010078 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -070079
80 // The table is composed of 8-byte key/disp pairs
81 int byte_size = elements * 8;
82
83 int size_hi = byte_size >> 16;
84 int size_lo = byte_size & 0xffff;
85
buzbee2700f7e2014-03-07 09:46:20 -080086 RegStorage r_end = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070087 if (size_hi) {
buzbee2700f7e2014-03-07 09:46:20 -080088 NewLIR2(kMipsLui, r_end.GetReg(), size_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -070089 }
90 // Must prevent code motion for the curr pc pair
91 GenBarrier(); // Scheduling barrier
92 NewLIR0(kMipsCurrPC); // Really a jal to .+8
93 // Now, fill the branch delay slot
94 if (size_hi) {
buzbee2700f7e2014-03-07 09:46:20 -080095 NewLIR3(kMipsOri, r_end.GetReg(), r_end.GetReg(), size_lo);
Brian Carlstrom7940e442013-07-12 13:46:57 -070096 } else {
buzbee2700f7e2014-03-07 09:46:20 -080097 NewLIR3(kMipsOri, r_end.GetReg(), rZERO, size_lo);
Brian Carlstrom7940e442013-07-12 13:46:57 -070098 }
99 GenBarrier(); // Scheduling barrier
100
101 // Construct BaseLabel and set up table base register
102 LIR* base_label = NewLIR0(kPseudoTargetLabel);
103 // Remember base label so offsets can be computed later
104 tab_rec->anchor = base_label;
buzbee2700f7e2014-03-07 09:46:20 -0800105 RegStorage r_base = AllocTemp();
106 NewLIR4(kMipsDelta, r_base.GetReg(), 0, WrapPointer(base_label), WrapPointer(tab_rec));
107 OpRegRegReg(kOpAdd, r_end, r_end, r_base);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700108
109 // Grab switch test value
110 rl_src = LoadValue(rl_src, kCoreReg);
111
112 // Test loop
buzbee2700f7e2014-03-07 09:46:20 -0800113 RegStorage r_key = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114 LIR* loop_label = NewLIR0(kPseudoTargetLabel);
buzbee2700f7e2014-03-07 09:46:20 -0800115 LIR* exit_branch = OpCmpBranch(kCondEq, r_base, r_end, NULL);
buzbee695d13a2014-04-19 13:32:20 -0700116 Load32Disp(r_base, 0, r_key);
buzbee2700f7e2014-03-07 09:46:20 -0800117 OpRegImm(kOpAdd, r_base, 8);
118 OpCmpBranch(kCondNe, rl_src.reg, r_key, loop_label);
119 RegStorage r_disp = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -0700120 Load32Disp(r_base, -4, r_disp);
buzbee2700f7e2014-03-07 09:46:20 -0800121 OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp);
122 OpReg(kOpBx, rs_rRA);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123
124 // Loop exit
125 LIR* exit_label = NewLIR0(kPseudoTargetLabel);
126 exit_branch->target = exit_label;
127}
128
129/*
130 * Code pattern will look something like:
131 *
132 * lw r_val
buzbee2700f7e2014-03-07 09:46:20 -0800133 * jal BaseLabel ; stores "return address" (BaseLabel) in rRA
Brian Carlstrom7940e442013-07-12 13:46:57 -0700134 * nop ; opportunistically fill
135 * [subiu r_val, bias] ; Remove bias if low_val != 0
136 * bound check -> done
buzbee2700f7e2014-03-07 09:46:20 -0800137 * lw r_disp, [rRA, r_val]
138 * addu rRA, r_disp
Andreas Gampe8d365912015-01-13 11:32:32 -0800139 * jalr rZERO, rRA
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140 * done:
141 */
Andreas Gampe48971b32014-08-06 10:09:01 -0700142void MipsMir2Lir::GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700143 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700144 // Add the table to the list - we'll process it later
buzbee0d829482013-10-11 15:24:55 -0700145 SwitchTable* tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000146 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Chao-ying Fu72f53af2014-11-11 16:48:40 -0800147 tab_rec->switch_mir = mir;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 tab_rec->table = table;
149 tab_rec->vaddr = current_dalvik_offset_;
150 int size = table[1];
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100151 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700152
153 // Get the switch value
154 rl_src = LoadValue(rl_src, kCoreReg);
155
156 // Prepare the bias. If too big, handle 1st stage here
157 int low_key = s4FromSwitchData(&table[2]);
158 bool large_bias = false;
buzbee2700f7e2014-03-07 09:46:20 -0800159 RegStorage r_key;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160 if (low_key == 0) {
buzbee2700f7e2014-03-07 09:46:20 -0800161 r_key = rl_src.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 } else if ((low_key & 0xffff) != low_key) {
163 r_key = AllocTemp();
164 LoadConstant(r_key, low_key);
165 large_bias = true;
166 } else {
167 r_key = AllocTemp();
168 }
169
170 // Must prevent code motion for the curr pc pair
171 GenBarrier();
172 NewLIR0(kMipsCurrPC); // Really a jal to .+8
173 // Now, fill the branch delay slot with bias strip
174 if (low_key == 0) {
175 NewLIR0(kMipsNop);
176 } else {
177 if (large_bias) {
buzbee2700f7e2014-03-07 09:46:20 -0800178 OpRegRegReg(kOpSub, r_key, rl_src.reg, r_key);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700179 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800180 OpRegRegImm(kOpSub, r_key, rl_src.reg, low_key);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700181 }
182 }
183 GenBarrier(); // Scheduling barrier
184
185 // Construct BaseLabel and set up table base register
186 LIR* base_label = NewLIR0(kPseudoTargetLabel);
187 // Remember base label so offsets can be computed later
188 tab_rec->anchor = base_label;
189
190 // Bounds check - if < 0 or >= size continue following switch
191 LIR* branch_over = OpCmpImmBranch(kCondHi, r_key, size-1, NULL);
192
193 // Materialize the table base pointer
buzbee2700f7e2014-03-07 09:46:20 -0800194 RegStorage r_base = AllocTemp();
195 NewLIR4(kMipsDelta, r_base.GetReg(), 0, WrapPointer(base_label), WrapPointer(tab_rec));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196
197 // Load the displacement from the switch table
buzbee2700f7e2014-03-07 09:46:20 -0800198 RegStorage r_disp = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -0700199 LoadBaseIndexed(r_base, r_key, r_disp, 2, k32);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700200
buzbee2700f7e2014-03-07 09:46:20 -0800201 // Add to rAP and go
202 OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp);
203 OpReg(kOpBx, rs_rRA);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700204
205 /* branch_over target here */
206 LIR* target = NewLIR0(kPseudoTargetLabel);
207 branch_over->target = target;
208}
209
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700210void MipsMir2Lir::GenMoveException(RegLocation rl_dest) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700211 int ex_offset = Thread::ExceptionOffset<4>().Int32Value();
buzbeea0cd2d72014-06-01 09:33:49 -0700212 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
213 RegStorage reset_reg = AllocTempRef();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000214 LoadRefDisp(rs_rMIPS_SELF, ex_offset, rl_result.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700215 LoadConstant(reset_reg, 0);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000216 StoreRefDisp(rs_rMIPS_SELF, ex_offset, reset_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217 FreeTemp(reset_reg);
218 StoreValue(rl_dest, rl_result);
219}
220
Vladimir Markobf535be2014-11-19 18:52:35 +0000221void MipsMir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800222 RegStorage reg_card_base = AllocTemp();
223 RegStorage reg_card_no = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -0700224 // NOTE: native pointer.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700225 LoadWordDisp(rs_rMIPS_SELF, Thread::CardTableOffset<4>().Int32Value(), reg_card_base);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700226 OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift);
buzbee2700f7e2014-03-07 09:46:20 -0800227 StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228 FreeTemp(reg_card_base);
229 FreeTemp(reg_card_no);
230}
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700231
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700232void MipsMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700233 int spill_count = num_core_spills_ + num_fp_spills_;
234 /*
235 * On entry, rMIPS_ARG0, rMIPS_ARG1, rMIPS_ARG2 & rMIPS_ARG3 are live. Let the register
236 * allocation mechanism know so it doesn't try to use any of them when
237 * expanding the frame or flushing. This leaves the utility
238 * code with a single temp: r12. This should be enough.
239 */
buzbee091cc402014-03-31 10:14:40 -0700240 LockTemp(rs_rMIPS_ARG0);
241 LockTemp(rs_rMIPS_ARG1);
242 LockTemp(rs_rMIPS_ARG2);
243 LockTemp(rs_rMIPS_ARG3);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244
245 /*
246 * We can safely skip the stack overflow check if we're
247 * a leaf *and* our frame size < fudge factor.
248 */
Dave Allison648d7112014-07-25 16:15:27 -0700249 bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, kMips);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700250 NewLIR0(kPseudoMethodEntry);
buzbee2700f7e2014-03-07 09:46:20 -0800251 RegStorage check_reg = AllocTemp();
252 RegStorage new_sp = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700253 if (!skip_overflow_check) {
254 /* Load stack limit */
buzbee695d13a2014-04-19 13:32:20 -0700255 Load32Disp(rs_rMIPS_SELF, Thread::StackEndOffset<4>().Int32Value(), check_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700256 }
257 /* Spill core callee saves */
258 SpillCoreRegs();
259 /* NOTE: promotion of FP regs currently unsupported, thus no FP spill */
260 DCHECK_EQ(num_fp_spills_, 0);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700261 const int frame_sub = frame_size_ - spill_count * 4;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700262 if (!skip_overflow_check) {
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700263 class StackOverflowSlowPath : public LIRSlowPath {
264 public:
265 StackOverflowSlowPath(Mir2Lir* m2l, LIR* branch, size_t sp_displace)
266 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, nullptr), sp_displace_(sp_displace) {
267 }
268 void Compile() OVERRIDE {
269 m2l_->ResetRegPool();
270 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700271 GenerateTargetLabel(kPseudoThrowTarget);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700272 // LR is offset 0 since we push in reverse order.
buzbee695d13a2014-04-19 13:32:20 -0700273 m2l_->Load32Disp(rs_rMIPS_SP, 0, rs_rRA);
buzbee2700f7e2014-03-07 09:46:20 -0800274 m2l_->OpRegImm(kOpAdd, rs_rMIPS_SP, sp_displace_);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700275 m2l_->ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700276 RegStorage r_tgt = m2l_->CallHelperSetup(kQuickThrowStackOverflow); // Doesn't clobber LR.
277 m2l_->CallHelper(r_tgt, kQuickThrowStackOverflow, false /* MarkSafepointPC */,
278 false /* UseLink */);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700279 }
280
281 private:
282 const size_t sp_displace_;
283 };
buzbee2700f7e2014-03-07 09:46:20 -0800284 OpRegRegImm(kOpSub, new_sp, rs_rMIPS_SP, frame_sub);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700285 LIR* branch = OpCmpBranch(kCondUlt, new_sp, check_reg, nullptr);
286 AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, spill_count * 4));
287 // TODO: avoid copy for small frame sizes.
buzbee2700f7e2014-03-07 09:46:20 -0800288 OpRegCopy(rs_rMIPS_SP, new_sp); // Establish stack
Brian Carlstrom7940e442013-07-12 13:46:57 -0700289 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800290 OpRegImm(kOpSub, rs_rMIPS_SP, frame_sub);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700291 }
292
293 FlushIns(ArgLocs, rl_method);
294
buzbee091cc402014-03-31 10:14:40 -0700295 FreeTemp(rs_rMIPS_ARG0);
296 FreeTemp(rs_rMIPS_ARG1);
297 FreeTemp(rs_rMIPS_ARG2);
298 FreeTemp(rs_rMIPS_ARG3);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700299}
300
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700301void MipsMir2Lir::GenExitSequence() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302 /*
303 * In the exit path, rMIPS_RET0/rMIPS_RET1 are live - make sure they aren't
304 * allocated by the register utilities as temps.
305 */
buzbee091cc402014-03-31 10:14:40 -0700306 LockTemp(rs_rMIPS_RET0);
307 LockTemp(rs_rMIPS_RET1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700308
309 NewLIR0(kPseudoMethodExit);
310 UnSpillCoreRegs();
buzbee2700f7e2014-03-07 09:46:20 -0800311 OpReg(kOpBx, rs_rRA);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700312}
313
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800314void MipsMir2Lir::GenSpecialExitSequence() {
buzbee2700f7e2014-03-07 09:46:20 -0800315 OpReg(kOpBx, rs_rRA);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800316}
317
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000318void MipsMir2Lir::GenSpecialEntryForSuspend() {
319 // Keep 16-byte stack alignment - push A0, i.e. ArtMethod*, 2 filler words and RA.
320 core_spill_mask_ = (1u << rs_rRA.GetRegNum());
321 num_core_spills_ = 1u;
322 fp_spill_mask_ = 0u;
323 num_fp_spills_ = 0u;
324 frame_size_ = 16u;
325 core_vmap_table_.clear();
326 fp_vmap_table_.clear();
327 OpRegImm(kOpSub, rs_rMIPS_SP, frame_size_);
328 Store32Disp(rs_rMIPS_SP, frame_size_ - 4, rs_rRA);
329 Store32Disp(rs_rMIPS_SP, 0, rs_rA0);
330}
331
332void MipsMir2Lir::GenSpecialExitForSuspend() {
333 // Pop the frame. Don't pop ArtMethod*, it's no longer needed.
334 Load32Disp(rs_rMIPS_SP, frame_size_ - 4, rs_rRA);
335 OpRegImm(kOpAdd, rs_rMIPS_SP, frame_size_);
336}
337
Andreas Gamped500b532015-01-16 22:09:55 -0800338/*
339 * Bit of a hack here - in the absence of a real scheduling pass,
340 * emit the next instruction in static & direct invoke sequences.
341 */
342static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info ATTRIBUTE_UNUSED,
343 int state, const MethodReference& target_method,
344 uint32_t,
345 uintptr_t direct_code, uintptr_t direct_method,
346 InvokeType type) {
347 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
348 if (direct_code != 0 && direct_method != 0) {
349 switch (state) {
350 case 0: // Get the current Method* [sets kArg0]
351 if (direct_code != static_cast<uintptr_t>(-1)) {
352 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
353 } else {
354 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
355 }
356 if (direct_method != static_cast<uintptr_t>(-1)) {
357 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
358 } else {
359 cg->LoadMethodAddress(target_method, type, kArg0);
360 }
361 break;
362 default:
363 return -1;
364 }
365 } else {
366 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
367 switch (state) {
368 case 0: // Get the current Method* [sets kArg0]
369 // TUNING: we can save a reg copy if Method* has been promoted.
370 cg->LoadCurrMethodDirect(arg0_ref);
371 break;
372 case 1: // Get method->dex_cache_resolved_methods_
373 cg->LoadRefDisp(arg0_ref,
374 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
375 arg0_ref,
376 kNotVolatile);
377 // Set up direct code if known.
378 if (direct_code != 0) {
379 if (direct_code != static_cast<uintptr_t>(-1)) {
380 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
381 } else {
382 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
383 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
384 }
385 }
386 break;
387 case 2: // Grab target method*
388 CHECK_EQ(cu->dex_file, target_method.dex_file);
389 cg->LoadRefDisp(arg0_ref,
390 mirror::ObjectArray<mirror::Object>::
391 OffsetOfElement(target_method.dex_method_index).Int32Value(),
392 arg0_ref,
393 kNotVolatile);
394 break;
395 case 3: // Grab the code from the method*
396 if (direct_code == 0) {
397 int32_t offset = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
398 InstructionSetPointerSize(cu->instruction_set)).Int32Value();
399 // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt]
400 cg->LoadWordDisp(arg0_ref, offset, cg->TargetPtrReg(kInvokeTgt));
401 }
402 break;
403 default:
404 return -1;
405 }
406 }
407 return state + 1;
408}
409
410NextCallInsn MipsMir2Lir::GetNextSDCallInsn() {
411 return NextSDCallInsn;
412}
413
414LIR* MipsMir2Lir::GenCallInsn(const MirMethodLoweringInfo& method_info ATTRIBUTE_UNUSED) {
415 return OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
416}
417
Brian Carlstrom7940e442013-07-12 13:46:57 -0700418} // namespace art