blob: 0890c15bab159381889429434e0cd6d678e0c136 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
buzbee5de34942012-03-01 14:51:57 -08002 * Copyright (C) 2012 The Android Open Source Project
buzbee67bf8852011-08-17 17:51:35 -07003 *
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. */
buzbee67bf8852011-08-17 17:51:35 -070018
19#include "../../CompilerIR.h"
20
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080021namespace art {
22
buzbee67bf8852011-08-17 17:51:35 -070023#if defined(_CODEGEN_C)
buzbee31a4a6f2012-02-28 15:36:15 -080024LIR *opRegImm(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int value);
25LIR *opRegReg(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int rSrc2);
buzbee82488f52012-03-02 08:20:26 -080026LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg,
27 int checkValue, LIR* target);
buzbee408ad162012-06-06 16:45:18 -070028bool genNegLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeec5159d52012-03-03 11:48:39 -080029 RegLocation rlSrc);
buzbee67bf8852011-08-17 17:51:35 -070030
buzbee31a4a6f2012-02-28 15:36:15 -080031/* Forward declaraton the portable versions due to circular dependency */
buzbee408ad162012-06-06 16:45:18 -070032bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode,
Bill Buzbeea114add2012-05-03 15:00:40 -070033 RegLocation rlDest, RegLocation rlSrc1,
34 RegLocation rlSrc2);
buzbee67bf8852011-08-17 17:51:35 -070035
buzbee408ad162012-06-06 16:45:18 -070036bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode,
Bill Buzbeea114add2012-05-03 15:00:40 -070037 RegLocation rlDest, RegLocation rlSrc1,
38 RegLocation rlSrc2);
buzbee67bf8852011-08-17 17:51:35 -070039
buzbee408ad162012-06-06 16:45:18 -070040bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode,
41 RegLocation rlDest, RegLocation rlSrc);
buzbee31a4a6f2012-02-28 15:36:15 -080042
43ArmConditionCode oatArmConditionEncoding(ConditionCode code);
44
45int loadHelper(CompilationUnit* cUnit, int offset);
buzbee31a4a6f2012-02-28 15:36:15 -080046LIR* loadConstant(CompilationUnit* cUnit, int reg, int immVal);
buzbee82488f52012-03-02 08:20:26 -080047void opRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi,
48 int srcLo, int srcHi);
49LIR* opRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
buzbee31a4a6f2012-02-28 15:36:15 -080050void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
51 RegLocation rlFree);
52
53
54/*
55 * Return most flexible allowed register class based on size.
56 * Bug: 2813841
57 * Must use a core register for data types narrower than word (due
58 * to possible unaligned load/store.
59 */
60inline RegisterClass oatRegClassBySize(OpSize size)
61{
Bill Buzbeea114add2012-05-03 15:00:40 -070062 return (size == kUnsignedHalf ||
63 size == kSignedHalf ||
64 size == kUnsignedByte ||
65 size == kSignedByte ) ? kCoreReg : kAnyReg;
buzbee31a4a6f2012-02-28 15:36:15 -080066}
67
68/*
69 * Construct an s4 from two consecutive half-words of switch data.
70 * This needs to check endianness because the DEX optimizer only swaps
71 * half-words in instruction stream.
72 *
73 * "switchData" must be 32-bit aligned.
74 */
75#if __BYTE_ORDER == __LITTLE_ENDIAN
76inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070077 return *(s4*) switchData;
buzbee31a4a6f2012-02-28 15:36:15 -080078}
79#else
80inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070081 u2* data = switchData;
82 return data[0] | (((s4) data[1]) << 16);
buzbee31a4a6f2012-02-28 15:36:15 -080083}
84#endif
buzbee67bf8852011-08-17 17:51:35 -070085
86#endif
87
buzbeeb046e162012-10-30 15:48:42 -070088extern void oatSetupResourceMasks(CompilationUnit* cUnit, LIR* lir);
buzbee67bf8852011-08-17 17:51:35 -070089
Bill Buzbeea114add2012-05-03 15:00:40 -070090extern LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc);
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080091
buzbeeb046e162012-10-30 15:48:42 -070092bool genAddLong(CompilationUnit* cUnit, RegLocation rlDest,
93 RegLocation rlSrc1, RegLocation rlSrc2);
94bool genSubLong(CompilationUnit* cUnit, RegLocation rlDest,
95 RegLocation rlSrc1, RegLocation rlSrc2);
96bool genAndLong(CompilationUnit* cUnit, RegLocation rlDest,
97 RegLocation rlSrc1, RegLocation rlSrc2);
98bool genOrLong(CompilationUnit* cUnit, RegLocation rlDest,
99 RegLocation rlSrc1, RegLocation rlSrc2);
100bool genXorLong(CompilationUnit* cUnit, RegLocation rlDest,
101 RegLocation rlSrc1, RegLocation rlSrc2);
102
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800103} // namespace art