blob: 8a2028abf06303df224cf338f8b663c98c8d4d46 [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
Ben Chenge9695e52009-06-16 16:11:47 -070017#include "codegen/Optimizer.h"
18
Ben Chengba4fc8b2009-06-01 13:00:29 -070019#ifndef _DALVIK_VM_COMPILER_IR
20#define _DALVIK_VM_COMPILER_IR
21
22typedef enum BBType {
23 /* For coding convenience reasons chaining cell types should appear first */
Ben Cheng1efc9c52009-06-08 18:25:27 -070024 CHAINING_CELL_NORMAL = 0,
25 CHAINING_CELL_HOT,
Ben Chengba4fc8b2009-06-01 13:00:29 -070026 CHAINING_CELL_INVOKE,
27 CHAINING_CELL_LAST,
28 DALVIK_BYTECODE,
29 PC_RECONSTRUCTION,
30 EXCEPTION_HANDLING,
31} BBType;
32
Bill Buzbee46cd5b62009-06-05 15:36:06 -070033typedef struct ChainCellCounts {
34 union {
35 u1 count[CHAINING_CELL_LAST];
36 u4 dummyForAlignment;
37 } u;
38} ChainCellCounts;
39
Ben Chengba4fc8b2009-06-01 13:00:29 -070040typedef struct LIR {
41 int offset;
42 struct LIR *next;
43 struct LIR *prev;
44 struct LIR *target;
45} LIR;
46
47typedef struct MIR {
48 DecodedInstruction dalvikInsn;
49 unsigned int width;
50 unsigned int offset;
51 struct MIR *prev;
52 struct MIR *next;
53} MIR;
54
55typedef struct BasicBlock {
56 int id;
57 int visited;
58 unsigned int startOffset;
59 const Method *containingMethod; // For blocks from the callee
60 BBType blockType;
Ben Cheng1efc9c52009-06-08 18:25:27 -070061 bool needFallThroughBranch; // For blocks ended due to length limit
Ben Chengba4fc8b2009-06-01 13:00:29 -070062 MIR *firstMIRInsn;
63 MIR *lastMIRInsn;
64 struct BasicBlock *fallThrough;
65 struct BasicBlock *taken;
66 struct BasicBlock *next; // Serial link for book keeping purposes
67} BasicBlock;
68
69typedef struct CompilationUnit {
Ben Cheng1efc9c52009-06-08 18:25:27 -070070 int numInsts;
Ben Chengba4fc8b2009-06-01 13:00:29 -070071 int numBlocks;
72 BasicBlock **blockList;
73 const Method *method;
74 const JitTraceDescription *traceDesc;
75 LIR *firstLIRInsn;
76 LIR *lastLIRInsn;
77 LIR *wordList;
Bill Buzbee6e963e12009-06-17 16:56:19 -070078 LIR *chainCellOffsetLIR;
Ben Chengba4fc8b2009-06-01 13:00:29 -070079 GrowableList pcReconstructionList;
Ben Cheng1efc9c52009-06-08 18:25:27 -070080 int headerSize; // bytes before the first code ptr
81 int dataOffset; // starting offset of literal pool
82 int totalSize; // header + code size
Ben Chengba4fc8b2009-06-01 13:00:29 -070083 unsigned char *codeBuffer;
84 void *baseAddr;
85 bool printMe;
86 bool allSingleStep;
Ben Cheng1efc9c52009-06-08 18:25:27 -070087 bool halveInstCount;
Bill Buzbee6e963e12009-06-17 16:56:19 -070088 bool executionCount; // Add code to count trace executions
Ben Chengba4fc8b2009-06-01 13:00:29 -070089 int numChainingCells[CHAINING_CELL_LAST];
90 LIR *firstChainingLIR[CHAINING_CELL_LAST];
Ben Chenge9695e52009-06-16 16:11:47 -070091 RegisterScoreboard registerScoreboard; // Track register dependency
92 int optRound; // round number to tell an LIR's age
Ben Chengba4fc8b2009-06-01 13:00:29 -070093} CompilationUnit;
94
95BasicBlock *dvmCompilerNewBB(BBType blockType);
96
97void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
98
99void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
100
Ben Chenge9695e52009-06-16 16:11:47 -0700101void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
102
Ben Chengba4fc8b2009-06-01 13:00:29 -0700103/* Debug Utilities */
104void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
105
106#endif /* _DALVIK_VM_COMPILER_IR */