blob: 76f7c4a6d606e768769c8708643100a8d1347a54 [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -08001/*
2 * Copyright (C) 2011 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
17/*
18 * This file contains x86-specific codegen factory support.
19 * It is included by
20 *
21 * Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 */
24
25namespace art {
26
27bool genAddLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest,
28 RegLocation rlSrc1, RegLocation rlSrc2)
29{
30 UNIMPLEMENTED(WARNING) << "genAddLong";
31#if 0
32 rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg);
33 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
34 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
35 /*
36 * [v1 v0] = [a1 a0] + [a3 a2];
37 * addu v0,a2,a0
38 * addu t1,a3,a1
39 * sltu v1,v0,a2
40 * addu v1,v1,t1
41 */
42
43 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc2.lowReg, rlSrc1.lowReg);
44 int tReg = oatAllocTemp(cUnit);
45 opRegRegReg(cUnit, kOpAdd, tReg, rlSrc2.highReg, rlSrc1.highReg);
46 newLIR3(cUnit, kMipsSltu, rlResult.highReg, rlResult.lowReg, rlSrc2.lowReg);
47 opRegRegReg(cUnit, kOpAdd, rlResult.highReg, rlResult.highReg, tReg);
48 oatFreeTemp(cUnit, tReg);
49 storeValueWide(cUnit, rlDest, rlResult);
50#endif
51 return false;
52}
53
54bool genSubLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest,
55 RegLocation rlSrc1, RegLocation rlSrc2)
56{
57 UNIMPLEMENTED(WARNING) << "genSubLong";
58#if 0
59 rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg);
60 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
61 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
62 /*
63 * [v1 v0] = [a1 a0] - [a3 a2];
64 * subu v0,a0,a2
65 * subu v1,a1,a3
66 * sltu t1,a0,v0
67 * subu v1,v1,t1
68 */
69
70 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg);
71 opRegRegReg(cUnit, kOpSub, rlResult.highReg, rlSrc1.highReg, rlSrc2.highReg);
72 int tReg = oatAllocTemp(cUnit);
73 newLIR3(cUnit, kMipsSltu, tReg, rlSrc1.lowReg, rlResult.lowReg);
74 opRegRegReg(cUnit, kOpSub, rlResult.highReg, rlResult.highReg, tReg);
75 oatFreeTemp(cUnit, tReg);
76 storeValueWide(cUnit, rlDest, rlResult);
77#endif
78 return false;
79}
80
81bool genNegLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest,
82 RegLocation rlSrc)
83{
84 UNIMPLEMENTED(WARNING) << "genNegLong";
85#if 0
86 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
87 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
88 /*
89 * [v1 v0] = -[a1 a0]
90 * negu v0,a0
91 * negu v1,a1
92 * sltu t1,r_zero
93 * subu v1,v1,t1
94 */
95
96 opRegReg(cUnit, kOpNeg, rlResult.lowReg, rlSrc.lowReg);
97 opRegReg(cUnit, kOpNeg, rlResult.highReg, rlSrc.highReg);
98 int tReg = oatAllocTemp(cUnit);
99 newLIR3(cUnit, kMipsSltu, tReg, r_ZERO, rlResult.lowReg);
100 opRegRegReg(cUnit, kOpSub, rlResult.highReg, rlResult.highReg, tReg);
101 oatFreeTemp(cUnit, tReg);
102 storeValueWide(cUnit, rlDest, rlResult);
103#endif
104 return false;
105}
106
107void genDebuggerUpdate(CompilationUnit* cUnit, int32_t offset);
108
109/*
110 * In the Arm code a it is typical to use the link register
111 * to hold the target address. However, for Mips we must
112 * ensure that all branch instructions can be restarted if
113 * there is a trap in the shadow. Allocate a temp register.
114 */
115int loadHelper(CompilationUnit* cUnit, int offset)
116{
117 int tReg = oatAllocTemp(cUnit);
118 loadWordDisp(cUnit, rSELF, offset, tReg);
119 return tReg;
120}
121
122void spillCoreRegs(CompilationUnit* cUnit)
123{
124 if (cUnit->numCoreSpills == 0) {
125 return;
126 }
127 UNIMPLEMENTED(WARNING) << "spillCoreRegs";
128#if 0
129 uint32_t mask = cUnit->coreSpillMask;
130 int offset = cUnit->numCoreSpills * 4;
131 opRegImm(cUnit, kOpSub, rSP, offset);
132 for (int reg = 0; mask; mask >>= 1, reg++) {
133 if (mask & 0x1) {
134 offset -= 4;
135 storeWordDisp(cUnit, rSP, offset, reg);
136 }
137 }
138#endif
139}
140
141void unSpillCoreRegs(CompilationUnit* cUnit)
142{
143 if (cUnit->numCoreSpills == 0) {
144 return;
145 }
146 UNIMPLEMENTED(WARNING) << "unSpillCoreRegs";
147#if 0
148 uint32_t mask = cUnit->coreSpillMask;
149 int offset = cUnit->frameSize;
150 for (int reg = 0; mask; mask >>= 1, reg++) {
151 if (mask & 0x1) {
152 offset -= 4;
153 loadWordDisp(cUnit, rSP, offset, reg);
154 }
155 }
156 opRegImm(cUnit, kOpAdd, rSP, cUnit->frameSize);
157#endif
158}
159
160void genEntrySequence(CompilationUnit* cUnit, BasicBlock* bb)
161{
162 UNIMPLEMENTED(WARNING) << "genEntrySequence";
163#if 0
164 int spillCount = cUnit->numCoreSpills + cUnit->numFPSpills;
165 /*
166 * On entry, rARG0, rARG1, rARG2 & rARG3 are live. Let the register
167 * allocation mechanism know so it doesn't try to use any of them when
168 * expanding the frame or flushing. This leaves the utility
169 * code with a single temp: r12. This should be enough.
170 */
171 oatLockTemp(cUnit, rARG0);
172 oatLockTemp(cUnit, rARG1);
173 oatLockTemp(cUnit, rARG2);
174 oatLockTemp(cUnit, rARG3);
175
176 /*
177 * We can safely skip the stack overflow check if we're
178 * a leaf *and* our frame size < fudge factor.
179 */
180 bool skipOverflowCheck = ((cUnit->attrs & METHOD_IS_LEAF) &&
181 ((size_t)cUnit->frameSize <
182 Thread::kStackOverflowReservedBytes));
183 newLIR0(cUnit, kPseudoMethodEntry);
184 int checkReg = oatAllocTemp(cUnit);
185 int newSP = oatAllocTemp(cUnit);
186 if (!skipOverflowCheck) {
187 /* Load stack limit */
188 loadWordDisp(cUnit, rSELF,
189 Thread::StackEndOffset().Int32Value(), checkReg);
190 }
191 /* Spill core callee saves */
192 spillCoreRegs(cUnit);
193 /* NOTE: promotion of FP regs currently unsupported, thus no FP spill */
194 DCHECK_EQ(cUnit->numFPSpills, 0);
195 if (!skipOverflowCheck) {
196 opRegRegImm(cUnit, kOpSub, newSP, rSP,
197 cUnit->frameSize - (spillCount * 4));
198 genRegRegCheck(cUnit, kCondCc, newSP, checkReg, NULL,
199 kThrowStackOverflow);
200 opRegCopy(cUnit, rSP, newSP); // Establish stack
201 } else {
202 opRegImm(cUnit, kOpSub, rSP,
203 cUnit->frameSize - (spillCount * 4));
204 }
205 storeBaseDisp(cUnit, rSP, 0, rARG0, kWord);
206 flushIns(cUnit);
207
208 if (cUnit->genDebugger) {
209 // Refresh update debugger callout
210 loadWordDisp(cUnit, rSELF,
211 OFFSETOF_MEMBER(Thread, pUpdateDebuggerFromCode), rSUSPEND);
212 genDebuggerUpdate(cUnit, DEBUGGER_METHOD_ENTRY);
213 }
214
215 oatFreeTemp(cUnit, rARG0);
216 oatFreeTemp(cUnit, rARG1);
217 oatFreeTemp(cUnit, rARG2);
218 oatFreeTemp(cUnit, rARG3);
219#endif
220}
221
222void genExitSequence(CompilationUnit* cUnit, BasicBlock* bb)
223{
224 UNIMPLEMENTED(WARNING) << "genExitSequence";
225#if 0
226 /*
227 * In the exit path, rRET0/rRET1 are live - make sure they aren't
228 * allocated by the register utilities as temps.
229 */
230 oatLockTemp(cUnit, rRET0);
231 oatLockTemp(cUnit, rRET1);
232
233 newLIR0(cUnit, kPseudoMethodExit);
234 /* If we're compiling for the debugger, generate an update callout */
235 if (cUnit->genDebugger) {
236 genDebuggerUpdate(cUnit, DEBUGGER_METHOD_EXIT);
237 }
238 unSpillCoreRegs(cUnit);
239 opReg(cUnit, kOpBx, r_RA);
240#endif
241}
242
243/*
244 * Nop any unconditional branches that go to the next instruction.
245 * Note: new redundant branches may be inserted later, and we'll
246 * use a check in final instruction assembly to nop those out.
247 */
248void removeRedundantBranches(CompilationUnit* cUnit)
249{
250 UNIMPLEMENTED(WARNING) << "removeRedundantBranches";
251#if 0
252 LIR* thisLIR;
253
254 for (thisLIR = (LIR*) cUnit->firstLIRInsn;
255 thisLIR != (LIR*) cUnit->lastLIRInsn;
256 thisLIR = NEXT_LIR(thisLIR)) {
257
258 /* Branch to the next instruction */
259 if (thisLIR->opcode == kMipsB) {
260 LIR* nextLIR = thisLIR;
261
262 while (true) {
263 nextLIR = NEXT_LIR(nextLIR);
264
265 /*
266 * Is the branch target the next instruction?
267 */
268 if (nextLIR == (LIR*) thisLIR->target) {
269 thisLIR->flags.isNop = true;
270 break;
271 }
272
273 /*
274 * Found real useful stuff between the branch and the target.
275 * Need to explicitly check the lastLIRInsn here because it
276 * might be the last real instruction.
277 */
278 if (!isPseudoOpcode(nextLIR->opcode) ||
279 (nextLIR = (LIR*) cUnit->lastLIRInsn))
280 break;
281 }
282 }
283 }
284#endif
285}
286
287
288/* Common initialization routine for an architecture family */
289bool oatArchInit()
290{
291 int i;
292
293 for (i = 0; i < kX86Last; i++) {
294 if (EncodingMap[i].opcode != i) {
295 LOG(FATAL) << "Encoding order for " << EncodingMap[i].name <<
296 " is wrong: expecting " << i << ", seeing " <<
297 (int)EncodingMap[i].opcode;
298 }
299 }
300
301 return oatArchVariantInit();
302}
303
304} // namespace art