Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_ |
| 18 | #define ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include "mir_to_lir.h" |
| 21 | |
| 22 | #include "dex/compiler_internals.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | /* Mark a temp register as dead. Does not affect allocation state. */ |
| 27 | inline void Mir2Lir::ClobberBody(RegisterInfo* p) { |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame^] | 28 | DCHECK(p->IsTemp()); |
| 29 | if (!p->IsDead()) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 30 | DCHECK(!(p->IsLive() && p->IsDirty())) << "Live & dirty temp in clobber"; |
buzbee | 30adc73 | 2014-05-09 15:10:18 -0700 | [diff] [blame] | 31 | p->MarkDead(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 32 | p->ResetDefBody(); |
| 33 | if (p->IsWide()) { |
| 34 | p->SetIsWide(false); |
| 35 | if (p->GetReg() != p->Partner()) { |
| 36 | // Register pair - deal with the other half. |
| 37 | p = GetRegInfo(p->Partner()); |
| 38 | p->SetIsWide(false); |
buzbee | 30adc73 | 2014-05-09 15:10:18 -0700 | [diff] [blame] | 39 | p->MarkDead(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 40 | p->ResetDefBody(); |
| 41 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 46 | inline LIR* Mir2Lir::RawLIR(DexOffset dalvik_offset, int opcode, int op0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 47 | int op1, int op2, int op3, int op4, LIR* target) { |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 48 | LIR* insn = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocLIR)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 49 | insn->dalvik_offset = dalvik_offset; |
| 50 | insn->opcode = opcode; |
| 51 | insn->operands[0] = op0; |
| 52 | insn->operands[1] = op1; |
| 53 | insn->operands[2] = op2; |
| 54 | insn->operands[3] = op3; |
| 55 | insn->operands[4] = op4; |
| 56 | insn->target = target; |
| 57 | SetupResourceMasks(insn); |
| 58 | if ((opcode == kPseudoTargetLabel) || (opcode == kPseudoSafepointPC) || |
| 59 | (opcode == kPseudoExportedPC)) { |
| 60 | // Always make labels scheduling barriers |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 61 | DCHECK(!insn->flags.use_def_invalid); |
| 62 | insn->u.m.use_mask = insn->u.m.def_mask = ENCODE_ALL; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 63 | } |
| 64 | return insn; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * The following are building blocks to construct low-level IRs with 0 - 4 |
| 69 | * operands. |
| 70 | */ |
| 71 | inline LIR* Mir2Lir::NewLIR0(int opcode) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 72 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & NO_OPERAND)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 73 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 74 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 75 | << current_dalvik_offset_; |
| 76 | LIR* insn = RawLIR(current_dalvik_offset_, opcode); |
| 77 | AppendLIR(insn); |
| 78 | return insn; |
| 79 | } |
| 80 | |
| 81 | inline LIR* Mir2Lir::NewLIR1(int opcode, int dest) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 82 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_UNARY_OP)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 83 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 84 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 85 | << current_dalvik_offset_; |
| 86 | LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest); |
| 87 | AppendLIR(insn); |
| 88 | return insn; |
| 89 | } |
| 90 | |
| 91 | inline LIR* Mir2Lir::NewLIR2(int opcode, int dest, int src1) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 92 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_BINARY_OP)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 93 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 94 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 95 | << current_dalvik_offset_; |
| 96 | LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1); |
| 97 | AppendLIR(insn); |
| 98 | return insn; |
| 99 | } |
| 100 | |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 101 | inline LIR* Mir2Lir::NewLIR2NoDest(int opcode, int src, int info) { |
| 102 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_UNARY_OP)) |
| 103 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 104 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 105 | << current_dalvik_offset_; |
| 106 | LIR* insn = RawLIR(current_dalvik_offset_, opcode, src, info); |
| 107 | AppendLIR(insn); |
| 108 | return insn; |
| 109 | } |
| 110 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 111 | inline LIR* Mir2Lir::NewLIR3(int opcode, int dest, int src1, int src2) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 112 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_TERTIARY_OP)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 113 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 114 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 115 | << current_dalvik_offset_; |
| 116 | LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1, src2); |
| 117 | AppendLIR(insn); |
| 118 | return insn; |
| 119 | } |
| 120 | |
| 121 | inline LIR* Mir2Lir::NewLIR4(int opcode, int dest, int src1, int src2, int info) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 122 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_QUAD_OP)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 123 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 124 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 125 | << current_dalvik_offset_; |
| 126 | LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1, src2, info); |
| 127 | AppendLIR(insn); |
| 128 | return insn; |
| 129 | } |
| 130 | |
| 131 | inline LIR* Mir2Lir::NewLIR5(int opcode, int dest, int src1, int src2, int info1, |
| 132 | int info2) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 133 | DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_QUIN_OP)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 134 | << GetTargetInstName(opcode) << " " << opcode << " " |
| 135 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 136 | << current_dalvik_offset_; |
| 137 | LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1, src2, info1, info2); |
| 138 | AppendLIR(insn); |
| 139 | return insn; |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Mark the corresponding bit(s). |
| 144 | */ |
| 145 | inline void Mir2Lir::SetupRegMask(uint64_t* mask, int reg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 146 | DCHECK_EQ((reg & ~RegStorage::kRegValMask), 0); |
| 147 | DCHECK(reginfo_map_.Get(reg) != nullptr) << "No info for 0x" << reg; |
| 148 | *mask |= reginfo_map_.Get(reg)->DefUseMask(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Set up the proper fields in the resource mask |
| 153 | */ |
| 154 | inline void Mir2Lir::SetupResourceMasks(LIR* lir) { |
| 155 | int opcode = lir->opcode; |
| 156 | |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 157 | if (IsPseudoLirOp(opcode)) { |
| 158 | if (opcode != kPseudoBarrier) { |
| 159 | lir->flags.fixup = kFixupLabel; |
| 160 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | |
| 164 | uint64_t flags = GetTargetInstFlags(opcode); |
| 165 | |
| 166 | if (flags & NEEDS_FIXUP) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 167 | // Note: target-specific setup may specialize the fixup kind. |
| 168 | lir->flags.fixup = kFixupLabel; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* Get the starting size of the instruction's template */ |
| 172 | lir->flags.size = GetInsnSize(lir); |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 173 | estimated_native_code_size_ += lir->flags.size; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 174 | /* Set up the mask for resources that are updated */ |
| 175 | if (flags & (IS_LOAD | IS_STORE)) { |
| 176 | /* Default to heap - will catch specialized classes later */ |
| 177 | SetMemRefType(lir, flags & IS_LOAD, kHeapRef); |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Conservatively assume the branch here will call out a function that in |
| 182 | * turn will trash everything. |
| 183 | */ |
| 184 | if (flags & IS_BRANCH) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 185 | lir->u.m.def_mask = lir->u.m.use_mask = ENCODE_ALL; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | |
| 189 | if (flags & REG_DEF0) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 190 | SetupRegMask(&lir->u.m.def_mask, lir->operands[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | if (flags & REG_DEF1) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 194 | SetupRegMask(&lir->u.m.def_mask, lir->operands[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 197 | if (flags & REG_DEF2) { |
| 198 | SetupRegMask(&lir->u.m.def_mask, lir->operands[2]); |
| 199 | } |
| 200 | |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 201 | if (flags & REG_USE0) { |
| 202 | SetupRegMask(&lir->u.m.use_mask, lir->operands[0]); |
| 203 | } |
| 204 | |
| 205 | if (flags & REG_USE1) { |
| 206 | SetupRegMask(&lir->u.m.use_mask, lir->operands[1]); |
| 207 | } |
| 208 | |
| 209 | if (flags & REG_USE2) { |
| 210 | SetupRegMask(&lir->u.m.use_mask, lir->operands[2]); |
| 211 | } |
| 212 | |
| 213 | if (flags & REG_USE3) { |
| 214 | SetupRegMask(&lir->u.m.use_mask, lir->operands[3]); |
| 215 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 216 | |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 217 | if (flags & REG_USE4) { |
| 218 | SetupRegMask(&lir->u.m.use_mask, lir->operands[4]); |
| 219 | } |
| 220 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 221 | if (flags & SETS_CCODES) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 222 | lir->u.m.def_mask |= ENCODE_CCODE; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | if (flags & USES_CCODES) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 226 | lir->u.m.use_mask |= ENCODE_CCODE; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Handle target-specific actions |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 230 | SetupTargetResourceMasks(lir, flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 231 | } |
| 232 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 233 | inline art::Mir2Lir::RegisterInfo* Mir2Lir::GetRegInfo(RegStorage reg) { |
| 234 | RegisterInfo* res = reg.IsPair() ? reginfo_map_.Get(reg.GetLowReg()) : |
| 235 | reginfo_map_.Get(reg.GetReg()); |
| 236 | DCHECK(res != nullptr); |
| 237 | return res; |
buzbee | bd663de | 2013-09-10 15:41:31 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 240 | } // namespace art |
| 241 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 242 | #endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_ |