buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #ifndef ART_SRC_COMPILER_COMPILERCODEGEN_H_ |
| 18 | #define ART_SRC_COMPILER_COMPILERCODEGEN_H_ |
| 19 | |
| 20 | #include "../CompilerIR.h" |
| 21 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 22 | namespace art { |
| 23 | |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 24 | |
| 25 | // Set to 1 to measure cost of suspend check |
| 26 | #define NO_SUSPEND 0 |
| 27 | |
| 28 | /* Bit flags describing the behavior of native opcodes (Arm/Mips/x86 combined) */ |
| 29 | enum OpFeatureFlags { |
| 30 | kIsBranch = 0, |
| 31 | kNoOperand, |
| 32 | kIsUnaryOp, |
| 33 | kIsBinaryOp, |
| 34 | kIsTertiaryOp, |
| 35 | kIsQuadOp, |
| 36 | kIsQuinOp, |
| 37 | kIsSextupleOp, |
| 38 | kIsIT, |
| 39 | kMemLoad, |
| 40 | kMemStore, |
| 41 | kPCRelFixup, // x86 FIXME: add NEEDS_FIXUP to instruction attributes |
| 42 | kRegDef0, |
| 43 | kRegDef1, |
| 44 | kRegDefA, |
| 45 | kRegDefD, |
| 46 | kRegDefFPCSList0, |
| 47 | kRegDefFPCSList2, |
| 48 | kRegDefList0, |
| 49 | kRegDefList1, |
| 50 | kRegDefList2, |
| 51 | kRegDefLR, |
| 52 | kRegDefSP, |
| 53 | kRegUse0, |
| 54 | kRegUse1, |
| 55 | kRegUse2, |
| 56 | kRegUse3, |
| 57 | kRegUse4, |
| 58 | kRegUseA, |
| 59 | kRegUseC, |
| 60 | kRegUseD, |
| 61 | kRegUseFPCSList0, |
| 62 | kRegUseFPCSList2, |
| 63 | kRegUseList0, |
| 64 | kRegUseList1, |
| 65 | kRegUseLR, |
| 66 | kRegUsePC, |
| 67 | kRegUseSP, |
| 68 | kSetsCCodes, |
| 69 | kUsesCCodes |
| 70 | }; |
| 71 | |
| 72 | #define IS_BINARY_OP (1ULL << kIsBinaryOp) |
| 73 | #define IS_BRANCH (1ULL << kIsBranch) |
| 74 | #define IS_IT (1ULL << kIsIT) |
| 75 | #define IS_LOAD (1ULL << kMemLoad) |
| 76 | #define IS_QUAD_OP (1ULL << kIsQuadOp) |
| 77 | #define IS_QUIN_OP (1ULL << kIsQuinOp) |
| 78 | #define IS_SEXTUPLE_OP (1ULL << kIsSextupleOp) |
| 79 | #define IS_STORE (1ULL << kMemStore) |
| 80 | #define IS_TERTIARY_OP (1ULL << kIsTertiaryOp) |
| 81 | #define IS_UNARY_OP (1ULL << kIsUnaryOp) |
| 82 | #define NEEDS_FIXUP (1ULL << kPCRelFixup) |
| 83 | #define NO_OPERAND (1ULL << kNoOperand) |
| 84 | #define REG_DEF0 (1ULL << kRegDef0) |
| 85 | #define REG_DEF1 (1ULL << kRegDef1) |
| 86 | #define REG_DEFA (1ULL << kRegDefA) |
| 87 | #define REG_DEFD (1ULL << kRegDefD) |
| 88 | #define REG_DEF_FPCS_LIST0 (1ULL << kRegDefFPCSList0) |
| 89 | #define REG_DEF_FPCS_LIST2 (1ULL << kRegDefFPCSList2) |
| 90 | #define REG_DEF_LIST0 (1ULL << kRegDefList0) |
| 91 | #define REG_DEF_LIST1 (1ULL << kRegDefList1) |
| 92 | #define REG_DEF_LR (1ULL << kRegDefLR) |
| 93 | #define REG_DEF_SP (1ULL << kRegDefSP) |
| 94 | #define REG_USE0 (1ULL << kRegUse0) |
| 95 | #define REG_USE1 (1ULL << kRegUse1) |
| 96 | #define REG_USE2 (1ULL << kRegUse2) |
| 97 | #define REG_USE3 (1ULL << kRegUse3) |
| 98 | #define REG_USE4 (1ULL << kRegUse4) |
| 99 | #define REG_USEA (1ULL << kRegUseA) |
| 100 | #define REG_USEC (1ULL << kRegUseC) |
| 101 | #define REG_USED (1ULL << kRegUseD) |
| 102 | #define REG_USE_FPCS_LIST0 (1ULL << kRegUseFPCSList0) |
| 103 | #define REG_USE_FPCS_LIST2 (1ULL << kRegUseFPCSList2) |
| 104 | #define REG_USE_LIST0 (1ULL << kRegUseList0) |
| 105 | #define REG_USE_LIST1 (1ULL << kRegUseList1) |
| 106 | #define REG_USE_LR (1ULL << kRegUseLR) |
| 107 | #define REG_USE_PC (1ULL << kRegUsePC) |
| 108 | #define REG_USE_SP (1ULL << kRegUseSP) |
| 109 | #define SETS_CCODES (1ULL << kSetsCCodes) |
| 110 | #define USES_CCODES (1ULL << kUsesCCodes) |
| 111 | |
| 112 | /* Common combo register usage patterns */ |
| 113 | #define REG_DEF01 (REG_DEF0 | REG_DEF1) |
| 114 | #define REG_DEF01_USE2 (REG_DEF0 | REG_DEF1 | REG_USE2) |
| 115 | #define REG_DEF0_USE01 (REG_DEF0 | REG_USE01) |
| 116 | #define REG_DEF0_USE0 (REG_DEF0 | REG_USE0) |
| 117 | #define REG_DEF0_USE12 (REG_DEF0 | REG_USE12) |
| 118 | #define REG_DEF0_USE1 (REG_DEF0 | REG_USE1) |
| 119 | #define REG_DEF0_USE2 (REG_DEF0 | REG_USE2) |
| 120 | #define REG_DEFAD_USEAD (REG_DEFAD_USEA | REG_USED) |
| 121 | #define REG_DEFAD_USEA (REG_DEFA_USEA | REG_DEFD) |
| 122 | #define REG_DEFA_USEA (REG_DEFA | REG_USEA) |
| 123 | #define REG_USE012 (REG_USE01 | REG_USE2) |
| 124 | #define REG_USE014 (REG_USE01 | REG_USE4) |
| 125 | #define REG_USE01 (REG_USE0 | REG_USE1) |
| 126 | #define REG_USE02 (REG_USE0 | REG_USE2) |
| 127 | #define REG_USE12 (REG_USE1 | REG_USE2) |
| 128 | #define REG_USE23 (REG_USE2 | REG_USE3) |
| 129 | |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 130 | LIR* rawLIR(CompilationUnit* cUnit, int dalvikOffset, int opcode, int op0 = 0, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 131 | int op1 = 0, int op2 = 0, int op3 = 0, int op4 = 0, |
| 132 | LIR* target = NULL); |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 133 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 134 | int oatGetInsnSize(LIR* lir); |
| 135 | |
buzbee | 84fd693 | 2012-03-29 16:44:16 -0700 | [diff] [blame] | 136 | void genFusedLongCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir); |
| 137 | void genFusedFPCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 138 | bool gtBias, bool isDouble); |
| 139 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 140 | CallInfo* oatNewCallInfo(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 141 | InvokeType type, bool isRange); |
buzbee | 84fd693 | 2012-03-29 16:44:16 -0700 | [diff] [blame] | 142 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 143 | /* Lower middle-level IR to low-level IR for the whole method */ |
| 144 | void oatMethodMIR2LIR(CompilationUnit* cUnit); |
| 145 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 146 | /* Bitcode conversions */ |
| 147 | void oatMethodMIR2Bitcode(CompilationUnit* cUnit); |
| 148 | void oatMethodBitcode2LIR(CompilationUnit* cUnit); |
| 149 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 150 | /* Lower middle-level IR to low-level IR for the simple methods */ |
| 151 | void oatSpecialMIR2LIR(CompilationUnit* cUnit, SpecialCaseHandler specialCase ); |
| 152 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 153 | /* Assemble LIR into machine code */ |
| 154 | void oatAssembleLIR(CompilationUnit* cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 155 | AssemblerStatus oatAssembleInstructions(CompilationUnit* cUnit, |
| 156 | intptr_t startAddr); |
| 157 | void oatAssignOffsets(CompilationUnit* cUnit); |
| 158 | int oatAssignInsnOffsets(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 159 | |
| 160 | /* Implemented in the codegen/<target>/ArchUtility.c */ |
| 161 | void oatCodegenDump(CompilationUnit* cUnit); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 162 | void oatDumpPromotionMap(CompilationUnit* cUnit); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 163 | std::string buildInsnString(const char* fmt, LIR* lir, |
| 164 | unsigned char* baseAddr); |
| 165 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 166 | |
| 167 | /* Implemented in codegen/<target>/Ralloc.c */ |
| 168 | void oatSimpleRegAlloc(CompilationUnit* cUnit); |
| 169 | |
| 170 | /* Implemented in codegen/<target>/Thumb<version>Util.c */ |
| 171 | void oatInitializeRegAlloc(CompilationUnit* cUnit); |
| 172 | |
| 173 | /* Implemented in codegen/<target>/<target_variant>/ArchVariant.c */ |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 174 | InstructionSet oatInstructionSet(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * Implemented in codegen/<target>/<target_variant>/ArchVariant.c |
| 178 | * Architecture-specific initializations and checks |
| 179 | */ |
| 180 | bool oatArchVariantInit(void); |
| 181 | |
| 182 | /* Implemented in codegen/<target>/<target_variant>/ArchVariant.c */ |
| 183 | int oatTargetOptHint(int key); |
| 184 | |
| 185 | /* Implemented in codegen/<target>/<target_variant>/ArchVariant.c */ |
| 186 | void oatGenMemBarrier(CompilationUnit* cUnit, int barrierKind); |
| 187 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 188 | LIR* genRegMemCheck(CompilationUnit* cUnit, ConditionCode cCode, |
| 189 | int reg1, int base, int offset, ThrowKind kind); |
| 190 | LIR* opThreadMem(CompilationUnit* cUnit, OpKind op, int threadOffset); |
| 191 | LIR* opMem(CompilationUnit* cUnit, OpKind op, int rBase, int disp); |
| 192 | LIR* storeBaseIndexedDisp(CompilationUnit *cUnit, |
| 193 | int rBase, int rIndex, int scale, int displacement, |
| 194 | int rSrc, int rSrcHi, OpSize size, int sReg); |
| 195 | LIR* opRegMem(CompilationUnit *cUnit, OpKind op, int rDest, int rBase, int offset); |
| 196 | LIR* opCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1, |
| 197 | int src2, LIR* target); |
| 198 | void oatSetupRegMask(CompilationUnit* cUnit, u8* mask, int reg); |
| 199 | u8 oatGetRegMaskCommon(CompilationUnit* cUnit, int reg); |
| 200 | void setupTargetResourceMasks(CompilationUnit* cUnit, LIR* lir); |
| 201 | RegLocation genDivRem(CompilationUnit* cUnit, RegLocation rlDest, int regLo, int regHi, bool isDiv); |
| 202 | RegLocation genDivRemLit(CompilationUnit* cUnit, RegLocation rlDest, int regLo, int lit, bool isDiv); |
| 203 | void markGCCard(CompilationUnit* cUnit, int valReg, int tgtAddrReg); |
| 204 | bool genInlinedMinMaxInt(CompilationUnit *cUnit, CallInfo* info, bool isMin); |
| 205 | void opLea(CompilationUnit* cUnit, int rBase, int reg1, int reg2, int scale, int offset); |
| 206 | void opTlsCmp(CompilationUnit* cUnit, int offset, int val); |
| 207 | bool genInlinedSqrt(CompilationUnit* cUnit, CallInfo* info); |
| 208 | bool genInlinedCas32(CompilationUnit* cUnit, CallInfo* info, bool need_write_barrier); |
| 209 | LIR* opPcRelLoad(CompilationUnit* cUnit, int reg, LIR* target); |
| 210 | LIR* opVldm(CompilationUnit* cUnit, int rBase, int count); |
| 211 | LIR* opVstm(CompilationUnit* cUnit, int rBase, int count); |
| 212 | void genMultiplyByTwoBitMultiplier(CompilationUnit* cUnit, RegLocation rlSrc, |
| 213 | RegLocation rlResult, int lit, |
| 214 | int firstBit, int secondBit); |
| 215 | RegLocation inlineTarget(CompilationUnit* cUnit, CallInfo* info); |
| 216 | RegLocation inlineTargetWide(CompilationUnit* cUnit, CallInfo* info); |
| 217 | void genDivZeroCheck(CompilationUnit* cUnit, int regLo, int regHi); |
| 218 | LIR* genImmedCheck(CompilationUnit* cUnit, ConditionCode cCode, |
| 219 | int reg, int immVal, ThrowKind kind); |
| 220 | LIR* opTestSuspend(CompilationUnit* cUnit, LIR* target); |
| 221 | LIR* opDecAndBranch(CompilationUnit* cUnit, ConditionCode cCode, int reg, LIR* target); |
| 222 | LIR* opIT(CompilationUnit* cUnit, ArmConditionCode cond, const char* guide); |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 223 | uint64_t getPCUseDefEncoding(); |
| 224 | uint64_t getRegMaskCommon(CompilationUnit* cUnit, int reg); |
buzbee | f0504cd | 2012-11-13 16:31:10 -0800 | [diff] [blame] | 225 | int s2d(int lowReg, int highReg); |
| 226 | bool fpReg(int reg); |
| 227 | bool singleReg(int reg); |
| 228 | bool doubleReg(int reg); |
| 229 | uint32_t fpRegMask(); |
| 230 | bool sameRegType(int reg1, int reg2); |
| 231 | int targetReg(SpecialTargetRegister reg); |
| 232 | RegLocation locCReturn(); |
| 233 | RegLocation locCReturnWide(); |
| 234 | RegLocation locCReturnFloat(); |
| 235 | RegLocation locCReturnDouble(); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 236 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 237 | } // namespace art |
| 238 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 239 | #endif // ART_SRC_COMPILER_COMPILERCODEGEN_H_ |