blob: 03efe03c6ac5db14123d699e422f26626d422dd6 [file] [log] [blame]
buzbeee3acd072012-02-25 17:03:10 -08001/*
2 * Copyright (C) 2012 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
buzbeeb046e162012-10-30 15:48:42 -070017/* This file contains register alloction support */
buzbeee3acd072012-02-25 17:03:10 -080018
19#include "../../CompilerIR.h"
20
21namespace art {
22
23#if defined(_CODEGEN_C)
buzbee408ad162012-06-06 16:45:18 -070024bool genAddLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeec5159d52012-03-03 11:48:39 -080025 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070026bool genSubLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeec5159d52012-03-03 11:48:39 -080027 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070028bool genNegLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeec5159d52012-03-03 11:48:39 -080029 RegLocation rlSrc);
buzbee5de34942012-03-01 14:51:57 -080030LIR *opRegImm(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int value);
31LIR *opRegReg(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int rSrc2);
buzbee82488f52012-03-02 08:20:26 -080032LIR* opCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1,
33 int src2, LIR* target);
34LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg,
35 int checkValue, LIR* target);
buzbeee3acd072012-02-25 17:03:10 -080036
buzbee5de34942012-03-01 14:51:57 -080037/* Forward declaraton the portable versions due to circular dependency */
buzbee408ad162012-06-06 16:45:18 -070038bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbeee3acd072012-02-25 17:03:10 -080039 RegLocation rlDest, RegLocation rlSrc1,
40 RegLocation rlSrc2);
41
buzbee408ad162012-06-06 16:45:18 -070042bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbeee3acd072012-02-25 17:03:10 -080043 RegLocation rlDest, RegLocation rlSrc1,
44 RegLocation rlSrc2);
45
buzbee408ad162012-06-06 16:45:18 -070046bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode,
47 RegLocation rlDest, RegLocation rlSrc);
buzbee5de34942012-03-01 14:51:57 -080048
buzbee5de34942012-03-01 14:51:57 -080049int loadHelper(CompilationUnit* cUnit, int offset);
buzbee5de34942012-03-01 14:51:57 -080050LIR* loadConstant(CompilationUnit* cUnit, int reg, int immVal);
buzbee82488f52012-03-02 08:20:26 -080051void opRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi,
52 int srcLo, int srcHi);
53LIR* opRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
buzbee5de34942012-03-01 14:51:57 -080054void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
55 RegLocation rlFree);
56
57
58/*
59 * Return most flexible allowed register class based on size.
60 * Bug: 2813841
61 * Must use a core register for data types narrower than word (due
62 * to possible unaligned load/store.
63 */
Elliott Hughes74847412012-06-20 18:10:21 -070064inline RegisterClass oatRegClassBySize(OpSize size) {
Bill Buzbeea114add2012-05-03 15:00:40 -070065 return (size == kUnsignedHalf ||
66 size == kSignedHalf ||
67 size == kUnsignedByte ||
Elliott Hughes74847412012-06-20 18:10:21 -070068 size == kSignedByte) ? kCoreReg : kAnyReg;
buzbee5de34942012-03-01 14:51:57 -080069}
70
71/*
72 * Construct an s4 from two consecutive half-words of switch data.
73 * This needs to check endianness because the DEX optimizer only swaps
74 * half-words in instruction stream.
75 *
76 * "switchData" must be 32-bit aligned.
77 */
78#if __BYTE_ORDER == __LITTLE_ENDIAN
79inline s4 s4FromSwitchData(const void* switchData) {
Elliott Hughes74847412012-06-20 18:10:21 -070080 return *reinterpret_cast<const s4*>(switchData);
buzbee5de34942012-03-01 14:51:57 -080081}
82#else
83inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070084 u2* data = switchData;
85 return data[0] | (((s4) data[1]) << 16);
buzbee5de34942012-03-01 14:51:57 -080086}
87#endif
buzbeee3acd072012-02-25 17:03:10 -080088
89#endif
90
buzbeeb046e162012-10-30 15:48:42 -070091extern void oatSetupResourceMasks(CompilationUnit* cUnit, LIR* lir);
buzbeee3acd072012-02-25 17:03:10 -080092
Bill Buzbeea114add2012-05-03 15:00:40 -070093extern LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc);
buzbeee3acd072012-02-25 17:03:10 -080094
buzbeeb046e162012-10-30 15:48:42 -070095bool genAddLong(CompilationUnit* cUnit, RegLocation rlDest,
96 RegLocation rlSrc1, RegLocation rlSrc2);
97bool genSubLong(CompilationUnit* cUnit, RegLocation rlDest,
98 RegLocation rlSrc1, RegLocation rlSrc2);
99bool genAndLong(CompilationUnit* cUnit, RegLocation rlDest,
100 RegLocation rlSrc1, RegLocation rlSrc2);
101bool genOrLong(CompilationUnit* cUnit, RegLocation rlDest,
102 RegLocation rlSrc1, RegLocation rlSrc2);
103bool genXorLong(CompilationUnit* cUnit, RegLocation rlDest,
104 RegLocation rlSrc1, RegLocation rlSrc2);
105
buzbeee3acd072012-02-25 17:03:10 -0800106} // namespace art