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