blob: 35611a3fb5ecb9384fdbb78af76fa029e9238dd9 [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
2 * Copyright (C) 2009 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 _DALVIK_VM_COMPILER_IR
18#define _DALVIK_VM_COMPILER_IR
19
Ben Cheng4238ec22009-08-24 16:32:22 -070020#include "codegen/Optimizer.h"
21
Bill Buzbee1465db52009-09-23 17:17:35 -070022typedef enum RegisterClass {
23 kCoreReg,
24 kFPReg,
25 kAnyReg,
26} RegisterClass;
27
28typedef enum RegLocationType {
29 kLocDalvikFrame = 0,
30 kLocPhysReg,
31 kLocRetval, // Return region in interpState
32 kLocSpill,
33} RegLocationType;
34
35typedef struct RegLocation {
36 RegLocationType location:2;
37 unsigned wide:1;
38 unsigned fp:1; // Hint for float/double
39 u1 lowReg:6; // First physical register
40 u1 highReg:6; // 2nd physical register (if wide)
41 s2 sRegLow; // SSA name for low Dalvik word
42} RegLocation;
43
44#define INVALID_SREG (-1)
45#define INVALID_REG (-1)
46
Ben Chengba4fc8b2009-06-01 13:00:29 -070047typedef enum BBType {
48 /* For coding convenience reasons chaining cell types should appear first */
Bill Buzbee1465db52009-09-23 17:17:35 -070049 kChainingCellNormal = 0,
50 kChainingCellHot,
51 kChainingCellInvokeSingleton,
52 kChainingCellInvokePredicted,
53 kChainingCellBackwardBranch,
54 kChainingCellLast,
55 kEntryBlock,
56 kDalvikByteCode,
57 kExitBlock,
58 kPCReconstruction,
59 kExceptionHandling,
Ben Chengba4fc8b2009-06-01 13:00:29 -070060} BBType;
61
Bill Buzbee46cd5b62009-06-05 15:36:06 -070062typedef struct ChainCellCounts {
63 union {
Bill Buzbee1465db52009-09-23 17:17:35 -070064 u1 count[kChainingCellLast];
Bill Buzbee46cd5b62009-06-05 15:36:06 -070065 u4 dummyForAlignment;
66 } u;
67} ChainCellCounts;
68
Ben Chengba4fc8b2009-06-01 13:00:29 -070069typedef struct LIR {
70 int offset;
71 struct LIR *next;
72 struct LIR *prev;
73 struct LIR *target;
74} LIR;
75
Ben Cheng4238ec22009-08-24 16:32:22 -070076enum ExtendedMIROpcode {
Bill Buzbee1465db52009-09-23 17:17:35 -070077 kMirOpFirst = 256,
78 kMirOpPhi = kMirOpFirst,
79 kMirOpNullNRangeUpCheck,
80 kMirOpNullNRangeDownCheck,
81 kMirOpLowerBound,
82 kMirOpPunt,
83 kMirOpLast,
Ben Cheng4238ec22009-08-24 16:32:22 -070084};
85
86struct SSARepresentation;
87
88typedef enum {
89 kMIRIgnoreNullCheck = 0,
90 kMIRNullCheckOnly,
91 kMIRIgnoreRangeCheck,
92 kMIRRangeCheckOnly,
93} MIROptimizationFlagPositons;
94
95#define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck)
96#define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly)
97#define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck)
98#define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly)
99
Ben Chengba4fc8b2009-06-01 13:00:29 -0700100typedef struct MIR {
101 DecodedInstruction dalvikInsn;
102 unsigned int width;
103 unsigned int offset;
104 struct MIR *prev;
105 struct MIR *next;
Ben Cheng4238ec22009-08-24 16:32:22 -0700106 struct SSARepresentation *ssaRep;
107 int OptimizationFlags;
Bill Buzbee1465db52009-09-23 17:17:35 -0700108 int seqNum;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700109} MIR;
110
Ben Cheng4238ec22009-08-24 16:32:22 -0700111struct BasicBlockDataFlow;
112
Ben Chengba4fc8b2009-06-01 13:00:29 -0700113typedef struct BasicBlock {
114 int id;
115 int visited;
116 unsigned int startOffset;
117 const Method *containingMethod; // For blocks from the callee
118 BBType blockType;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700119 bool needFallThroughBranch; // For blocks ended due to length limit
Ben Chengba4fc8b2009-06-01 13:00:29 -0700120 MIR *firstMIRInsn;
121 MIR *lastMIRInsn;
122 struct BasicBlock *fallThrough;
123 struct BasicBlock *taken;
124 struct BasicBlock *next; // Serial link for book keeping purposes
Ben Cheng4238ec22009-08-24 16:32:22 -0700125 struct BasicBlockDataFlow *dataFlowInfo;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700126} BasicBlock;
127
Ben Cheng4238ec22009-08-24 16:32:22 -0700128struct LoopAnalysis;
Bill Buzbee1465db52009-09-23 17:17:35 -0700129struct RegisterPool;
Ben Cheng4238ec22009-08-24 16:32:22 -0700130
Ben Chengba4fc8b2009-06-01 13:00:29 -0700131typedef struct CompilationUnit {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700132 int numInsts;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700133 int numBlocks;
134 BasicBlock **blockList;
135 const Method *method;
136 const JitTraceDescription *traceDesc;
137 LIR *firstLIRInsn;
138 LIR *lastLIRInsn;
139 LIR *wordList;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700140 LIR *chainCellOffsetLIR;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700141 GrowableList pcReconstructionList;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700142 int headerSize; // bytes before the first code ptr
143 int dataOffset; // starting offset of literal pool
144 int totalSize; // header + code size
Ben Chengba4fc8b2009-06-01 13:00:29 -0700145 unsigned char *codeBuffer;
146 void *baseAddr;
147 bool printMe;
148 bool allSingleStep;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700149 bool halveInstCount;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700150 bool executionCount; // Add code to count trace executions
Ben Cheng4238ec22009-08-24 16:32:22 -0700151 bool hasLoop;
Bill Buzbee1465db52009-09-23 17:17:35 -0700152 int numChainingCells[kChainingCellLast];
153 LIR *firstChainingLIR[kChainingCellLast];
154 struct RegisterPool *regPool;
Ben Chenge9695e52009-06-16 16:11:47 -0700155 int optRound; // round number to tell an LIR's age
Bill Buzbee716f1202009-07-23 13:22:09 -0700156 JitInstructionSetType instructionSet;
Ben Cheng4238ec22009-08-24 16:32:22 -0700157 /* Number of total regs used in the whole cUnit after SSA transformation */
158 int numSSARegs;
159 /* Map SSA reg i to the Dalvik[15..0]/Sub[31..16] pair. */
160 GrowableList *ssaToDalvikMap;
161
162 /* The following are new data structures to support SSA representations */
163 /* Map original Dalvik reg i to the SSA[15..0]/Sub[31..16] pair */
164 int *dalvikToSSAMap; // length == method->registersSize
165 BitVector *isConstantV; // length == numSSAReg
166 int *constantValues; // length == numSSAReg
167
168 /* Data structure for loop analysis and optimizations */
169 struct LoopAnalysis *loopAnalysis;
Bill Buzbee1465db52009-09-23 17:17:35 -0700170
171 /* Map SSA names to location */
172 RegLocation *regLocation;
173 int sequenceNumber;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700174} CompilationUnit;
175
176BasicBlock *dvmCompilerNewBB(BBType blockType);
177
178void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
179
Ben Cheng4238ec22009-08-24 16:32:22 -0700180void dvmCompilerPrependMIR(BasicBlock *bb, MIR *mir);
181
Ben Chengba4fc8b2009-06-01 13:00:29 -0700182void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
183
Ben Chenge9695e52009-06-16 16:11:47 -0700184void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
185
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700186void dvmCompilerInsertLIRAfter(LIR *currentLIR, LIR *newLIR);
187
Ben Chengba4fc8b2009-06-01 13:00:29 -0700188/* Debug Utilities */
189void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
190
191#endif /* _DALVIK_VM_COMPILER_IR */