blob: 712cbae39e1e41aa4ffa917391363cb0fb85a06b [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
20typedef enum BBType {
21 /* For coding convenience reasons chaining cell types should appear first */
Ben Cheng1efc9c52009-06-08 18:25:27 -070022 CHAINING_CELL_NORMAL = 0,
23 CHAINING_CELL_HOT,
Ben Chengba4fc8b2009-06-01 13:00:29 -070024 CHAINING_CELL_INVOKE,
25 CHAINING_CELL_LAST,
26 DALVIK_BYTECODE,
27 PC_RECONSTRUCTION,
28 EXCEPTION_HANDLING,
29} BBType;
30
Bill Buzbee46cd5b62009-06-05 15:36:06 -070031typedef struct ChainCellCounts {
32 union {
33 u1 count[CHAINING_CELL_LAST];
34 u4 dummyForAlignment;
35 } u;
36} ChainCellCounts;
37
Ben Chengba4fc8b2009-06-01 13:00:29 -070038typedef struct LIR {
39 int offset;
40 struct LIR *next;
41 struct LIR *prev;
42 struct LIR *target;
43} LIR;
44
45typedef struct MIR {
46 DecodedInstruction dalvikInsn;
47 unsigned int width;
48 unsigned int offset;
49 struct MIR *prev;
50 struct MIR *next;
51} MIR;
52
53typedef struct BasicBlock {
54 int id;
55 int visited;
56 unsigned int startOffset;
57 const Method *containingMethod; // For blocks from the callee
58 BBType blockType;
Ben Cheng1efc9c52009-06-08 18:25:27 -070059 bool needFallThroughBranch; // For blocks ended due to length limit
Ben Chengba4fc8b2009-06-01 13:00:29 -070060 MIR *firstMIRInsn;
61 MIR *lastMIRInsn;
62 struct BasicBlock *fallThrough;
63 struct BasicBlock *taken;
64 struct BasicBlock *next; // Serial link for book keeping purposes
65} BasicBlock;
66
67typedef struct CompilationUnit {
Ben Cheng1efc9c52009-06-08 18:25:27 -070068 int numInsts;
Ben Chengba4fc8b2009-06-01 13:00:29 -070069 int numBlocks;
70 BasicBlock **blockList;
71 const Method *method;
72 const JitTraceDescription *traceDesc;
73 LIR *firstLIRInsn;
74 LIR *lastLIRInsn;
75 LIR *wordList;
76 GrowableList pcReconstructionList;
Ben Cheng1efc9c52009-06-08 18:25:27 -070077 int headerSize; // bytes before the first code ptr
78 int dataOffset; // starting offset of literal pool
79 int totalSize; // header + code size
Ben Chengba4fc8b2009-06-01 13:00:29 -070080 unsigned char *codeBuffer;
81 void *baseAddr;
82 bool printMe;
83 bool allSingleStep;
Ben Cheng1efc9c52009-06-08 18:25:27 -070084 bool halveInstCount;
Ben Chengba4fc8b2009-06-01 13:00:29 -070085 int numChainingCells[CHAINING_CELL_LAST];
86 LIR *firstChainingLIR[CHAINING_CELL_LAST];
87} CompilationUnit;
88
89BasicBlock *dvmCompilerNewBB(BBType blockType);
90
91void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
92
93void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
94
95/* Debug Utilities */
96void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
97
98#endif /* _DALVIK_VM_COMPILER_IR */