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) { |
| 28 | if (p->is_temp) { |
| 29 | DCHECK(!(p->live && p->dirty)) << "Live & dirty temp in clobber"; |
| 30 | p->live = false; |
| 31 | p->s_reg = INVALID_SREG; |
| 32 | p->def_start = NULL; |
| 33 | p->def_end = NULL; |
| 34 | if (p->pair) { |
| 35 | p->pair = false; |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 36 | p = GetRegInfo(p->partner); |
| 37 | p->pair = false; |
| 38 | p->live = false; |
| 39 | p->s_reg = INVALID_SREG; |
| 40 | p->def_start = NULL; |
| 41 | p->def_end = NULL; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | inline LIR* Mir2Lir::RawLIR(int dalvik_offset, int opcode, int op0, |
| 47 | int op1, int op2, int op3, int op4, LIR* target) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 48 | LIR* insn = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), ArenaAllocator::kAllocLIR)); |
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 |
| 61 | insn->use_mask = insn->def_mask = ENCODE_ALL; |
| 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) { |
| 71 | DCHECK(is_pseudo_opcode(opcode) || (GetTargetInstFlags(opcode) & NO_OPERAND)) |
| 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) { |
| 81 | DCHECK(is_pseudo_opcode(opcode) || (GetTargetInstFlags(opcode) & IS_UNARY_OP)) |
| 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) { |
| 91 | DCHECK(is_pseudo_opcode(opcode) || (GetTargetInstFlags(opcode) & IS_BINARY_OP)) |
| 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 | |
| 100 | inline LIR* Mir2Lir::NewLIR3(int opcode, int dest, int src1, int src2) { |
| 101 | DCHECK(is_pseudo_opcode(opcode) || (GetTargetInstFlags(opcode) & IS_TERTIARY_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, dest, src1, src2); |
| 106 | AppendLIR(insn); |
| 107 | return insn; |
| 108 | } |
| 109 | |
| 110 | inline LIR* Mir2Lir::NewLIR4(int opcode, int dest, int src1, int src2, int info) { |
| 111 | DCHECK(is_pseudo_opcode(opcode) || (GetTargetInstFlags(opcode) & IS_QUAD_OP)) |
| 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, info); |
| 116 | AppendLIR(insn); |
| 117 | return insn; |
| 118 | } |
| 119 | |
| 120 | inline LIR* Mir2Lir::NewLIR5(int opcode, int dest, int src1, int src2, int info1, |
| 121 | int info2) { |
| 122 | DCHECK(is_pseudo_opcode(opcode) || (GetTargetInstFlags(opcode) & IS_QUIN_OP)) |
| 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, info1, info2); |
| 127 | AppendLIR(insn); |
| 128 | return insn; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Mark the corresponding bit(s). |
| 133 | */ |
| 134 | inline void Mir2Lir::SetupRegMask(uint64_t* mask, int reg) { |
| 135 | *mask |= GetRegMaskCommon(reg); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Set up the proper fields in the resource mask |
| 140 | */ |
| 141 | inline void Mir2Lir::SetupResourceMasks(LIR* lir) { |
| 142 | int opcode = lir->opcode; |
| 143 | |
| 144 | if (opcode <= 0) { |
| 145 | lir->use_mask = lir->def_mask = 0; |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | uint64_t flags = GetTargetInstFlags(opcode); |
| 150 | |
| 151 | if (flags & NEEDS_FIXUP) { |
| 152 | lir->flags.pcRelFixup = true; |
| 153 | } |
| 154 | |
| 155 | /* Get the starting size of the instruction's template */ |
| 156 | lir->flags.size = GetInsnSize(lir); |
| 157 | |
| 158 | /* Set up the mask for resources that are updated */ |
| 159 | if (flags & (IS_LOAD | IS_STORE)) { |
| 160 | /* Default to heap - will catch specialized classes later */ |
| 161 | SetMemRefType(lir, flags & IS_LOAD, kHeapRef); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Conservatively assume the branch here will call out a function that in |
| 166 | * turn will trash everything. |
| 167 | */ |
| 168 | if (flags & IS_BRANCH) { |
| 169 | lir->def_mask = lir->use_mask = ENCODE_ALL; |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | if (flags & REG_DEF0) { |
| 174 | SetupRegMask(&lir->def_mask, lir->operands[0]); |
| 175 | } |
| 176 | |
| 177 | if (flags & REG_DEF1) { |
| 178 | SetupRegMask(&lir->def_mask, lir->operands[1]); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | if (flags & SETS_CCODES) { |
| 183 | lir->def_mask |= ENCODE_CCODE; |
| 184 | } |
| 185 | |
| 186 | if (flags & (REG_USE0 | REG_USE1 | REG_USE2 | REG_USE3)) { |
| 187 | int i; |
| 188 | |
| 189 | for (i = 0; i < 4; i++) { |
| 190 | if (flags & (1 << (kRegUse0 + i))) { |
| 191 | SetupRegMask(&lir->use_mask, lir->operands[i]); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (flags & USES_CCODES) { |
| 197 | lir->use_mask |= ENCODE_CCODE; |
| 198 | } |
| 199 | |
| 200 | // Handle target-specific actions |
| 201 | SetupTargetResourceMasks(lir); |
| 202 | } |
| 203 | |
buzbee | bd663de | 2013-09-10 15:41:31 -0700 | [diff] [blame] | 204 | inline art::Mir2Lir::RegisterInfo* Mir2Lir::GetRegInfo(int reg) { |
| 205 | DCHECK(reginfo_map_.Get(reg) != NULL); |
| 206 | return reginfo_map_.Get(reg); |
| 207 | } |
| 208 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 209 | } // namespace art |
| 210 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 211 | #endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_ |