2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _DALVIK_VM_COMPILER_IR
18 #define _DALVIK_VM_COMPILER_IR
20 #include "codegen/Optimizer.h"
22 typedef enum RegisterClass {
28 typedef enum RegLocationType {
31 kLocRetval, // Return region in interpState
35 typedef struct RegLocation {
36 RegLocationType location:2;
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
44 #define INVALID_SREG (-1)
45 #define INVALID_REG (-1)
48 /* For coding convenience reasons chaining cell types should appear first */
49 kChainingCellNormal = 0,
51 kChainingCellInvokeSingleton,
52 kChainingCellInvokePredicted,
53 kChainingCellBackwardBranch,
62 typedef struct ChainCellCounts {
64 u1 count[kChainingCellLast];
76 enum ExtendedMIROpcode {
78 kMirOpPhi = kMirOpFirst,
79 kMirOpNullNRangeUpCheck,
80 kMirOpNullNRangeDownCheck,
86 struct SSARepresentation;
89 kMIRIgnoreNullCheck = 0,
93 } MIROptimizationFlagPositons;
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)
101 DecodedInstruction dalvikInsn;
106 struct SSARepresentation *ssaRep;
107 int OptimizationFlags;
111 struct BasicBlockDataFlow;
113 typedef struct BasicBlock {
116 unsigned int startOffset;
117 const Method *containingMethod; // For blocks from the callee
119 bool needFallThroughBranch; // For blocks ended due to length limit
122 struct BasicBlock *fallThrough;
123 struct BasicBlock *taken;
124 struct BasicBlock *next; // Serial link for book keeping purposes
125 struct BasicBlockDataFlow *dataFlowInfo;
131 typedef struct CompilationUnit {
134 BasicBlock **blockList;
135 const Method *method;
136 const JitTraceDescription *traceDesc;
140 LIR *chainCellOffsetLIR;
141 GrowableList pcReconstructionList;
142 int headerSize; // bytes before the first code ptr
143 int dataOffset; // starting offset of literal pool
144 int totalSize; // header + code size
145 unsigned char *codeBuffer;
150 bool executionCount; // Add code to count trace executions
152 int numChainingCells[kChainingCellLast];
153 LIR *firstChainingLIR[kChainingCellLast];
154 struct RegisterPool *regPool;
155 int optRound; // round number to tell an LIR's age
156 JitInstructionSetType instructionSet;
157 /* Number of total regs used in the whole cUnit after SSA transformation */
159 /* Map SSA reg i to the Dalvik[15..0]/Sub[31..16] pair. */
160 GrowableList *ssaToDalvikMap;
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
168 /* Data structure for loop analysis and optimizations */
169 struct LoopAnalysis *loopAnalysis;
171 /* Map SSA names to location */
172 RegLocation *regLocation;
176 * Set to the Dalvik PC of the switch instruction if it has more than
177 * MAX_CHAINED_SWITCH_CASES cases.
179 const u2 *switchOverflowPad;
182 BasicBlock *dvmCompilerNewBB(BBType blockType);
184 void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
186 void dvmCompilerPrependMIR(BasicBlock *bb, MIR *mir);
188 void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
190 void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
192 void dvmCompilerInsertLIRAfter(LIR *currentLIR, LIR *newLIR);
194 /* Debug Utilities */
195 void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
197 #endif /* _DALVIK_VM_COMPILER_IR */