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 X86 ISA */ |
| 18 | |
| 19 | #include "codegen_x86.h" |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame] | 20 | |
| 21 | #include "base/logging.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 22 | #include "dex/quick/mir_to_lir-inl.h" |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame] | 23 | #include "driver/compiler_driver.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [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 | #include "x86_lir.h" |
| 28 | |
| 29 | namespace art { |
| 30 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 31 | /* |
| 32 | * The sparse table in the literal pool is an array of <key,displacement> |
| 33 | * pairs. |
| 34 | */ |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 35 | void X86Mir2Lir::GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) { |
Chao-ying Fu | da96aed | 2014-10-27 14:42:00 -0700 | [diff] [blame] | 36 | GenSmallSparseSwitch(mir, table_offset, rl_src); |
| 37 | } |
| 38 | |
| 39 | /* |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 40 | * Code pattern will look something like: |
| 41 | * |
| 42 | * mov r_val, .. |
| 43 | * call 0 |
| 44 | * pop r_start_of_method |
| 45 | * sub r_start_of_method, .. |
| 46 | * mov r_key_reg, r_val |
| 47 | * sub r_key_reg, low_key |
| 48 | * cmp r_key_reg, size-1 ; bound check |
| 49 | * ja done |
| 50 | * mov r_disp, [r_start_of_method + r_key_reg * 4 + table_offset] |
| 51 | * add r_start_of_method, r_disp |
| 52 | * jmp r_start_of_method |
| 53 | * done: |
| 54 | */ |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 55 | void X86Mir2Lir::GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) { |
Chao-ying Fu | 72f53af | 2014-11-11 16:48:40 -0800 | [diff] [blame] | 56 | const uint16_t* table = mir_graph_->GetTable(mir, table_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 57 | // Add the table to the list - we'll process it later |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 58 | SwitchTable* tab_rec = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 59 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
Chao-ying Fu | 72f53af | 2014-11-11 16:48:40 -0800 | [diff] [blame] | 60 | tab_rec->switch_mir = mir; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 61 | tab_rec->table = table; |
| 62 | tab_rec->vaddr = current_dalvik_offset_; |
| 63 | int size = table[1]; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 64 | switch_tables_.push_back(tab_rec); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 65 | |
| 66 | // Get the switch value |
| 67 | rl_src = LoadValue(rl_src, kCoreReg); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 68 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 69 | int low_key = s4FromSwitchData(&table[2]); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 70 | RegStorage keyReg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | // Remove the bias, if necessary |
| 72 | if (low_key == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 73 | keyReg = rl_src.reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 74 | } else { |
| 75 | keyReg = AllocTemp(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 76 | OpRegRegImm(kOpSub, keyReg, rl_src.reg, low_key); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 77 | } |
Mark Mendell | 27dee8b | 2014-12-01 19:06:12 -0500 | [diff] [blame] | 78 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 79 | // Bounds check - if < 0 or >= size continue following switch |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 80 | OpRegImm(kOpCmp, keyReg, size - 1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 81 | LIR* branch_over = OpCondBranch(kCondHi, NULL); |
| 82 | |
Mark Mendell | 27dee8b | 2014-12-01 19:06:12 -0500 | [diff] [blame] | 83 | RegStorage addr_for_jump; |
| 84 | if (cu_->target64) { |
| 85 | RegStorage table_base = AllocTempWide(); |
| 86 | // Load the address of the table into table_base. |
| 87 | LIR* lea = RawLIR(current_dalvik_offset_, kX86Lea64RM, table_base.GetReg(), kRIPReg, |
| 88 | 256, 0, WrapPointer(tab_rec)); |
| 89 | lea->flags.fixup = kFixupSwitchTable; |
| 90 | AppendLIR(lea); |
| 91 | |
| 92 | // Load the offset from the table out of the table. |
| 93 | addr_for_jump = AllocTempWide(); |
| 94 | NewLIR5(kX86MovsxdRA, addr_for_jump.GetReg(), table_base.GetReg(), keyReg.GetReg(), 2, 0); |
| 95 | |
| 96 | // Add the offset from the table to the table base. |
| 97 | OpRegReg(kOpAdd, addr_for_jump, table_base); |
| 98 | } else { |
| 99 | // Materialize a pointer to the switch table. |
| 100 | RegStorage start_of_method_reg; |
| 101 | if (base_of_code_ != nullptr) { |
| 102 | // We can use the saved value. |
| 103 | RegLocation rl_method = mir_graph_->GetRegLocation(base_of_code_->s_reg_low); |
| 104 | rl_method = LoadValue(rl_method, kCoreReg); |
| 105 | start_of_method_reg = rl_method.reg; |
| 106 | store_method_addr_used_ = true; |
| 107 | } else { |
| 108 | start_of_method_reg = AllocTempRef(); |
| 109 | NewLIR1(kX86StartOfMethod, start_of_method_reg.GetReg()); |
| 110 | } |
| 111 | // Load the displacement from the switch table. |
| 112 | addr_for_jump = AllocTemp(); |
| 113 | NewLIR5(kX86PcRelLoadRA, addr_for_jump.GetReg(), start_of_method_reg.GetReg(), keyReg.GetReg(), |
| 114 | 2, WrapPointer(tab_rec)); |
| 115 | // Add displacement to start of method. |
| 116 | OpRegReg(kOpAdd, addr_for_jump, start_of_method_reg); |
| 117 | } |
| 118 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 119 | // ..and go! |
Mark Mendell | 27dee8b | 2014-12-01 19:06:12 -0500 | [diff] [blame] | 120 | tab_rec->anchor = NewLIR1(kX86JmpR, addr_for_jump.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 121 | |
| 122 | /* branch_over target here */ |
| 123 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 124 | branch_over->target = target; |
| 125 | } |
| 126 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 127 | void X86Mir2Lir::GenMoveException(RegLocation rl_dest) { |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 128 | int ex_offset = cu_->target64 ? |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 129 | Thread::ExceptionOffset<8>().Int32Value() : |
| 130 | Thread::ExceptionOffset<4>().Int32Value(); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 131 | RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true); |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 132 | NewLIR2(cu_->target64 ? kX86Mov64RT : kX86Mov32RT, rl_result.reg.GetReg(), ex_offset); |
| 133 | NewLIR2(cu_->target64 ? kX86Mov64TI : kX86Mov32TI, ex_offset, 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 134 | StoreValue(rl_dest, rl_result); |
| 135 | } |
| 136 | |
Vladimir Marko | bf535be | 2014-11-19 18:52:35 +0000 | [diff] [blame] | 137 | void X86Mir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) { |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 138 | DCHECK_EQ(tgt_addr_reg.Is64Bit(), cu_->target64); |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 139 | RegStorage reg_card_base = AllocTempRef(); |
| 140 | RegStorage reg_card_no = AllocTempRef(); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 141 | int ct_offset = cu_->target64 ? |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 142 | Thread::CardTableOffset<8>().Int32Value() : |
| 143 | Thread::CardTableOffset<4>().Int32Value(); |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 144 | NewLIR2(cu_->target64 ? kX86Mov64RT : kX86Mov32RT, reg_card_base.GetReg(), ct_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 145 | OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 146 | StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 147 | FreeTemp(reg_card_base); |
| 148 | FreeTemp(reg_card_no); |
| 149 | } |
| 150 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 151 | void X86Mir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 152 | /* |
| 153 | * On entry, rX86_ARG0, rX86_ARG1, rX86_ARG2 are live. Let the register |
| 154 | * allocation mechanism know so it doesn't try to use any of them when |
| 155 | * expanding the frame or flushing. This leaves the utility |
| 156 | * code with no spare temps. |
| 157 | */ |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 158 | const RegStorage arg0 = TargetReg32(kArg0); |
| 159 | const RegStorage arg1 = TargetReg32(kArg1); |
| 160 | const RegStorage arg2 = TargetReg32(kArg2); |
| 161 | LockTemp(arg0); |
| 162 | LockTemp(arg1); |
| 163 | LockTemp(arg2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 164 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 165 | /* |
| 166 | * We can safely skip the stack overflow check if we're |
| 167 | * a leaf *and* our frame size < fudge factor. |
| 168 | */ |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 169 | const InstructionSet isa = cu_->target64 ? kX86_64 : kX86; |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 170 | bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, isa); |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 171 | const RegStorage rs_rSP = cu_->target64 ? rs_rX86_SP_64 : rs_rX86_SP_32; |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 172 | |
| 173 | // If we doing an implicit stack overflow check, perform the load immediately |
| 174 | // before the stack pointer is decremented and anything is saved. |
| 175 | if (!skip_overflow_check && |
| 176 | cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks()) { |
| 177 | // Implicit stack overflow check. |
| 178 | // test eax,[esp + -overflow] |
| 179 | int overflow = GetStackOverflowReservedBytes(isa); |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 180 | NewLIR3(kX86Test32RM, rs_rAX.GetReg(), rs_rSP.GetReg(), -overflow); |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 181 | MarkPossibleStackOverflowException(); |
| 182 | } |
| 183 | |
| 184 | /* Build frame, return address already on stack */ |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 185 | stack_decrement_ = OpRegImm(kOpSub, rs_rSP, frame_size_ - |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 186 | GetInstructionSetPointerSize(cu_->instruction_set)); |
| 187 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 188 | NewLIR0(kPseudoMethodEntry); |
| 189 | /* Spill core callee saves */ |
| 190 | SpillCoreRegs(); |
Serguei Katkov | c380191 | 2014-07-08 17:21:53 +0700 | [diff] [blame] | 191 | SpillFPRegs(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 192 | if (!skip_overflow_check) { |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 193 | class StackOverflowSlowPath : public LIRSlowPath { |
| 194 | public: |
| 195 | StackOverflowSlowPath(Mir2Lir* m2l, LIR* branch, size_t sp_displace) |
| 196 | : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, nullptr), sp_displace_(sp_displace) { |
| 197 | } |
| 198 | void Compile() OVERRIDE { |
| 199 | m2l_->ResetRegPool(); |
| 200 | m2l_->ResetDefTracking(); |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 201 | GenerateTargetLabel(kPseudoThrowTarget); |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 202 | const RegStorage local_rs_rSP = cu_->target64 ? rs_rX86_SP_64 : rs_rX86_SP_32; |
| 203 | m2l_->OpRegImm(kOpAdd, local_rs_rSP, sp_displace_); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 204 | m2l_->ClobberCallerSave(); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 205 | // Assumes codegen and target are in thumb2 mode. |
Andreas Gampe | 9843059 | 2014-07-27 19:44:50 -0700 | [diff] [blame] | 206 | m2l_->CallHelper(RegStorage::InvalidReg(), kQuickThrowStackOverflow, |
| 207 | false /* MarkSafepointPC */, false /* UseLink */); |
Mathieu Chartier | 0d507d1 | 2014-03-19 10:17:28 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | private: |
| 211 | const size_t sp_displace_; |
| 212 | }; |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 213 | if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks()) { |
| 214 | // TODO: for large frames we should do something like: |
| 215 | // spill ebp |
| 216 | // lea ebp, [esp + frame_size] |
| 217 | // cmp ebp, fs:[stack_end_] |
| 218 | // jcc stack_overflow_exception |
| 219 | // mov esp, ebp |
| 220 | // in case a signal comes in that's not using an alternate signal stack and the large frame |
| 221 | // may have moved us outside of the reserved area at the end of the stack. |
| 222 | // cmp rs_rX86_SP, fs:[stack_end_]; jcc throw_slowpath |
| 223 | if (cu_->target64) { |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 224 | OpRegThreadMem(kOpCmp, rs_rX86_SP_64, Thread::StackEndOffset<8>()); |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 225 | } else { |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 226 | OpRegThreadMem(kOpCmp, rs_rX86_SP_32, Thread::StackEndOffset<4>()); |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 227 | } |
| 228 | LIR* branch = OpCondBranch(kCondUlt, nullptr); |
| 229 | AddSlowPath( |
Chao-ying Fu | e0ccdc0 | 2014-06-06 17:32:37 -0700 | [diff] [blame] | 230 | new(arena_)StackOverflowSlowPath(this, branch, |
| 231 | frame_size_ - |
| 232 | GetInstructionSetPointerSize(cu_->instruction_set))); |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 233 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | FlushIns(ArgLocs, rl_method); |
| 237 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 238 | if (base_of_code_ != nullptr) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 239 | RegStorage method_start = TargetPtrReg(kArg0); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 240 | // We have been asked to save the address of the method start for later use. |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 241 | setup_method_address_[0] = NewLIR1(kX86StartOfMethod, method_start.GetReg()); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 242 | int displacement = SRegOffset(base_of_code_->s_reg_low); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 243 | // Native pointer - must be natural word size. |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 244 | setup_method_address_[1] = StoreBaseDisp(rs_rSP, displacement, method_start, |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 245 | cu_->target64 ? k64 : k32, kNotVolatile); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 248 | FreeTemp(arg0); |
| 249 | FreeTemp(arg1); |
| 250 | FreeTemp(arg2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void X86Mir2Lir::GenExitSequence() { |
| 254 | /* |
| 255 | * In the exit path, rX86_RET0/rX86_RET1 are live - make sure they aren't |
| 256 | * allocated by the register utilities as temps. |
| 257 | */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 258 | LockTemp(rs_rX86_RET0); |
| 259 | LockTemp(rs_rX86_RET1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 260 | |
| 261 | NewLIR0(kPseudoMethodExit); |
| 262 | UnSpillCoreRegs(); |
Serguei Katkov | c380191 | 2014-07-08 17:21:53 +0700 | [diff] [blame] | 263 | UnSpillFPRegs(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 264 | /* Remove frame except for return address */ |
Ian Rogers | b28c1c0 | 2014-11-08 11:21:21 -0800 | [diff] [blame] | 265 | const RegStorage rs_rSP = cu_->target64 ? rs_rX86_SP_64 : rs_rX86_SP_32; |
| 266 | stack_increment_ = OpRegImm(kOpAdd, rs_rSP, |
| 267 | frame_size_ - GetInstructionSetPointerSize(cu_->instruction_set)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 268 | NewLIR0(kX86Ret); |
| 269 | } |
| 270 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 271 | void X86Mir2Lir::GenSpecialExitSequence() { |
| 272 | NewLIR0(kX86Ret); |
| 273 | } |
| 274 | |
Vladimir Marko | 6ce3eba | 2015-02-16 13:05:59 +0000 | [diff] [blame] | 275 | void X86Mir2Lir::GenSpecialEntryForSuspend() { |
| 276 | // Keep 16-byte stack alignment, there's already the return address, so |
| 277 | // - for 32-bit push EAX, i.e. ArtMethod*, ESI, EDI, |
| 278 | // - for 64-bit push RAX, i.e. ArtMethod*. |
| 279 | if (!cu_->target64) { |
| 280 | DCHECK(!IsTemp(rs_rSI)); |
| 281 | DCHECK(!IsTemp(rs_rDI)); |
| 282 | core_spill_mask_ = |
Vladimir Marko | d7a5e55 | 2015-02-20 14:53:53 +0000 | [diff] [blame^] | 283 | (1u << rs_rDI.GetRegNum()) | (1u << rs_rSI.GetRegNum()) | (1u << rs_rRET.GetRegNum()); |
Vladimir Marko | 6ce3eba | 2015-02-16 13:05:59 +0000 | [diff] [blame] | 284 | num_core_spills_ = 3u; |
| 285 | } else { |
| 286 | core_spill_mask_ = (1u << rs_rRET.GetRegNum()); |
| 287 | num_core_spills_ = 1u; |
| 288 | } |
| 289 | fp_spill_mask_ = 0u; |
| 290 | num_fp_spills_ = 0u; |
| 291 | frame_size_ = 16u; |
| 292 | core_vmap_table_.clear(); |
| 293 | fp_vmap_table_.clear(); |
| 294 | if (!cu_->target64) { |
| 295 | NewLIR1(kX86Push32R, rs_rDI.GetReg()); |
| 296 | NewLIR1(kX86Push32R, rs_rSI.GetReg()); |
| 297 | } |
| 298 | NewLIR1(kX86Push32R, TargetReg(kArg0, kRef).GetReg()); // ArtMethod* |
| 299 | } |
| 300 | |
| 301 | void X86Mir2Lir::GenSpecialExitForSuspend() { |
| 302 | // Pop the frame. (ArtMethod* no longer needed but restore it anyway.) |
| 303 | NewLIR1(kX86Pop32R, TargetReg(kArg0, kRef).GetReg()); // ArtMethod* |
| 304 | if (!cu_->target64) { |
| 305 | NewLIR1(kX86Pop32R, rs_rSI.GetReg()); |
| 306 | NewLIR1(kX86Pop32R, rs_rDI.GetReg()); |
| 307 | } |
| 308 | } |
| 309 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 310 | void X86Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) { |
| 311 | if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 312 | return; |
| 313 | } |
| 314 | // Implicit null pointer check. |
| 315 | // test eax,[arg1+0] |
| 316 | NewLIR3(kX86Test32RM, rs_rAX.GetReg(), reg.GetReg(), 0); |
| 317 | MarkPossibleNullPointerException(opt_flags); |
| 318 | } |
| 319 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 320 | /* |
| 321 | * Bit of a hack here - in the absence of a real scheduling pass, |
| 322 | * emit the next instruction in static & direct invoke sequences. |
| 323 | */ |
| 324 | static int X86NextSDCallInsn(CompilationUnit* cu, CallInfo* info, |
| 325 | int state, const MethodReference& target_method, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 326 | uint32_t, |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 327 | uintptr_t direct_code, uintptr_t direct_method, |
| 328 | InvokeType type) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 329 | UNUSED(info, direct_code); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 330 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
| 331 | if (direct_method != 0) { |
| 332 | switch (state) { |
| 333 | case 0: // Get the current Method* [sets kArg0] |
| 334 | if (direct_method != static_cast<uintptr_t>(-1)) { |
| 335 | cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method); |
| 336 | } else { |
| 337 | cg->LoadMethodAddress(target_method, type, kArg0); |
| 338 | } |
| 339 | break; |
| 340 | default: |
| 341 | return -1; |
| 342 | } |
| 343 | } else { |
| 344 | RegStorage arg0_ref = cg->TargetReg(kArg0, kRef); |
| 345 | switch (state) { |
| 346 | case 0: // Get the current Method* [sets kArg0] |
| 347 | // TUNING: we can save a reg copy if Method* has been promoted. |
| 348 | cg->LoadCurrMethodDirect(arg0_ref); |
| 349 | break; |
| 350 | case 1: // Get method->dex_cache_resolved_methods_ |
| 351 | cg->LoadRefDisp(arg0_ref, |
| 352 | mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), |
| 353 | arg0_ref, |
| 354 | kNotVolatile); |
| 355 | break; |
| 356 | case 2: // Grab target method* |
| 357 | CHECK_EQ(cu->dex_file, target_method.dex_file); |
| 358 | cg->LoadRefDisp(arg0_ref, |
| 359 | mirror::ObjectArray<mirror::Object>::OffsetOfElement( |
| 360 | target_method.dex_method_index).Int32Value(), |
| 361 | arg0_ref, |
| 362 | kNotVolatile); |
| 363 | break; |
| 364 | default: |
| 365 | return -1; |
| 366 | } |
| 367 | } |
| 368 | return state + 1; |
| 369 | } |
| 370 | |
| 371 | NextCallInsn X86Mir2Lir::GetNextSDCallInsn() { |
| 372 | return X86NextSDCallInsn; |
| 373 | } |
| 374 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 375 | } // namespace art |