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 | |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame] | 21 | #include "base/logging.h" |
| 22 | #include "dex/mir_graph.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | #include "dex/quick/mir_to_lir-inl.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 26 | #include "mips_lir.h" |
Andreas Gampe | d500b53 | 2015-01-16 22:09:55 -0800 | [diff] [blame] | 27 | #include "mirror/art_method.h" |
| 28 | #include "mirror/object_array-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 32 | bool MipsMir2Lir::GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 33 | // TODO |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 34 | UNUSED(bb, mir, special); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 35 | return false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 36 | } |
| 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 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 41 | * 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 Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 43 | * 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 | * |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 51 | * ori r_end, rZERO, #table_size ; size in bytes |
| 52 | * jal BaseLabel ; stores "return address" (BaseLabel) in rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 53 | * nop ; opportunistically fill |
| 54 | * BaseLabel: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 55 | * addiu r_base, rRA, <table> - <BaseLabel> ; table relative to BaseLabel |
| 56 | addu r_end, r_end, r_base ; end of table |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 57 | * lw r_val, [rSP, v_reg_off] ; Test Value |
| 58 | * loop: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 59 | * beq r_base, r_end, done |
| 60 | * lw r_key, 0(r_base) |
| 61 | * addu r_base, 8 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 62 | * bne r_val, r_key, loop |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 63 | * lw r_disp, -4(r_base) |
| 64 | * addu rRA, r_disp |
Andreas Gampe | 8d36591 | 2015-01-13 11:32:32 -0800 | [diff] [blame] | 65 | * jalr rZERO, rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 66 | * done: |
| 67 | * |
| 68 | */ |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 69 | void MipsMir2Lir::GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 70 | const uint16_t* table = mir_graph_->GetTable(mir, table_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | // Add the table to the list - we'll process it later |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 72 | SwitchTable* tab_rec = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 73 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
Chao-ying Fu | 72f53af | 2014-11-11 16:48:40 -0800 | [diff] [blame] | 74 | tab_rec->switch_mir = mir; |
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]; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 78 | switch_tables_.push_back(tab_rec); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 79 | |
| 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 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 86 | RegStorage r_end = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 87 | if (size_hi) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 88 | NewLIR2(kMipsLui, r_end.GetReg(), size_hi); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 89 | } |
| 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) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 95 | NewLIR3(kMipsOri, r_end.GetReg(), r_end.GetReg(), size_lo); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 96 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 97 | NewLIR3(kMipsOri, r_end.GetReg(), rZERO, size_lo); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 98 | } |
| 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; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 105 | 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 Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 108 | |
| 109 | // Grab switch test value |
| 110 | rl_src = LoadValue(rl_src, kCoreReg); |
| 111 | |
| 112 | // Test loop |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 113 | RegStorage r_key = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 114 | LIR* loop_label = NewLIR0(kPseudoTargetLabel); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 115 | LIR* exit_branch = OpCmpBranch(kCondEq, r_base, r_end, NULL); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 116 | Load32Disp(r_base, 0, r_key); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 117 | OpRegImm(kOpAdd, r_base, 8); |
| 118 | OpCmpBranch(kCondNe, rl_src.reg, r_key, loop_label); |
| 119 | RegStorage r_disp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 120 | Load32Disp(r_base, -4, r_disp); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 121 | OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp); |
| 122 | OpReg(kOpBx, rs_rRA); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 123 | |
| 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 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 133 | * jal BaseLabel ; stores "return address" (BaseLabel) in rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 134 | * nop ; opportunistically fill |
| 135 | * [subiu r_val, bias] ; Remove bias if low_val != 0 |
| 136 | * bound check -> done |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 137 | * lw r_disp, [rRA, r_val] |
| 138 | * addu rRA, r_disp |
Andreas Gampe | 8d36591 | 2015-01-13 11:32:32 -0800 | [diff] [blame] | 139 | * jalr rZERO, rRA |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 140 | * done: |
| 141 | */ |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 142 | void MipsMir2Lir::GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 143 | const uint16_t* table = mir_graph_->GetTable(mir, table_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 144 | // Add the table to the list - we'll process it later |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 145 | SwitchTable* tab_rec = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 146 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
Chao-ying Fu | 72f53af | 2014-11-11 16:48:40 -0800 | [diff] [blame] | 147 | tab_rec->switch_mir = mir; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 148 | tab_rec->table = table; |
| 149 | tab_rec->vaddr = current_dalvik_offset_; |
| 150 | int size = table[1]; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 151 | switch_tables_.push_back(tab_rec); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 152 | |
| 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; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 159 | RegStorage r_key; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 160 | if (low_key == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 161 | r_key = rl_src.reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 162 | } 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) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 178 | OpRegRegReg(kOpSub, r_key, rl_src.reg, r_key); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 179 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 180 | OpRegRegImm(kOpSub, r_key, rl_src.reg, low_key); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 181 | } |
| 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 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 194 | RegStorage r_base = AllocTemp(); |
| 195 | NewLIR4(kMipsDelta, r_base.GetReg(), 0, WrapPointer(base_label), WrapPointer(tab_rec)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 196 | |
| 197 | // Load the displacement from the switch table |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 198 | RegStorage r_disp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 199 | LoadBaseIndexed(r_base, r_key, r_disp, 2, k32); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 200 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 201 | // Add to rAP and go |
| 202 | OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp); |
| 203 | OpReg(kOpBx, rs_rRA); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 204 | |
| 205 | /* branch_over target here */ |
| 206 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 207 | branch_over->target = target; |
| 208 | } |
| 209 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 210 | void MipsMir2Lir::GenMoveException(RegLocation rl_dest) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 211 | int ex_offset = Thread::ExceptionOffset<4>().Int32Value(); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 212 | RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true); |
| 213 | RegStorage reset_reg = AllocTempRef(); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 214 | LoadRefDisp(rs_rMIPS_SELF, ex_offset, rl_result.reg, kNotVolatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 215 | LoadConstant(reset_reg, 0); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 216 | StoreRefDisp(rs_rMIPS_SELF, ex_offset, reset_reg, kNotVolatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 217 | FreeTemp(reset_reg); |
| 218 | StoreValue(rl_dest, rl_result); |
| 219 | } |
| 220 | |
Vladimir Marko | bf535be | 2014-11-19 18:52:35 +0000 | [diff] [blame] | 221 | void MipsMir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 222 | RegStorage reg_card_base = AllocTemp(); |
| 223 | RegStorage reg_card_no = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 224 | // NOTE: native pointer. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 225 | LoadWordDisp(rs_rMIPS_SELF, Thread::CardTableOffset<4>().Int32Value(), reg_card_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 226 | OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 227 | StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 228 | FreeTemp(reg_card_base); |
| 229 | FreeTemp(reg_card_no); |
| 230 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 231 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 232 | void MipsMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 233 | 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 | */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 240 | LockTemp(rs_rMIPS_ARG0); |
| 241 | LockTemp(rs_rMIPS_ARG1); |
| 242 | LockTemp(rs_rMIPS_ARG2); |
| 243 | LockTemp(rs_rMIPS_ARG3); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * We can safely skip the stack overflow check if we're |
| 247 | * a leaf *and* our frame size < fudge factor. |
| 248 | */ |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 249 | bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, kMips); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 250 | NewLIR0(kPseudoMethodEntry); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 251 | RegStorage check_reg = AllocTemp(); |
| 252 | RegStorage new_sp = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 253 | if (!skip_overflow_check) { |
| 254 | /* Load stack limit */ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 255 | Load32Disp(rs_rMIPS_SELF, Thread::StackEndOffset<4>().Int32Value(), check_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 256 | } |
| 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 Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 261 | const int frame_sub = frame_size_ - spill_count * 4; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 262 | if (!skip_overflow_check) { |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 263 | 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 Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 271 | GenerateTargetLabel(kPseudoThrowTarget); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 272 | // LR is offset 0 since we push in reverse order. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 273 | m2l_->Load32Disp(rs_rMIPS_SP, 0, rs_rRA); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 274 | m2l_->OpRegImm(kOpAdd, rs_rMIPS_SP, sp_displace_); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 275 | m2l_->ClobberCallerSave(); |
Andreas Gampe | 9843059 | 2014-07-27 19:44:50 -0700 | [diff] [blame] | 276 | RegStorage r_tgt = m2l_->CallHelperSetup(kQuickThrowStackOverflow); // Doesn't clobber LR. |
| 277 | m2l_->CallHelper(r_tgt, kQuickThrowStackOverflow, false /* MarkSafepointPC */, |
| 278 | false /* UseLink */); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | private: |
| 282 | const size_t sp_displace_; |
| 283 | }; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 284 | OpRegRegImm(kOpSub, new_sp, rs_rMIPS_SP, frame_sub); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 285 | 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. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 288 | OpRegCopy(rs_rMIPS_SP, new_sp); // Establish stack |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 289 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 290 | OpRegImm(kOpSub, rs_rMIPS_SP, frame_sub); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | FlushIns(ArgLocs, rl_method); |
| 294 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 295 | FreeTemp(rs_rMIPS_ARG0); |
| 296 | FreeTemp(rs_rMIPS_ARG1); |
| 297 | FreeTemp(rs_rMIPS_ARG2); |
| 298 | FreeTemp(rs_rMIPS_ARG3); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 301 | void MipsMir2Lir::GenExitSequence() { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 302 | /* |
| 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 | */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 306 | LockTemp(rs_rMIPS_RET0); |
| 307 | LockTemp(rs_rMIPS_RET1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 308 | |
| 309 | NewLIR0(kPseudoMethodExit); |
| 310 | UnSpillCoreRegs(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 311 | OpReg(kOpBx, rs_rRA); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 314 | void MipsMir2Lir::GenSpecialExitSequence() { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 315 | OpReg(kOpBx, rs_rRA); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Vladimir Marko | 6ce3eba | 2015-02-16 13:05:59 +0000 | [diff] [blame] | 318 | void 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 | |
| 332 | void 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 Gampe | d500b53 | 2015-01-16 22:09:55 -0800 | [diff] [blame] | 338 | /* |
| 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 | */ |
| 342 | static 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 | |
| 410 | NextCallInsn MipsMir2Lir::GetNextSDCallInsn() { |
| 411 | return NextSDCallInsn; |
| 412 | } |
| 413 | |
| 414 | LIR* MipsMir2Lir::GenCallInsn(const MirMethodLoweringInfo& method_info ATTRIBUTE_UNUSED) { |
| 415 | return OpReg(kOpBlx, TargetPtrReg(kInvokeTgt)); |
| 416 | } |
| 417 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 418 | } // namespace art |