buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [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 "oat/runtime/oat_support_entrypoints.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 20 | #include "mips_lir.h" |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 21 | #include "codegen_mips.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 22 | #include "../codegen_util.h" |
| 23 | #include "../ralloc_util.h" |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 27 | void MipsCodegen::GenSpecialCase(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 28 | SpecialCaseHandler special_case) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 29 | { |
| 30 | // TODO |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * The lack of pc-relative loads on Mips presents somewhat of a challenge |
| 35 | * for our PIC switch table strategy. To materialize the current location |
| 36 | * we'll do a dummy JAL and reference our tables using r_RA as the |
| 37 | * base register. Note that r_RA will be used both as the base to |
| 38 | * locate the switch table data and as the reference base for the switch |
| 39 | * target offsets stored in the table. We'll use a special pseudo-instruction |
| 40 | * to represent the jal and trigger the construction of the |
| 41 | * switch table offsets (which will happen after final assembly and all |
| 42 | * labels are fixed). |
| 43 | * |
| 44 | * The test loop will look something like: |
| 45 | * |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 46 | * ori rEnd, r_ZERO, #table_size ; size in bytes |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 47 | * jal BaseLabel ; stores "return address" (BaseLabel) in r_RA |
| 48 | * nop ; opportunistically fill |
| 49 | * BaseLabel: |
| 50 | * addiu rBase, r_RA, <table> - <BaseLabel> ; table relative to BaseLabel |
| 51 | addu rEnd, rEnd, rBase ; end of table |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 52 | * lw r_val, [rSP, v_reg_off] ; Test Value |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 53 | * loop: |
| 54 | * beq rBase, rEnd, done |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 55 | * lw r_key, 0(rBase) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 56 | * addu rBase, 8 |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 57 | * bne r_val, r_key, loop |
| 58 | * lw r_disp, -4(rBase) |
| 59 | * addu r_RA, r_disp |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 60 | * jr r_RA |
| 61 | * done: |
| 62 | * |
| 63 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 64 | void MipsCodegen::GenSparseSwitch(CompilationUnit* cu, uint32_t table_offset, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 65 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 66 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
| 67 | if (cu->verbose) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 68 | DumpSparseSwitchTable(table); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 69 | } |
| 70 | // Add the table to the list - we'll process it later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 71 | SwitchTable *tab_rec = |
| 72 | static_cast<SwitchTable*>(NewMem(cu, sizeof(SwitchTable), true, kAllocData)); |
| 73 | tab_rec->table = table; |
| 74 | tab_rec->vaddr = cu->current_dalvik_offset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 75 | int elements = table[1]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 76 | tab_rec->targets = |
| 77 | static_cast<LIR**>(NewMem(cu, elements * sizeof(LIR*), true, kAllocLIR)); |
| 78 | InsertGrowableList(cu, &cu->switch_tables, reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 79 | |
| 80 | // The table is composed of 8-byte key/disp pairs |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 81 | int byte_size = elements * 8; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 82 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 83 | int size_hi = byte_size >> 16; |
| 84 | int size_lo = byte_size & 0xffff; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 85 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 86 | int rEnd = AllocTemp(cu); |
| 87 | if (size_hi) { |
| 88 | NewLIR2(cu, kMipsLui, rEnd, size_hi); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 89 | } |
| 90 | // Must prevent code motion for the curr pc pair |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 91 | GenBarrier(cu); // Scheduling barrier |
| 92 | NewLIR0(cu, kMipsCurrPC); // Really a jal to .+8 |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 93 | // Now, fill the branch delay slot |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 94 | if (size_hi) { |
| 95 | NewLIR3(cu, kMipsOri, rEnd, rEnd, size_lo); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 96 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 97 | NewLIR3(cu, kMipsOri, rEnd, r_ZERO, size_lo); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 98 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 99 | GenBarrier(cu); // Scheduling barrier |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 100 | |
| 101 | // Construct BaseLabel and set up table base register |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 102 | LIR* base_label = NewLIR0(cu, kPseudoTargetLabel); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 103 | // Remember base label so offsets can be computed later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 104 | tab_rec->anchor = base_label; |
| 105 | int rBase = AllocTemp(cu); |
| 106 | NewLIR4(cu, kMipsDelta, rBase, 0, reinterpret_cast<uintptr_t>(base_label), |
| 107 | reinterpret_cast<uintptr_t>(tab_rec)); |
| 108 | OpRegRegReg(cu, kOpAdd, rEnd, rEnd, rBase); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 109 | |
| 110 | // Grab switch test value |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 111 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 112 | |
| 113 | // Test loop |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 114 | int r_key = AllocTemp(cu); |
| 115 | LIR* loop_label = NewLIR0(cu, kPseudoTargetLabel); |
| 116 | LIR* exit_branch = OpCmpBranch(cu , kCondEq, rBase, rEnd, NULL); |
| 117 | LoadWordDisp(cu, rBase, 0, r_key); |
| 118 | OpRegImm(cu, kOpAdd, rBase, 8); |
| 119 | OpCmpBranch(cu, kCondNe, rl_src.low_reg, r_key, loop_label); |
| 120 | int r_disp = AllocTemp(cu); |
| 121 | LoadWordDisp(cu, rBase, -4, r_disp); |
| 122 | OpRegRegReg(cu, kOpAdd, r_RA, r_RA, r_disp); |
| 123 | OpReg(cu, kOpBx, r_RA); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 124 | |
| 125 | // Loop exit |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 126 | LIR* exit_label = NewLIR0(cu, kPseudoTargetLabel); |
| 127 | exit_branch->target = exit_label; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Code pattern will look something like: |
| 132 | * |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 133 | * lw r_val |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 134 | * jal BaseLabel ; stores "return address" (BaseLabel) in r_RA |
| 135 | * nop ; opportunistically fill |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 136 | * [subiu r_val, bias] ; Remove bias if low_val != 0 |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 137 | * bound check -> done |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 138 | * lw r_disp, [r_RA, r_val] |
| 139 | * addu r_RA, r_disp |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 140 | * jr r_RA |
| 141 | * done: |
| 142 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 143 | void MipsCodegen::GenPackedSwitch(CompilationUnit* cu, uint32_t table_offset, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 144 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 145 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
| 146 | if (cu->verbose) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 147 | DumpPackedSwitchTable(table); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 148 | } |
| 149 | // Add the table to the list - we'll process it later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 150 | SwitchTable *tab_rec = |
| 151 | static_cast<SwitchTable*>(NewMem(cu, sizeof(SwitchTable), true, kAllocData)); |
| 152 | tab_rec->table = table; |
| 153 | tab_rec->vaddr = cu->current_dalvik_offset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 154 | int size = table[1]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 155 | tab_rec->targets = static_cast<LIR**>(NewMem(cu, size * sizeof(LIR*), true, kAllocLIR)); |
| 156 | InsertGrowableList(cu, &cu->switch_tables, reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 157 | |
| 158 | // Get the switch value |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 159 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 160 | |
| 161 | // Prepare the bias. If too big, handle 1st stage here |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 162 | int low_key = s4FromSwitchData(&table[2]); |
| 163 | bool large_bias = false; |
| 164 | int r_key; |
| 165 | if (low_key == 0) { |
| 166 | r_key = rl_src.low_reg; |
| 167 | } else if ((low_key & 0xffff) != low_key) { |
| 168 | r_key = AllocTemp(cu); |
| 169 | LoadConstant(cu, r_key, low_key); |
| 170 | large_bias = true; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 171 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 172 | r_key = AllocTemp(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // Must prevent code motion for the curr pc pair |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 176 | GenBarrier(cu); |
| 177 | NewLIR0(cu, kMipsCurrPC); // Really a jal to .+8 |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 178 | // Now, fill the branch delay slot with bias strip |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 179 | if (low_key == 0) { |
| 180 | NewLIR0(cu, kMipsNop); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 181 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 182 | if (large_bias) { |
| 183 | OpRegRegReg(cu, kOpSub, r_key, rl_src.low_reg, r_key); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 184 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 185 | OpRegRegImm(cu, kOpSub, r_key, rl_src.low_reg, low_key); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 188 | GenBarrier(cu); // Scheduling barrier |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 189 | |
| 190 | // Construct BaseLabel and set up table base register |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 191 | LIR* base_label = NewLIR0(cu, kPseudoTargetLabel); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 192 | // Remember base label so offsets can be computed later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 193 | tab_rec->anchor = base_label; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 194 | |
| 195 | // Bounds check - if < 0 or >= size continue following switch |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 196 | LIR* branch_over = OpCmpImmBranch(cu, kCondHi, r_key, size-1, NULL); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 197 | |
| 198 | // Materialize the table base pointer |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 199 | int rBase = AllocTemp(cu); |
| 200 | NewLIR4(cu, kMipsDelta, rBase, 0, reinterpret_cast<uintptr_t>(base_label), |
| 201 | reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 202 | |
| 203 | // Load the displacement from the switch table |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 204 | int r_disp = AllocTemp(cu); |
| 205 | LoadBaseIndexed(cu, rBase, r_key, r_disp, 2, kWord); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 206 | |
| 207 | // Add to r_AP and go |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 208 | OpRegRegReg(cu, kOpAdd, r_RA, r_RA, r_disp); |
| 209 | OpReg(cu, kOpBx, r_RA); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 210 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 211 | /* branch_over target here */ |
| 212 | LIR* target = NewLIR0(cu, kPseudoTargetLabel); |
| 213 | branch_over->target = target; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Array data table format: |
| 218 | * ushort ident = 0x0300 magic value |
| 219 | * ushort width width of each element in the table |
| 220 | * uint size number of elements in the table |
| 221 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 222 | * padding at the end) |
| 223 | * |
| 224 | * Total size is 4+(width * size + 1)/2 16-bit code units. |
| 225 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 226 | void MipsCodegen::GenFillArrayData(CompilationUnit* cu, uint32_t table_offset, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 227 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 228 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 229 | // Add the table to the list - we'll process it later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 230 | FillArrayData *tab_rec = |
| 231 | reinterpret_cast<FillArrayData*>(NewMem(cu, sizeof(FillArrayData), true, kAllocData)); |
| 232 | tab_rec->table = table; |
| 233 | tab_rec->vaddr = cu->current_dalvik_offset; |
| 234 | uint16_t width = tab_rec->table[1]; |
| 235 | uint32_t size = tab_rec->table[2] | ((static_cast<uint32_t>(tab_rec->table[3])) << 16); |
| 236 | tab_rec->size = (size * width) + 8; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 237 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 238 | InsertGrowableList(cu, &cu->fill_array_data, reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 239 | |
| 240 | // Making a call - use explicit registers |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 241 | FlushAllRegs(cu); /* Everything to home location */ |
| 242 | LockCallTemps(cu); |
| 243 | LoadValueDirectFixed(cu, rl_src, rMIPS_ARG0); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 244 | |
| 245 | // Must prevent code motion for the curr pc pair |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 246 | GenBarrier(cu); |
| 247 | NewLIR0(cu, kMipsCurrPC); // Really a jal to .+8 |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 248 | // Now, fill the branch delay slot with the helper load |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 249 | int r_tgt = LoadHelper(cu, ENTRYPOINT_OFFSET(pHandleFillArrayDataFromCode)); |
| 250 | GenBarrier(cu); // Scheduling barrier |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 251 | |
| 252 | // Construct BaseLabel and set up table base register |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 253 | LIR* base_label = NewLIR0(cu, kPseudoTargetLabel); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 254 | |
| 255 | // Materialize a pointer to the fill data image |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 256 | NewLIR4(cu, kMipsDelta, rMIPS_ARG1, 0, reinterpret_cast<uintptr_t>(base_label), |
| 257 | reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 258 | |
| 259 | // And go... |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 260 | ClobberCalleeSave(cu); |
| 261 | LIR* call_inst = OpReg(cu, kOpBlx, r_tgt); // ( array*, fill_data* ) |
| 262 | MarkSafepointPC(cu, call_inst); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* |
| 266 | * TODO: implement fast path to short-circuit thin-lock case |
| 267 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 268 | void MipsCodegen::GenMonitorEnter(CompilationUnit* cu, int opt_flags, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 269 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 270 | FlushAllRegs(cu); |
| 271 | LoadValueDirectFixed(cu, rl_src, rMIPS_ARG0); // Get obj |
| 272 | LockCallTemps(cu); // Prepare for explicit register usage |
| 273 | GenNullCheck(cu, rl_src.s_reg_low, rMIPS_ARG0, opt_flags); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 274 | // Go expensive route - artLockObjectFromCode(self, obj); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 275 | int r_tgt = LoadHelper(cu, ENTRYPOINT_OFFSET(pLockObjectFromCode)); |
| 276 | ClobberCalleeSave(cu); |
| 277 | LIR* call_inst = OpReg(cu, kOpBlx, r_tgt); |
| 278 | MarkSafepointPC(cu, call_inst); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* |
| 282 | * TODO: implement fast path to short-circuit thin-lock case |
| 283 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 284 | void MipsCodegen::GenMonitorExit(CompilationUnit* cu, int opt_flags, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 285 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 286 | FlushAllRegs(cu); |
| 287 | LoadValueDirectFixed(cu, rl_src, rMIPS_ARG0); // Get obj |
| 288 | LockCallTemps(cu); // Prepare for explicit register usage |
| 289 | GenNullCheck(cu, rl_src.s_reg_low, rMIPS_ARG0, opt_flags); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 290 | // Go expensive route - UnlockObjectFromCode(obj); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 291 | int r_tgt = LoadHelper(cu, ENTRYPOINT_OFFSET(pUnlockObjectFromCode)); |
| 292 | ClobberCalleeSave(cu); |
| 293 | LIR* call_inst = OpReg(cu, kOpBlx, r_tgt); |
| 294 | MarkSafepointPC(cu, call_inst); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Mark garbage collection card. Skip if the value we're storing is null. |
| 299 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 300 | void MipsCodegen::MarkGCCard(CompilationUnit* cu, int val_reg, int tgt_addr_reg) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 301 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 302 | int reg_card_base = AllocTemp(cu); |
| 303 | int reg_card_no = AllocTemp(cu); |
| 304 | LIR* branch_over = OpCmpImmBranch(cu, kCondEq, val_reg, 0, NULL); |
| 305 | LoadWordDisp(cu, rMIPS_SELF, Thread::CardTableOffset().Int32Value(), reg_card_base); |
| 306 | OpRegRegImm(cu, kOpLsr, reg_card_no, tgt_addr_reg, CardTable::kCardShift); |
| 307 | StoreBaseIndexed(cu, reg_card_base, reg_card_no, reg_card_base, 0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 308 | kUnsignedByte); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 309 | LIR* target = NewLIR0(cu, kPseudoTargetLabel); |
| 310 | branch_over->target = target; |
| 311 | FreeTemp(cu, reg_card_base); |
| 312 | FreeTemp(cu, reg_card_no); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 313 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 314 | void MipsCodegen::GenEntrySequence(CompilationUnit* cu, RegLocation* ArgLocs, RegLocation rl_method) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 315 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 316 | int spill_count = cu->num_core_spills + cu->num_fp_spills; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 317 | /* |
| 318 | * On entry, rMIPS_ARG0, rMIPS_ARG1, rMIPS_ARG2 & rMIPS_ARG3 are live. Let the register |
| 319 | * allocation mechanism know so it doesn't try to use any of them when |
| 320 | * expanding the frame or flushing. This leaves the utility |
| 321 | * code with a single temp: r12. This should be enough. |
| 322 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 323 | LockTemp(cu, rMIPS_ARG0); |
| 324 | LockTemp(cu, rMIPS_ARG1); |
| 325 | LockTemp(cu, rMIPS_ARG2); |
| 326 | LockTemp(cu, rMIPS_ARG3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * We can safely skip the stack overflow check if we're |
| 330 | * a leaf *and* our frame size < fudge factor. |
| 331 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 332 | bool skip_overflow_check = ((cu->attrs & METHOD_IS_LEAF) && |
| 333 | (static_cast<size_t>(cu->frame_size) < Thread::kStackOverflowReservedBytes)); |
| 334 | NewLIR0(cu, kPseudoMethodEntry); |
| 335 | int check_reg = AllocTemp(cu); |
| 336 | int new_sp = AllocTemp(cu); |
| 337 | if (!skip_overflow_check) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 338 | /* Load stack limit */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 339 | LoadWordDisp(cu, rMIPS_SELF, Thread::StackEndOffset().Int32Value(), check_reg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 340 | } |
| 341 | /* Spill core callee saves */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 342 | SpillCoreRegs(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 343 | /* NOTE: promotion of FP regs currently unsupported, thus no FP spill */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 344 | DCHECK_EQ(cu->num_fp_spills, 0); |
| 345 | if (!skip_overflow_check) { |
| 346 | OpRegRegImm(cu, kOpSub, new_sp, rMIPS_SP, cu->frame_size - (spill_count * 4)); |
| 347 | GenRegRegCheck(cu, kCondCc, new_sp, check_reg, kThrowStackOverflow); |
| 348 | OpRegCopy(cu, rMIPS_SP, new_sp); // Establish stack |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 349 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 350 | OpRegImm(cu, kOpSub, rMIPS_SP, cu->frame_size - (spill_count * 4)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 351 | } |
| 352 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 353 | FlushIns(cu, ArgLocs, rl_method); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 354 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 355 | FreeTemp(cu, rMIPS_ARG0); |
| 356 | FreeTemp(cu, rMIPS_ARG1); |
| 357 | FreeTemp(cu, rMIPS_ARG2); |
| 358 | FreeTemp(cu, rMIPS_ARG3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 359 | } |
| 360 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 361 | void MipsCodegen::GenExitSequence(CompilationUnit* cu) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 362 | { |
| 363 | /* |
| 364 | * In the exit path, rMIPS_RET0/rMIPS_RET1 are live - make sure they aren't |
| 365 | * allocated by the register utilities as temps. |
| 366 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 367 | LockTemp(cu, rMIPS_RET0); |
| 368 | LockTemp(cu, rMIPS_RET1); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 369 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 370 | NewLIR0(cu, kPseudoMethodExit); |
| 371 | UnSpillCoreRegs(cu); |
| 372 | OpReg(cu, kOpBx, r_RA); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | } // namespace art |