OSDN Git Service

389ac7c514d69e1965ef06604ba3438d4303d254
[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 #include "codegen/Optimizer.h"
18
19 #ifndef _DALVIK_VM_COMPILER_IR
20 #define _DALVIK_VM_COMPILER_IR
21
22 typedef enum BBType {
23     /* For coding convenience reasons chaining cell types should appear first */
24     CHAINING_CELL_NORMAL = 0,
25     CHAINING_CELL_HOT,
26     CHAINING_CELL_INVOKE_SINGLETON,
27     CHAINING_CELL_INVOKE_PREDICTED,
28     CHAINING_CELL_BACKWARD_BRANCH,
29     CHAINING_CELL_LAST,
30     DALVIK_BYTECODE,
31     PC_RECONSTRUCTION,
32     EXCEPTION_HANDLING,
33 } BBType;
34
35 typedef struct ChainCellCounts {
36     union {
37         u1 count[CHAINING_CELL_LAST];
38         u4 dummyForAlignment;
39     } u;
40 } ChainCellCounts;
41
42 typedef struct LIR {
43     int offset;
44     struct LIR *next;
45     struct LIR *prev;
46     struct LIR *target;
47 } LIR;
48
49 typedef struct MIR {
50     DecodedInstruction dalvikInsn;
51     unsigned int width;
52     unsigned int offset;
53     struct MIR *prev;
54     struct MIR *next;
55 } MIR;
56
57 typedef struct BasicBlock {
58     int id;
59     int visited;
60     unsigned int startOffset;
61     const Method *containingMethod;     // For blocks from the callee
62     BBType blockType;
63     bool needFallThroughBranch;         // For blocks ended due to length limit
64     MIR *firstMIRInsn;
65     MIR *lastMIRInsn;
66     struct BasicBlock *fallThrough;
67     struct BasicBlock *taken;
68     struct BasicBlock *next;            // Serial link for book keeping purposes
69 } BasicBlock;
70
71 typedef struct CompilationUnit {
72     int numInsts;
73     int numBlocks;
74     BasicBlock **blockList;
75     const Method *method;
76     const JitTraceDescription *traceDesc;
77     LIR *firstLIRInsn;
78     LIR *lastLIRInsn;
79     LIR *wordList;
80     LIR *chainCellOffsetLIR;
81     GrowableList pcReconstructionList;
82     int headerSize;                     // bytes before the first code ptr
83     int dataOffset;                     // starting offset of literal pool
84     int totalSize;                      // header + code size
85     unsigned char *codeBuffer;
86     void *baseAddr;
87     bool printMe;
88     bool allSingleStep;
89     bool halveInstCount;
90     bool executionCount;                // Add code to count trace executions
91     int numChainingCells[CHAINING_CELL_LAST];
92     LIR *firstChainingLIR[CHAINING_CELL_LAST];
93     RegisterScoreboard registerScoreboard;      // Track register dependency
94     int optRound;                       // round number to tell an LIR's age
95     JitInstructionSetType instructionSet;
96 } CompilationUnit;
97
98 BasicBlock *dvmCompilerNewBB(BBType blockType);
99
100 void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
101
102 void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
103
104 void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
105
106 /* Debug Utilities */
107 void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
108
109 #endif /* _DALVIK_VM_COMPILER_IR */