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