Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 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 Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 20 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include "dex/quick/mir_to_lir-inl.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 24 | #include "mips_lir.h" |
Andreas Gampe | d500b53 | 2015-01-16 22:09:55 -0800 | [diff] [blame^] | 25 | #include "mirror/art_method.h" |
| 26 | #include "mirror/object_array-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 30 | bool MipsMir2Lir::GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 31 | // TODO |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 32 | UNUSED(bb, mir, special); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 33 | return false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* |
| 37 | * The lack of pc-relative loads on Mips presents somewhat of a challenge |
| 38 | * for our PIC switch table strategy. To materialize the current location |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 39 | * we'll do a dummy JAL and reference our tables using rRA as the |
| 40 | * base register. Note that rRA will be used both as the base to |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 41 | * locate the switch table data and as the reference base for the switch |
| 42 | * target offsets stored in the table. We'll use a special pseudo-instruction |
| 43 | * to represent the jal and trigger the construction of the |
| 44 | * switch table offsets (which will happen after final assembly and all |
| 45 | * labels are fixed). |
| 46 | * |
| 47 | * The test loop will look something like: |
| 48 | * |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 49 | * ori r_end, rZERO, #table_size ; size in bytes |
| 50 | * jal BaseLabel ; stores "return address" (BaseLabel) in rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 51 | * nop ; opportunistically fill |
| 52 | * BaseLabel: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 53 | * addiu r_base, rRA, <table> - <BaseLabel> ; table relative to BaseLabel |
| 54 | addu r_end, r_end, r_base ; end of table |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 55 | * lw r_val, [rSP, v_reg_off] ; Test Value |
| 56 | * loop: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 57 | * beq r_base, r_end, done |
| 58 | * lw r_key, 0(r_base) |
| 59 | * addu r_base, 8 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 60 | * bne r_val, r_key, loop |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 61 | * lw r_disp, -4(r_base) |
| 62 | * addu rRA, r_disp |
Andreas Gampe | 8d36591 | 2015-01-13 11:32:32 -0800 | [diff] [blame] | 63 | * jalr rZERO, rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 64 | * done: |
| 65 | * |
| 66 | */ |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 67 | void MipsMir2Lir::GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 68 | const uint16_t* table = mir_graph_->GetTable(mir, table_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 69 | if (cu_->verbose) { |
| 70 | DumpSparseSwitchTable(table); |
| 71 | } |
| 72 | // Add the table to the list - we'll process it later |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 73 | SwitchTable* tab_rec = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 74 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 75 | tab_rec->table = table; |
| 76 | tab_rec->vaddr = current_dalvik_offset_; |
| 77 | int elements = table[1]; |
| 78 | tab_rec->targets = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 79 | static_cast<LIR**>(arena_->Alloc(elements * sizeof(LIR*), kArenaAllocLIR)); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 80 | switch_tables_.push_back(tab_rec); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 81 | |
| 82 | // The table is composed of 8-byte key/disp pairs |
| 83 | int byte_size = elements * 8; |
| 84 | |
| 85 | int size_hi = byte_size >> 16; |
| 86 | int size_lo = byte_size & 0xffff; |
| 87 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 88 | RegStorage r_end = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 89 | if (size_hi) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 90 | NewLIR2(kMipsLui, r_end.GetReg(), size_hi); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 91 | } |
| 92 | // Must prevent code motion for the curr pc pair |
| 93 | GenBarrier(); // Scheduling barrier |
| 94 | NewLIR0(kMipsCurrPC); // Really a jal to .+8 |
| 95 | // Now, fill the branch delay slot |
| 96 | if (size_hi) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 97 | NewLIR3(kMipsOri, r_end.GetReg(), r_end.GetReg(), size_lo); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 98 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 99 | NewLIR3(kMipsOri, r_end.GetReg(), rZERO, size_lo); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 100 | } |
| 101 | GenBarrier(); // Scheduling barrier |
| 102 | |
| 103 | // Construct BaseLabel and set up table base register |
| 104 | LIR* base_label = NewLIR0(kPseudoTargetLabel); |
| 105 | // Remember base label so offsets can be computed later |
| 106 | tab_rec->anchor = base_label; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 107 | RegStorage r_base = AllocTemp(); |
| 108 | NewLIR4(kMipsDelta, r_base.GetReg(), 0, WrapPointer(base_label), WrapPointer(tab_rec)); |
| 109 | OpRegRegReg(kOpAdd, r_end, r_end, r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 110 | |
| 111 | // Grab switch test value |
| 112 | rl_src = LoadValue(rl_src, kCoreReg); |
| 113 | |
| 114 | // Test loop |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 115 | RegStorage r_key = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 116 | LIR* loop_label = NewLIR0(kPseudoTargetLabel); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 117 | LIR* exit_branch = OpCmpBranch(kCondEq, r_base, r_end, NULL); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 118 | Load32Disp(r_base, 0, r_key); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 119 | OpRegImm(kOpAdd, r_base, 8); |
| 120 | OpCmpBranch(kCondNe, rl_src.reg, r_key, loop_label); |
| 121 | RegStorage r_disp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 122 | Load32Disp(r_base, -4, r_disp); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 123 | OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp); |
| 124 | OpReg(kOpBx, rs_rRA); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 125 | |
| 126 | // Loop exit |
| 127 | LIR* exit_label = NewLIR0(kPseudoTargetLabel); |
| 128 | exit_branch->target = exit_label; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Code pattern will look something like: |
| 133 | * |
| 134 | * lw r_val |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 135 | * jal BaseLabel ; stores "return address" (BaseLabel) in rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 136 | * nop ; opportunistically fill |
| 137 | * [subiu r_val, bias] ; Remove bias if low_val != 0 |
| 138 | * bound check -> done |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 139 | * lw r_disp, [rRA, r_val] |
| 140 | * addu rRA, r_disp |
Andreas Gampe | 8d36591 | 2015-01-13 11:32:32 -0800 | [diff] [blame] | 141 | * jalr rZERO, rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 142 | * done: |
| 143 | */ |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 144 | void MipsMir2Lir::GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 145 | const uint16_t* table = mir_graph_->GetTable(mir, table_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 146 | if (cu_->verbose) { |
| 147 | DumpPackedSwitchTable(table); |
| 148 | } |
| 149 | // Add the table to the list - we'll process it later |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 150 | SwitchTable* tab_rec = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 151 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 152 | tab_rec->table = table; |
| 153 | tab_rec->vaddr = current_dalvik_offset_; |
| 154 | int size = table[1]; |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 155 | tab_rec->targets = static_cast<LIR**>(arena_->Alloc(size * sizeof(LIR*), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 156 | kArenaAllocLIR)); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 157 | switch_tables_.push_back(tab_rec); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 158 | |
| 159 | // Get the switch value |
| 160 | rl_src = LoadValue(rl_src, kCoreReg); |
| 161 | |
| 162 | // Prepare the bias. If too big, handle 1st stage here |
| 163 | int low_key = s4FromSwitchData(&table[2]); |
| 164 | bool large_bias = false; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 165 | RegStorage r_key; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 166 | if (low_key == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 167 | r_key = rl_src.reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 168 | } else if ((low_key & 0xffff) != low_key) { |
| 169 | r_key = AllocTemp(); |
| 170 | LoadConstant(r_key, low_key); |
| 171 | large_bias = true; |
| 172 | } else { |
| 173 | r_key = AllocTemp(); |
| 174 | } |
| 175 | |
| 176 | // Must prevent code motion for the curr pc pair |
| 177 | GenBarrier(); |
| 178 | NewLIR0(kMipsCurrPC); // Really a jal to .+8 |
| 179 | // Now, fill the branch delay slot with bias strip |
| 180 | if (low_key == 0) { |
| 181 | NewLIR0(kMipsNop); |
| 182 | } else { |
| 183 | if (large_bias) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 184 | OpRegRegReg(kOpSub, r_key, rl_src.reg, r_key); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 185 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 186 | OpRegRegImm(kOpSub, r_key, rl_src.reg, low_key); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | GenBarrier(); // Scheduling barrier |
| 190 | |
| 191 | // Construct BaseLabel and set up table base register |
| 192 | LIR* base_label = NewLIR0(kPseudoTargetLabel); |
| 193 | // Remember base label so offsets can be computed later |
| 194 | tab_rec->anchor = base_label; |
| 195 | |
| 196 | // Bounds check - if < 0 or >= size continue following switch |
| 197 | LIR* branch_over = OpCmpImmBranch(kCondHi, r_key, size-1, NULL); |
| 198 | |
| 199 | // Materialize the table base pointer |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 200 | RegStorage r_base = AllocTemp(); |
| 201 | NewLIR4(kMipsDelta, r_base.GetReg(), 0, WrapPointer(base_label), WrapPointer(tab_rec)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 202 | |
| 203 | // Load the displacement from the switch table |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 204 | RegStorage r_disp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 205 | LoadBaseIndexed(r_base, r_key, r_disp, 2, k32); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 206 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 207 | // Add to rAP and go |
| 208 | OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp); |
| 209 | OpReg(kOpBx, rs_rRA); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 210 | |
| 211 | /* branch_over target here */ |
| 212 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 213 | branch_over->target = target; |
| 214 | } |
| 215 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 216 | void MipsMir2Lir::GenMoveException(RegLocation rl_dest) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 217 | int ex_offset = Thread::ExceptionOffset<4>().Int32Value(); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 218 | RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true); |
| 219 | RegStorage reset_reg = AllocTempRef(); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 220 | LoadRefDisp(rs_rMIPS_SELF, ex_offset, rl_result.reg, kNotVolatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 221 | LoadConstant(reset_reg, 0); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 222 | StoreRefDisp(rs_rMIPS_SELF, ex_offset, reset_reg, kNotVolatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 223 | FreeTemp(reset_reg); |
| 224 | StoreValue(rl_dest, rl_result); |
| 225 | } |
| 226 | |
Vladimir Marko | bf535be | 2014-11-19 18:52:35 +0000 | [diff] [blame] | 227 | void MipsMir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 228 | RegStorage reg_card_base = AllocTemp(); |
| 229 | RegStorage reg_card_no = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 230 | // NOTE: native pointer. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 231 | LoadWordDisp(rs_rMIPS_SELF, Thread::CardTableOffset<4>().Int32Value(), reg_card_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 232 | OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 233 | StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 234 | FreeTemp(reg_card_base); |
| 235 | FreeTemp(reg_card_no); |
| 236 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 237 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 238 | void MipsMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 239 | int spill_count = num_core_spills_ + num_fp_spills_; |
| 240 | /* |
| 241 | * On entry, rMIPS_ARG0, rMIPS_ARG1, rMIPS_ARG2 & rMIPS_ARG3 are live. Let the register |
| 242 | * allocation mechanism know so it doesn't try to use any of them when |
| 243 | * expanding the frame or flushing. This leaves the utility |
| 244 | * code with a single temp: r12. This should be enough. |
| 245 | */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 246 | LockTemp(rs_rMIPS_ARG0); |
| 247 | LockTemp(rs_rMIPS_ARG1); |
| 248 | LockTemp(rs_rMIPS_ARG2); |
| 249 | LockTemp(rs_rMIPS_ARG3); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * We can safely skip the stack overflow check if we're |
| 253 | * a leaf *and* our frame size < fudge factor. |
| 254 | */ |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 255 | bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, kMips); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 256 | NewLIR0(kPseudoMethodEntry); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 257 | RegStorage check_reg = AllocTemp(); |
| 258 | RegStorage new_sp = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 259 | if (!skip_overflow_check) { |
| 260 | /* Load stack limit */ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 261 | Load32Disp(rs_rMIPS_SELF, Thread::StackEndOffset<4>().Int32Value(), check_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 262 | } |
| 263 | /* Spill core callee saves */ |
| 264 | SpillCoreRegs(); |
| 265 | /* NOTE: promotion of FP regs currently unsupported, thus no FP spill */ |
| 266 | DCHECK_EQ(num_fp_spills_, 0); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 267 | const int frame_sub = frame_size_ - spill_count * 4; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 268 | if (!skip_overflow_check) { |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 269 | class StackOverflowSlowPath : public LIRSlowPath { |
| 270 | public: |
| 271 | StackOverflowSlowPath(Mir2Lir* m2l, LIR* branch, size_t sp_displace) |
| 272 | : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, nullptr), sp_displace_(sp_displace) { |
| 273 | } |
| 274 | void Compile() OVERRIDE { |
| 275 | m2l_->ResetRegPool(); |
| 276 | m2l_->ResetDefTracking(); |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 277 | GenerateTargetLabel(kPseudoThrowTarget); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 278 | // LR is offset 0 since we push in reverse order. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 279 | m2l_->Load32Disp(rs_rMIPS_SP, 0, rs_rRA); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 280 | m2l_->OpRegImm(kOpAdd, rs_rMIPS_SP, sp_displace_); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 281 | m2l_->ClobberCallerSave(); |
Andreas Gampe | 9843059 | 2014-07-27 19:44:50 -0700 | [diff] [blame] | 282 | RegStorage r_tgt = m2l_->CallHelperSetup(kQuickThrowStackOverflow); // Doesn't clobber LR. |
| 283 | m2l_->CallHelper(r_tgt, kQuickThrowStackOverflow, false /* MarkSafepointPC */, |
| 284 | false /* UseLink */); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | private: |
| 288 | const size_t sp_displace_; |
| 289 | }; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 290 | OpRegRegImm(kOpSub, new_sp, rs_rMIPS_SP, frame_sub); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 291 | LIR* branch = OpCmpBranch(kCondUlt, new_sp, check_reg, nullptr); |
| 292 | AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, spill_count * 4)); |
| 293 | // TODO: avoid copy for small frame sizes. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 294 | OpRegCopy(rs_rMIPS_SP, new_sp); // Establish stack |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 295 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 296 | OpRegImm(kOpSub, rs_rMIPS_SP, frame_sub); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | FlushIns(ArgLocs, rl_method); |
| 300 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 301 | FreeTemp(rs_rMIPS_ARG0); |
| 302 | FreeTemp(rs_rMIPS_ARG1); |
| 303 | FreeTemp(rs_rMIPS_ARG2); |
| 304 | FreeTemp(rs_rMIPS_ARG3); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 307 | void MipsMir2Lir::GenExitSequence() { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 308 | /* |
| 309 | * In the exit path, rMIPS_RET0/rMIPS_RET1 are live - make sure they aren't |
| 310 | * allocated by the register utilities as temps. |
| 311 | */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 312 | LockTemp(rs_rMIPS_RET0); |
| 313 | LockTemp(rs_rMIPS_RET1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 314 | |
| 315 | NewLIR0(kPseudoMethodExit); |
| 316 | UnSpillCoreRegs(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 317 | OpReg(kOpBx, rs_rRA); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 320 | void MipsMir2Lir::GenSpecialExitSequence() { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 321 | OpReg(kOpBx, rs_rRA); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Andreas Gampe | d500b53 | 2015-01-16 22:09:55 -0800 | [diff] [blame^] | 324 | /* |
| 325 | * Bit of a hack here - in the absence of a real scheduling pass, |
| 326 | * emit the next instruction in static & direct invoke sequences. |
| 327 | */ |
| 328 | static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info ATTRIBUTE_UNUSED, |
| 329 | int state, const MethodReference& target_method, |
| 330 | uint32_t, |
| 331 | uintptr_t direct_code, uintptr_t direct_method, |
| 332 | InvokeType type) { |
| 333 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
| 334 | if (direct_code != 0 && direct_method != 0) { |
| 335 | switch (state) { |
| 336 | case 0: // Get the current Method* [sets kArg0] |
| 337 | if (direct_code != static_cast<uintptr_t>(-1)) { |
| 338 | cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code); |
| 339 | } else { |
| 340 | cg->LoadCodeAddress(target_method, type, kInvokeTgt); |
| 341 | } |
| 342 | if (direct_method != static_cast<uintptr_t>(-1)) { |
| 343 | cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method); |
| 344 | } else { |
| 345 | cg->LoadMethodAddress(target_method, type, kArg0); |
| 346 | } |
| 347 | break; |
| 348 | default: |
| 349 | return -1; |
| 350 | } |
| 351 | } else { |
| 352 | RegStorage arg0_ref = cg->TargetReg(kArg0, kRef); |
| 353 | switch (state) { |
| 354 | case 0: // Get the current Method* [sets kArg0] |
| 355 | // TUNING: we can save a reg copy if Method* has been promoted. |
| 356 | cg->LoadCurrMethodDirect(arg0_ref); |
| 357 | break; |
| 358 | case 1: // Get method->dex_cache_resolved_methods_ |
| 359 | cg->LoadRefDisp(arg0_ref, |
| 360 | mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), |
| 361 | arg0_ref, |
| 362 | kNotVolatile); |
| 363 | // Set up direct code if known. |
| 364 | if (direct_code != 0) { |
| 365 | if (direct_code != static_cast<uintptr_t>(-1)) { |
| 366 | cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code); |
| 367 | } else { |
| 368 | CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds()); |
| 369 | cg->LoadCodeAddress(target_method, type, kInvokeTgt); |
| 370 | } |
| 371 | } |
| 372 | break; |
| 373 | case 2: // Grab target method* |
| 374 | CHECK_EQ(cu->dex_file, target_method.dex_file); |
| 375 | cg->LoadRefDisp(arg0_ref, |
| 376 | mirror::ObjectArray<mirror::Object>:: |
| 377 | OffsetOfElement(target_method.dex_method_index).Int32Value(), |
| 378 | arg0_ref, |
| 379 | kNotVolatile); |
| 380 | break; |
| 381 | case 3: // Grab the code from the method* |
| 382 | if (direct_code == 0) { |
| 383 | int32_t offset = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 384 | InstructionSetPointerSize(cu->instruction_set)).Int32Value(); |
| 385 | // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt] |
| 386 | cg->LoadWordDisp(arg0_ref, offset, cg->TargetPtrReg(kInvokeTgt)); |
| 387 | } |
| 388 | break; |
| 389 | default: |
| 390 | return -1; |
| 391 | } |
| 392 | } |
| 393 | return state + 1; |
| 394 | } |
| 395 | |
| 396 | NextCallInsn MipsMir2Lir::GetNextSDCallInsn() { |
| 397 | return NextSDCallInsn; |
| 398 | } |
| 399 | |
| 400 | LIR* MipsMir2Lir::GenCallInsn(const MirMethodLoweringInfo& method_info ATTRIBUTE_UNUSED) { |
| 401 | return OpReg(kOpBlx, TargetPtrReg(kInvokeTgt)); |
| 402 | } |
| 403 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 404 | } // namespace art |