OSDN Git Service

Implement chaining up to the first 64 cases in a switch statement.
[android-x86/dalvik.git] / vm / compiler / CompilerIR.h
1 /*
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
20 #include "codegen/Optimizer.h"
21
22 typedef enum RegisterClass {
23     kCoreReg,
24     kFPReg,
25     kAnyReg,
26 } RegisterClass;
27
28 typedef enum RegLocationType {
29     kLocDalvikFrame = 0,
30     kLocPhysReg,
31     kLocRetval,          // Return region in interpState
32     kLocSpill,
33 } RegLocationType;
34
35 typedef 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
47 typedef enum BBType {
48     /* For coding convenience reasons chaining cell types should appear first */
49     kChainingCellNormal = 0,
50     kChainingCellHot,
51     kChainingCellInvokeSingleton,
52     kChainingCellInvokePredicted,
53     kChainingCellBackwardBranch,
54     kChainingCellLast,
55     kEntryBlock,
56     kDalvikByteCode,
57     kExitBlock,
58     kPCReconstruction,
59     kExceptionHandling,
60 } BBType;
61
62 typedef struct ChainCellCounts {
63     union {
64         u1 count[kChainingCellLast];
65         u4 dummyForAlignment;
66     } u;
67 } ChainCellCounts;
68
69 typedef struct LIR {
70     int offset;
71     struct LIR *next;
72     struct LIR *prev;
73     struct LIR *target;
74 } LIR;
75
76 enum ExtendedMIROpcode {
77     kMirOpFirst = 256,
78     kMirOpPhi = kMirOpFirst,
79     kMirOpNullNRangeUpCheck,
80     kMirOpNullNRangeDownCheck,
81     kMirOpLowerBound,
82     kMirOpPunt,
83     kMirOpLast,
84 };
85
86 struct SSARepresentation;
87
88 typedef 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
100 typedef struct MIR {
101     DecodedInstruction dalvikInsn;
102     unsigned int width;
103     unsigned int offset;
104     struct MIR *prev;
105     struct MIR *next;
106     struct SSARepresentation *ssaRep;
107     int OptimizationFlags;
108     int seqNum;
109 } MIR;
110
111 struct BasicBlockDataFlow;
112
113 typedef struct BasicBlock {
114     int id;
115     int visited;
116     unsigned int startOffset;
117     const Method *containingMethod;     // For blocks from the callee
118     BBType blockType;
119     bool needFallThroughBranch;         // For blocks ended due to length limit
120     MIR *firstMIRInsn;
121     MIR *lastMIRInsn;
122     struct BasicBlock *fallThrough;
123     struct BasicBlock *taken;
124     struct BasicBlock *next;            // Serial link for book keeping purposes
125     struct BasicBlockDataFlow *dataFlowInfo;
126 } BasicBlock;
127
128 struct LoopAnalysis;
129 struct RegisterPool;
130
131 typedef struct CompilationUnit {
132     int numInsts;
133     int numBlocks;
134     BasicBlock **blockList;
135     const Method *method;
136     const JitTraceDescription *traceDesc;
137     LIR *firstLIRInsn;
138     LIR *lastLIRInsn;
139     LIR *wordList;
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;
146     void *baseAddr;
147     bool printMe;
148     bool allSingleStep;
149     bool halveInstCount;
150     bool executionCount;                // Add code to count trace executions
151     bool hasLoop;
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 */
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;
170
171     /* Map SSA names to location */
172     RegLocation *regLocation;
173     int sequenceNumber;
174
175     /*
176      * Set to the Dalvik PC of the switch instruction if it has more than
177      * MAX_CHAINED_SWITCH_CASES cases.
178      */
179     const u2 *switchOverflowPad;
180 } CompilationUnit;
181
182 BasicBlock *dvmCompilerNewBB(BBType blockType);
183
184 void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
185
186 void dvmCompilerPrependMIR(BasicBlock *bb, MIR *mir);
187
188 void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
189
190 void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
191
192 void dvmCompilerInsertLIRAfter(LIR *currentLIR, LIR *newLIR);
193
194 /* Debug Utilities */
195 void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
196
197 #endif /* _DALVIK_VM_COMPILER_IR */