blob: b5b50a471efe4727f1b4e8f5e0b00e82730f6fb5 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_
18#define ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include "mir_to_lir.h"
21
22#include "dex/compiler_internals.h"
23
24namespace art {
25
26/* Mark a temp register as dead. Does not affect allocation state. */
27inline void Mir2Lir::ClobberBody(RegisterInfo* p) {
buzbee091cc402014-03-31 10:14:40 -070028 if (p->IsTemp()) {
29 DCHECK(!(p->IsLive() && p->IsDirty())) << "Live & dirty temp in clobber";
buzbee30adc732014-05-09 15:10:18 -070030 p->MarkDead();
buzbee091cc402014-03-31 10:14:40 -070031 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);
buzbee30adc732014-05-09 15:10:18 -070038 p->MarkDead();
buzbee091cc402014-03-31 10:14:40 -070039 p->ResetDefBody();
40 }
Brian Carlstrom7940e442013-07-12 13:46:57 -070041 }
42 }
43}
44
buzbee0d829482013-10-11 15:24:55 -070045inline LIR* Mir2Lir::RawLIR(DexOffset dalvik_offset, int opcode, int op0,
Brian Carlstrom7940e442013-07-12 13:46:57 -070046 int op1, int op2, int op3, int op4, LIR* target) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000047 LIR* insn = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocLIR));
Brian Carlstrom7940e442013-07-12 13:46:57 -070048 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
buzbeeb48819d2013-09-14 16:15:25 -070060 DCHECK(!insn->flags.use_def_invalid);
61 insn->u.m.use_mask = insn->u.m.def_mask = ENCODE_ALL;
Brian Carlstrom7940e442013-07-12 13:46:57 -070062 }
63 return insn;
64}
65
66/*
67 * The following are building blocks to construct low-level IRs with 0 - 4
68 * operands.
69 */
70inline LIR* Mir2Lir::NewLIR0(int opcode) {
buzbee409fe942013-10-11 10:49:56 -070071 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & NO_OPERAND))
Brian Carlstrom7940e442013-07-12 13:46:57 -070072 << 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
80inline LIR* Mir2Lir::NewLIR1(int opcode, int dest) {
buzbee409fe942013-10-11 10:49:56 -070081 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_UNARY_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -070082 << 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
90inline LIR* Mir2Lir::NewLIR2(int opcode, int dest, int src1) {
buzbee409fe942013-10-11 10:49:56 -070091 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_BINARY_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 << 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 Lupusoru614c2b42014-01-28 17:05:21 -0800100inline 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 Carlstrom7940e442013-07-12 13:46:57 -0700110inline LIR* Mir2Lir::NewLIR3(int opcode, int dest, int src1, int src2) {
buzbee409fe942013-10-11 10:49:56 -0700111 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_TERTIARY_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700112 << 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
120inline LIR* Mir2Lir::NewLIR4(int opcode, int dest, int src1, int src2, int info) {
buzbee409fe942013-10-11 10:49:56 -0700121 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_QUAD_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122 << 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
130inline LIR* Mir2Lir::NewLIR5(int opcode, int dest, int src1, int src2, int info1,
131 int info2) {
buzbee409fe942013-10-11 10:49:56 -0700132 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_QUIN_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 << 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 */
144inline void Mir2Lir::SetupRegMask(uint64_t* mask, int reg) {
buzbee091cc402014-03-31 10:14:40 -0700145 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 Carlstrom7940e442013-07-12 13:46:57 -0700148}
149
150/*
151 * Set up the proper fields in the resource mask
152 */
153inline void Mir2Lir::SetupResourceMasks(LIR* lir) {
154 int opcode = lir->opcode;
155
buzbee409fe942013-10-11 10:49:56 -0700156 if (IsPseudoLirOp(opcode)) {
157 if (opcode != kPseudoBarrier) {
158 lir->flags.fixup = kFixupLabel;
159 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160 return;
161 }
162
163 uint64_t flags = GetTargetInstFlags(opcode);
164
165 if (flags & NEEDS_FIXUP) {
buzbeeb48819d2013-09-14 16:15:25 -0700166 // Note: target-specific setup may specialize the fixup kind.
167 lir->flags.fixup = kFixupLabel;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168 }
169
170 /* Get the starting size of the instruction's template */
171 lir->flags.size = GetInsnSize(lir);
buzbeeb48819d2013-09-14 16:15:25 -0700172 estimated_native_code_size_ += lir->flags.size;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700173 /* 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) {
buzbeeb48819d2013-09-14 16:15:25 -0700184 lir->u.m.def_mask = lir->u.m.use_mask = ENCODE_ALL;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700185 return;
186 }
187
188 if (flags & REG_DEF0) {
buzbeeb48819d2013-09-14 16:15:25 -0700189 SetupRegMask(&lir->u.m.def_mask, lir->operands[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700190 }
191
192 if (flags & REG_DEF1) {
buzbeeb48819d2013-09-14 16:15:25 -0700193 SetupRegMask(&lir->u.m.def_mask, lir->operands[1]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700194 }
195
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800196 if (flags & REG_DEF2) {
197 SetupRegMask(&lir->u.m.def_mask, lir->operands[2]);
198 }
199
buzbeeb48819d2013-09-14 16:15:25 -0700200 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 Carlstrom7940e442013-07-12 13:46:57 -0700215
buzbee17189ac2013-11-08 11:07:02 -0800216 if (flags & REG_USE4) {
217 SetupRegMask(&lir->u.m.use_mask, lir->operands[4]);
218 }
219
Brian Carlstrom7940e442013-07-12 13:46:57 -0700220 if (flags & SETS_CCODES) {
buzbeeb48819d2013-09-14 16:15:25 -0700221 lir->u.m.def_mask |= ENCODE_CCODE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700222 }
223
224 if (flags & USES_CCODES) {
buzbeeb48819d2013-09-14 16:15:25 -0700225 lir->u.m.use_mask |= ENCODE_CCODE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700226 }
227
228 // Handle target-specific actions
buzbeeb48819d2013-09-14 16:15:25 -0700229 SetupTargetResourceMasks(lir, flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700230}
231
buzbee091cc402014-03-31 10:14:40 -0700232inline 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;
buzbeebd663de2013-09-10 15:41:31 -0700237}
238
Brian Carlstrom7940e442013-07-12 13:46:57 -0700239} // namespace art
240
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700241#endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_