buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 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 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 17 | /* This file contains register alloction support. */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 18 | |
| 19 | #include "../../CompilerIR.h" |
| 20 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 21 | namespace art { |
| 22 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 23 | #if defined(_CODEGEN_C) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 24 | LIR *opRegImm(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int value); |
| 25 | LIR *opRegReg(CompilationUnit* cUnit, OpKind op, int rDestSrc1, int rSrc2); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 26 | LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg, |
| 27 | int checkValue, LIR* target); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 28 | bool genNegLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 29 | RegLocation rlSrc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 30 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 31 | /* Forward declaraton the portable versions due to circular dependency */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 32 | bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 33 | RegLocation rlDest, RegLocation rlSrc1, |
| 34 | RegLocation rlSrc2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 35 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 36 | bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 37 | RegLocation rlDest, RegLocation rlSrc1, |
| 38 | RegLocation rlSrc2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 39 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 40 | bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode, |
| 41 | RegLocation rlDest, RegLocation rlSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 42 | |
| 43 | ArmConditionCode oatArmConditionEncoding(ConditionCode code); |
| 44 | |
| 45 | int loadHelper(CompilationUnit* cUnit, int offset); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 46 | LIR* loadConstant(CompilationUnit* cUnit, int reg, int immVal); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 47 | void opRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi, |
| 48 | int srcLo, int srcHi); |
| 49 | LIR* opRegCopy(CompilationUnit* cUnit, int rDest, int rSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 50 | void 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 | */ |
| 60 | inline RegisterClass oatRegClassBySize(OpSize size) |
| 61 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 62 | return (size == kUnsignedHalf || |
| 63 | size == kSignedHalf || |
| 64 | size == kUnsignedByte || |
| 65 | size == kSignedByte ) ? kCoreReg : kAnyReg; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 66 | } |
| 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 |
| 76 | inline s4 s4FromSwitchData(const void* switchData) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 77 | return *(s4*) switchData; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 78 | } |
| 79 | #else |
| 80 | inline s4 s4FromSwitchData(const void* switchData) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 81 | u2* data = switchData; |
| 82 | return data[0] | (((s4) data[1]) << 16); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 83 | } |
| 84 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 85 | |
| 86 | #endif |
| 87 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 88 | extern void oatSetupResourceMasks(CompilationUnit* cUnit, LIR* lir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 89 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 90 | extern LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc); |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 91 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 92 | bool genAddLong(CompilationUnit* cUnit, RegLocation rlDest, |
| 93 | RegLocation rlSrc1, RegLocation rlSrc2); |
| 94 | bool genSubLong(CompilationUnit* cUnit, RegLocation rlDest, |
| 95 | RegLocation rlSrc1, RegLocation rlSrc2); |
| 96 | bool genAndLong(CompilationUnit* cUnit, RegLocation rlDest, |
| 97 | RegLocation rlSrc1, RegLocation rlSrc2); |
| 98 | bool genOrLong(CompilationUnit* cUnit, RegLocation rlDest, |
| 99 | RegLocation rlSrc1, RegLocation rlSrc2); |
| 100 | bool genXorLong(CompilationUnit* cUnit, RegLocation rlDest, |
| 101 | RegLocation rlSrc1, RegLocation rlSrc2); |
| 102 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 103 | } // namespace art |