blob: 568a3888b52d5488b8d4ead07dbedc29e70c19c2 [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
17/*
18 * This file contains register alloction support and is intended to be
19 * included by:
20 *
21 * Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 */
24
25#include "../../CompilerIR.h"
26
27namespace art {
28
29#if defined(_CODEGEN_C)
buzbee408ad162012-06-06 16:45:18 -070030bool genAddLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeee88dfbf2012-03-05 11:19:57 -080031 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070032bool genSubLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeee88dfbf2012-03-05 11:19:57 -080033 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070034bool genAndLong(CompilationUnit* cUnit, RegLocation rlDest,
Ian Rogers7caad772012-03-30 01:07:54 -070035 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070036bool genOrLong(CompilationUnit* cUnit, RegLocation rlDest,
Ian Rogers7caad772012-03-30 01:07:54 -070037 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070038bool genXorLong(CompilationUnit* cUnit, RegLocation rlDest,
Ian Rogers7caad772012-03-30 01:07:54 -070039 RegLocation rlSrc1, RegLocation rlSrc2);
buzbee408ad162012-06-06 16:45:18 -070040bool genNegLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbeee88dfbf2012-03-05 11:19:57 -080041 RegLocation rlSrc);
42LIR *opRegImm(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int value);
43LIR *opRegReg(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int rSrc2);
44LIR* opCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1,
45 int src2, LIR* target);
46LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg,
47 int checkValue, LIR* target);
48
Ian Rogers96ab4202012-03-05 19:51:02 -080049/* Forward declaration of the portable versions due to circular dependency */
buzbee408ad162012-06-06 16:45:18 -070050bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbeee88dfbf2012-03-05 11:19:57 -080051 RegLocation rlDest, RegLocation rlSrc1,
52 RegLocation rlSrc2);
53
buzbee408ad162012-06-06 16:45:18 -070054bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbeee88dfbf2012-03-05 11:19:57 -080055 RegLocation rlDest, RegLocation rlSrc1,
56 RegLocation rlSrc2);
57
buzbee408ad162012-06-06 16:45:18 -070058bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode,
59 RegLocation rlDest, RegLocation rlSrc);
buzbeee88dfbf2012-03-05 11:19:57 -080060
61int loadHelper(CompilationUnit* cUnit, int offset);
buzbeee88dfbf2012-03-05 11:19:57 -080062LIR* loadConstant(CompilationUnit* cUnit, int reg, int immVal);
63void opRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi,
64 int srcLo, int srcHi);
65LIR* opRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
66void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
67 RegLocation rlFree);
68
69
70/*
71 * Return most flexible allowed register class based on size.
72 * Bug: 2813841
73 * Must use a core register for data types narrower than word (due
74 * to possible unaligned load/store.
75 */
76inline RegisterClass oatRegClassBySize(OpSize size)
77{
Bill Buzbeea114add2012-05-03 15:00:40 -070078 return (size == kUnsignedHalf ||
79 size == kSignedHalf ||
80 size == kUnsignedByte ||
81 size == kSignedByte ) ? kCoreReg : kAnyReg;
buzbeee88dfbf2012-03-05 11:19:57 -080082}
83
84/*
85 * Construct an s4 from two consecutive half-words of switch data.
86 * This needs to check endianness because the DEX optimizer only swaps
87 * half-words in instruction stream.
88 *
89 * "switchData" must be 32-bit aligned.
90 */
91#if __BYTE_ORDER == __LITTLE_ENDIAN
92inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070093 return *(s4*) switchData;
buzbeee88dfbf2012-03-05 11:19:57 -080094}
95#else
96inline s4 s4FromSwitchData(const void* switchData) {
Bill Buzbeea114add2012-05-03 15:00:40 -070097 u2* data = switchData;
98 return data[0] | (((s4) data[1]) << 16);
buzbeee88dfbf2012-03-05 11:19:57 -080099}
100#endif
101
102#endif
103
104extern void oatSetupResourceMasks(LIR* lir);
105
Bill Buzbeea114add2012-05-03 15:00:40 -0700106extern LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc);
buzbeee88dfbf2012-03-05 11:19:57 -0800107
108} // namespace art