blob: f5d71c439d53d2b4d49416ad6478d116daeee434 [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";
30 p->SetIsLive(false);
31 p->SetSReg(INVALID_SREG);
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);
39 p->SetIsLive(false);
40 p->SetSReg(INVALID_SREG);
41 p->ResetDefBody();
42 }
Brian Carlstrom7940e442013-07-12 13:46:57 -070043 }
44 }
45}
46
buzbee0d829482013-10-11 15:24:55 -070047inline LIR* Mir2Lir::RawLIR(DexOffset dalvik_offset, int opcode, int op0,
Brian Carlstrom7940e442013-07-12 13:46:57 -070048 int op1, int op2, int op3, int op4, LIR* target) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000049 LIR* insn = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocLIR));
Brian Carlstrom7940e442013-07-12 13:46:57 -070050 insn->dalvik_offset = dalvik_offset;
51 insn->opcode = opcode;
52 insn->operands[0] = op0;
53 insn->operands[1] = op1;
54 insn->operands[2] = op2;
55 insn->operands[3] = op3;
56 insn->operands[4] = op4;
57 insn->target = target;
58 SetupResourceMasks(insn);
59 if ((opcode == kPseudoTargetLabel) || (opcode == kPseudoSafepointPC) ||
60 (opcode == kPseudoExportedPC)) {
61 // Always make labels scheduling barriers
buzbeeb48819d2013-09-14 16:15:25 -070062 DCHECK(!insn->flags.use_def_invalid);
63 insn->u.m.use_mask = insn->u.m.def_mask = ENCODE_ALL;
Brian Carlstrom7940e442013-07-12 13:46:57 -070064 }
65 return insn;
66}
67
68/*
69 * The following are building blocks to construct low-level IRs with 0 - 4
70 * operands.
71 */
72inline LIR* Mir2Lir::NewLIR0(int opcode) {
buzbee409fe942013-10-11 10:49:56 -070073 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & NO_OPERAND))
Brian Carlstrom7940e442013-07-12 13:46:57 -070074 << GetTargetInstName(opcode) << " " << opcode << " "
75 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
76 << current_dalvik_offset_;
77 LIR* insn = RawLIR(current_dalvik_offset_, opcode);
78 AppendLIR(insn);
79 return insn;
80}
81
82inline LIR* Mir2Lir::NewLIR1(int opcode, int dest) {
buzbee409fe942013-10-11 10:49:56 -070083 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_UNARY_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -070084 << GetTargetInstName(opcode) << " " << opcode << " "
85 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
86 << current_dalvik_offset_;
87 LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest);
88 AppendLIR(insn);
89 return insn;
90}
91
92inline LIR* Mir2Lir::NewLIR2(int opcode, int dest, int src1) {
buzbee409fe942013-10-11 10:49:56 -070093 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_BINARY_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 << GetTargetInstName(opcode) << " " << opcode << " "
95 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
96 << current_dalvik_offset_;
97 LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1);
98 AppendLIR(insn);
99 return insn;
100}
101
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800102inline LIR* Mir2Lir::NewLIR2NoDest(int opcode, int src, int info) {
103 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_UNARY_OP))
104 << GetTargetInstName(opcode) << " " << opcode << " "
105 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
106 << current_dalvik_offset_;
107 LIR* insn = RawLIR(current_dalvik_offset_, opcode, src, info);
108 AppendLIR(insn);
109 return insn;
110}
111
Brian Carlstrom7940e442013-07-12 13:46:57 -0700112inline LIR* Mir2Lir::NewLIR3(int opcode, int dest, int src1, int src2) {
buzbee409fe942013-10-11 10:49:56 -0700113 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_TERTIARY_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114 << GetTargetInstName(opcode) << " " << opcode << " "
115 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
116 << current_dalvik_offset_;
117 LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1, src2);
118 AppendLIR(insn);
119 return insn;
120}
121
122inline LIR* Mir2Lir::NewLIR4(int opcode, int dest, int src1, int src2, int info) {
buzbee409fe942013-10-11 10:49:56 -0700123 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_QUAD_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124 << GetTargetInstName(opcode) << " " << opcode << " "
125 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
126 << current_dalvik_offset_;
127 LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1, src2, info);
128 AppendLIR(insn);
129 return insn;
130}
131
132inline LIR* Mir2Lir::NewLIR5(int opcode, int dest, int src1, int src2, int info1,
133 int info2) {
buzbee409fe942013-10-11 10:49:56 -0700134 DCHECK(IsPseudoLirOp(opcode) || (GetTargetInstFlags(opcode) & IS_QUIN_OP))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700135 << GetTargetInstName(opcode) << " " << opcode << " "
136 << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " "
137 << current_dalvik_offset_;
138 LIR* insn = RawLIR(current_dalvik_offset_, opcode, dest, src1, src2, info1, info2);
139 AppendLIR(insn);
140 return insn;
141}
142
143/*
144 * Mark the corresponding bit(s).
145 */
146inline void Mir2Lir::SetupRegMask(uint64_t* mask, int reg) {
buzbee091cc402014-03-31 10:14:40 -0700147 DCHECK_EQ((reg & ~RegStorage::kRegValMask), 0);
148 DCHECK(reginfo_map_.Get(reg) != nullptr) << "No info for 0x" << reg;
149 *mask |= reginfo_map_.Get(reg)->DefUseMask();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150}
151
152/*
153 * Set up the proper fields in the resource mask
154 */
155inline void Mir2Lir::SetupResourceMasks(LIR* lir) {
156 int opcode = lir->opcode;
157
buzbee409fe942013-10-11 10:49:56 -0700158 if (IsPseudoLirOp(opcode)) {
159 if (opcode != kPseudoBarrier) {
160 lir->flags.fixup = kFixupLabel;
161 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 return;
163 }
164
165 uint64_t flags = GetTargetInstFlags(opcode);
166
167 if (flags & NEEDS_FIXUP) {
buzbeeb48819d2013-09-14 16:15:25 -0700168 // Note: target-specific setup may specialize the fixup kind.
169 lir->flags.fixup = kFixupLabel;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700170 }
171
172 /* Get the starting size of the instruction's template */
173 lir->flags.size = GetInsnSize(lir);
buzbeeb48819d2013-09-14 16:15:25 -0700174 estimated_native_code_size_ += lir->flags.size;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700175 /* Set up the mask for resources that are updated */
176 if (flags & (IS_LOAD | IS_STORE)) {
177 /* Default to heap - will catch specialized classes later */
178 SetMemRefType(lir, flags & IS_LOAD, kHeapRef);
179 }
180
181 /*
182 * Conservatively assume the branch here will call out a function that in
183 * turn will trash everything.
184 */
185 if (flags & IS_BRANCH) {
buzbeeb48819d2013-09-14 16:15:25 -0700186 lir->u.m.def_mask = lir->u.m.use_mask = ENCODE_ALL;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700187 return;
188 }
189
190 if (flags & REG_DEF0) {
buzbeeb48819d2013-09-14 16:15:25 -0700191 SetupRegMask(&lir->u.m.def_mask, lir->operands[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700192 }
193
194 if (flags & REG_DEF1) {
buzbeeb48819d2013-09-14 16:15:25 -0700195 SetupRegMask(&lir->u.m.def_mask, lir->operands[1]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196 }
197
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800198 if (flags & REG_DEF2) {
199 SetupRegMask(&lir->u.m.def_mask, lir->operands[2]);
200 }
201
buzbeeb48819d2013-09-14 16:15:25 -0700202 if (flags & REG_USE0) {
203 SetupRegMask(&lir->u.m.use_mask, lir->operands[0]);
204 }
205
206 if (flags & REG_USE1) {
207 SetupRegMask(&lir->u.m.use_mask, lir->operands[1]);
208 }
209
210 if (flags & REG_USE2) {
211 SetupRegMask(&lir->u.m.use_mask, lir->operands[2]);
212 }
213
214 if (flags & REG_USE3) {
215 SetupRegMask(&lir->u.m.use_mask, lir->operands[3]);
216 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217
buzbee17189ac2013-11-08 11:07:02 -0800218 if (flags & REG_USE4) {
219 SetupRegMask(&lir->u.m.use_mask, lir->operands[4]);
220 }
221
Brian Carlstrom7940e442013-07-12 13:46:57 -0700222 if (flags & SETS_CCODES) {
buzbeeb48819d2013-09-14 16:15:25 -0700223 lir->u.m.def_mask |= ENCODE_CCODE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700224 }
225
226 if (flags & USES_CCODES) {
buzbeeb48819d2013-09-14 16:15:25 -0700227 lir->u.m.use_mask |= ENCODE_CCODE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228 }
229
230 // Handle target-specific actions
buzbeeb48819d2013-09-14 16:15:25 -0700231 SetupTargetResourceMasks(lir, flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232}
233
buzbee091cc402014-03-31 10:14:40 -0700234inline art::Mir2Lir::RegisterInfo* Mir2Lir::GetRegInfo(RegStorage reg) {
235 RegisterInfo* res = reg.IsPair() ? reginfo_map_.Get(reg.GetLowReg()) :
236 reginfo_map_.Get(reg.GetReg());
237 DCHECK(res != nullptr);
238 return res;
buzbeebd663de2013-09-10 15:41:31 -0700239}
240
Brian Carlstrom7940e442013-07-12 13:46:57 -0700241} // namespace art
242
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700243#endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_INL_H_