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