blob: 868e666b08c3b2139b833aa3b3d992fefeca0a77 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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 Hughes11d1b0c2012-01-23 16:57:47 -080022namespace art {
23
buzbeeec137432012-11-13 12:13:16 -080024
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) */
29enum 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
buzbeea2ebdd72012-03-04 14:57:06 -0800130LIR* rawLIR(CompilationUnit* cUnit, int dalvikOffset, int opcode, int op0 = 0,
Bill Buzbeea114add2012-05-03 15:00:40 -0700131 int op1 = 0, int op2 = 0, int op3 = 0, int op4 = 0,
132 LIR* target = NULL);
buzbeea2ebdd72012-03-04 14:57:06 -0800133
buzbeee88dfbf2012-03-05 11:19:57 -0800134int oatGetInsnSize(LIR* lir);
135
buzbee84fd6932012-03-29 16:44:16 -0700136void genFusedLongCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir);
137void genFusedFPCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir,
138 bool gtBias, bool isDouble);
139
buzbee6969d502012-06-15 16:40:31 -0700140CallInfo* oatNewCallInfo(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir,
141 InvokeType type, bool isRange);
buzbee84fd6932012-03-29 16:44:16 -0700142
buzbee67bf8852011-08-17 17:51:35 -0700143/* Lower middle-level IR to low-level IR for the whole method */
144void oatMethodMIR2LIR(CompilationUnit* cUnit);
145
buzbee2cfc6392012-05-07 14:51:40 -0700146/* Bitcode conversions */
147void oatMethodMIR2Bitcode(CompilationUnit* cUnit);
148void oatMethodBitcode2LIR(CompilationUnit* cUnit);
149
buzbee16da88c2012-03-20 10:38:17 -0700150/* Lower middle-level IR to low-level IR for the simple methods */
151void oatSpecialMIR2LIR(CompilationUnit* cUnit, SpecialCaseHandler specialCase );
152
buzbee67bf8852011-08-17 17:51:35 -0700153/* Assemble LIR into machine code */
154void oatAssembleLIR(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800155AssemblerStatus oatAssembleInstructions(CompilationUnit* cUnit,
156 intptr_t startAddr);
157void oatAssignOffsets(CompilationUnit* cUnit);
158int oatAssignInsnOffsets(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700159
160/* Implemented in the codegen/<target>/ArchUtility.c */
161void oatCodegenDump(CompilationUnit* cUnit);
buzbee67bc2362011-10-11 18:08:40 -0700162void oatDumpPromotionMap(CompilationUnit* cUnit);
buzbee5de34942012-03-01 14:51:57 -0800163std::string buildInsnString(const char* fmt, LIR* lir,
164 unsigned char* baseAddr);
165
buzbee67bf8852011-08-17 17:51:35 -0700166
167/* Implemented in codegen/<target>/Ralloc.c */
168void oatSimpleRegAlloc(CompilationUnit* cUnit);
169
170/* Implemented in codegen/<target>/Thumb<version>Util.c */
171void oatInitializeRegAlloc(CompilationUnit* cUnit);
172
173/* Implemented in codegen/<target>/<target_variant>/ArchVariant.c */
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800174InstructionSet oatInstructionSet();
buzbee67bf8852011-08-17 17:51:35 -0700175
176/*
177 * Implemented in codegen/<target>/<target_variant>/ArchVariant.c
178 * Architecture-specific initializations and checks
179 */
180bool oatArchVariantInit(void);
181
182/* Implemented in codegen/<target>/<target_variant>/ArchVariant.c */
183int oatTargetOptHint(int key);
184
185/* Implemented in codegen/<target>/<target_variant>/ArchVariant.c */
186void oatGenMemBarrier(CompilationUnit* cUnit, int barrierKind);
187
buzbeeb046e162012-10-30 15:48:42 -0700188LIR* genRegMemCheck(CompilationUnit* cUnit, ConditionCode cCode,
189 int reg1, int base, int offset, ThrowKind kind);
190LIR* opThreadMem(CompilationUnit* cUnit, OpKind op, int threadOffset);
191LIR* opMem(CompilationUnit* cUnit, OpKind op, int rBase, int disp);
192LIR* storeBaseIndexedDisp(CompilationUnit *cUnit,
193 int rBase, int rIndex, int scale, int displacement,
194 int rSrc, int rSrcHi, OpSize size, int sReg);
195LIR* opRegMem(CompilationUnit *cUnit, OpKind op, int rDest, int rBase, int offset);
196LIR* opCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1,
197 int src2, LIR* target);
198void oatSetupRegMask(CompilationUnit* cUnit, u8* mask, int reg);
199u8 oatGetRegMaskCommon(CompilationUnit* cUnit, int reg);
200void setupTargetResourceMasks(CompilationUnit* cUnit, LIR* lir);
201RegLocation genDivRem(CompilationUnit* cUnit, RegLocation rlDest, int regLo, int regHi, bool isDiv);
202RegLocation genDivRemLit(CompilationUnit* cUnit, RegLocation rlDest, int regLo, int lit, bool isDiv);
203void markGCCard(CompilationUnit* cUnit, int valReg, int tgtAddrReg);
204bool genInlinedMinMaxInt(CompilationUnit *cUnit, CallInfo* info, bool isMin);
205void opLea(CompilationUnit* cUnit, int rBase, int reg1, int reg2, int scale, int offset);
206void opTlsCmp(CompilationUnit* cUnit, int offset, int val);
207bool genInlinedSqrt(CompilationUnit* cUnit, CallInfo* info);
208bool genInlinedCas32(CompilationUnit* cUnit, CallInfo* info, bool need_write_barrier);
209LIR* opPcRelLoad(CompilationUnit* cUnit, int reg, LIR* target);
210LIR* opVldm(CompilationUnit* cUnit, int rBase, int count);
211LIR* opVstm(CompilationUnit* cUnit, int rBase, int count);
212void genMultiplyByTwoBitMultiplier(CompilationUnit* cUnit, RegLocation rlSrc,
213 RegLocation rlResult, int lit,
214 int firstBit, int secondBit);
215RegLocation inlineTarget(CompilationUnit* cUnit, CallInfo* info);
216RegLocation inlineTargetWide(CompilationUnit* cUnit, CallInfo* info);
217void genDivZeroCheck(CompilationUnit* cUnit, int regLo, int regHi);
218LIR* genImmedCheck(CompilationUnit* cUnit, ConditionCode cCode,
219 int reg, int immVal, ThrowKind kind);
220LIR* opTestSuspend(CompilationUnit* cUnit, LIR* target);
221LIR* opDecAndBranch(CompilationUnit* cUnit, ConditionCode cCode, int reg, LIR* target);
222LIR* opIT(CompilationUnit* cUnit, ArmConditionCode cond, const char* guide);
buzbeeec137432012-11-13 12:13:16 -0800223uint64_t getPCUseDefEncoding();
224uint64_t getRegMaskCommon(CompilationUnit* cUnit, int reg);
buzbeef0504cd2012-11-13 16:31:10 -0800225int s2d(int lowReg, int highReg);
226bool fpReg(int reg);
227bool singleReg(int reg);
228bool doubleReg(int reg);
229uint32_t fpRegMask();
230bool sameRegType(int reg1, int reg2);
231int targetReg(SpecialTargetRegister reg);
232RegLocation locCReturn();
233RegLocation locCReturnWide();
234RegLocation locCReturnFloat();
235RegLocation locCReturnDouble();
buzbeeb046e162012-10-30 15:48:42 -0700236
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800237} // namespace art
238
buzbee67bf8852011-08-17 17:51:35 -0700239#endif // ART_SRC_COMPILER_COMPILERCODEGEN_H_