blob: 3755e500aaf01392d13e9d23f269c5fa97aa97ca [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -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 */
buzbeee88dfbf2012-03-05 11:19:57 -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,
buzbeee88dfbf2012-03-05 11:19:57 -080025 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070026bool genSubLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeee88dfbf2012-03-05 11:19:57 -080027 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070028bool genAndLong(CompilationUnit* cUnit, RegLocation rlDest,
Ian Rogers7caad772012-03-30 01:07:54 -070029 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070030bool genOrLong(CompilationUnit* cUnit, RegLocation rlDest,
Ian Rogers7caad772012-03-30 01:07:54 -070031 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070032bool genXorLong(CompilationUnit* cUnit, RegLocation rlDest,
Ian Rogers7caad772012-03-30 01:07:54 -070033 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070034bool genNegLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeee88dfbf2012-03-05 11:19:57 -080035 RegLocation rlSrc);
36LIR *opRegImm(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int value);
37LIR *opRegReg(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int rSrc2);
38LIR* opCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1,
39 int src2, LIR* target);
40LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg,
41 int checkValue, LIR* target);
42
Ian Rogers96ab4202012-03-05 19:51:02 -080043/* Forward declaration of the portable versions due to circular dependency */
buzbee408ad162012-06-06 16:45:18 -070044bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbeee88dfbf2012-03-05 11:19:57 -080045 RegLocation rlDest, RegLocation rlSrc1,
46 RegLocation rlSrc2);
47
buzbee408ad162012-06-06 16:45:18 -070048bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbeee88dfbf2012-03-05 11:19:57 -080049 RegLocation rlDest, RegLocation rlSrc1,
50 RegLocation rlSrc2);
51
buzbee408ad162012-06-06 16:45:18 -070052bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode,
53 RegLocation rlDest, RegLocation rlSrc);
buzbeee88dfbf2012-03-05 11:19:57 -080054
55int loadHelper(CompilationUnit* cUnit, int offset);
buzbeee88dfbf2012-03-05 11:19:57 -080056LIR* loadConstant(CompilationUnit* cUnit, int reg, int immVal);
57void opRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi,
58 int srcLo, int srcHi);
59LIR* opRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
60void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
61 RegLocation rlFree);
62
63
64/*
65 * Return most flexible allowed register class based on size.
66 * Bug: 2813841
67 * Must use a core register for data types narrower than word (due
68 * to possible unaligned load/store.
69 */
70inline RegisterClass oatRegClassBySize(OpSize size)
71{
Bill Buzbeea114add2012-05-03 15:00:40 -070072 return (size == kUnsignedHalf ||
73 size == kSignedHalf ||
74 size == kUnsignedByte ||
75 size == kSignedByte ) ? kCoreReg : kAnyReg;
buzbeee88dfbf2012-03-05 11:19:57 -080076}
77
78/*
79 * Construct an s4 from two consecutive half-words of switch data.
80 * This needs to check endianness because the DEX optimizer only swaps
81 * half-words in instruction stream.
82 *
83 * "switchData" must be 32-bit aligned.
84 */
85#if __BYTE_ORDER == __LITTLE_ENDIAN
86inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070087 return *(s4*) switchData;
buzbeee88dfbf2012-03-05 11:19:57 -080088}
89#else
90inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070091 u2* data = switchData;
92 return data[0] | (((s4) data[1]) << 16);
buzbeee88dfbf2012-03-05 11:19:57 -080093}
94#endif
95
96#endif
97
buzbeeb046e162012-10-30 15:48:42 -070098extern void oatSetupResourceMasks(CompilationUnit* cUnit, LIR* lir);
buzbeee88dfbf2012-03-05 11:19:57 -080099
Bill Buzbeea114add2012-05-03 15:00:40 -0700100extern LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc);
buzbeee88dfbf2012-03-05 11:19:57 -0800101
102} // namespace art