blob: 389ac7c514d69e1965ef06604ba3438d4303d254 [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 Cheng38329f52009-07-07 14:19:20 -070026 CHAINING_CELL_INVOKE_SINGLETON,
27 CHAINING_CELL_INVOKE_PREDICTED,
Jeff Hao97319a82009-08-12 16:57:15 -070028 CHAINING_CELL_BACKWARD_BRANCH,
Ben Chengba4fc8b2009-06-01 13:00:29 -070029 CHAINING_CELL_LAST,
30 DALVIK_BYTECODE,
31 PC_RECONSTRUCTION,
32 EXCEPTION_HANDLING,
33} BBType;
34
Bill Buzbee46cd5b62009-06-05 15:36:06 -070035typedef struct ChainCellCounts {
36 union {
37 u1 count[CHAINING_CELL_LAST];
38 u4 dummyForAlignment;
39 } u;
40} ChainCellCounts;
41
Ben Chengba4fc8b2009-06-01 13:00:29 -070042typedef struct LIR {
43 int offset;
44 struct LIR *next;
45 struct LIR *prev;
46 struct LIR *target;
47} LIR;
48
49typedef struct MIR {
50 DecodedInstruction dalvikInsn;
51 unsigned int width;
52 unsigned int offset;
53 struct MIR *prev;
54 struct MIR *next;
55} MIR;
56
57typedef struct BasicBlock {
58 int id;
59 int visited;
60 unsigned int startOffset;
61 const Method *containingMethod; // For blocks from the callee
62 BBType blockType;
Ben Cheng1efc9c52009-06-08 18:25:27 -070063 bool needFallThroughBranch; // For blocks ended due to length limit
Ben Chengba4fc8b2009-06-01 13:00:29 -070064 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
71typedef struct CompilationUnit {
Ben Cheng1efc9c52009-06-08 18:25:27 -070072 int numInsts;
Ben Chengba4fc8b2009-06-01 13:00:29 -070073 int numBlocks;
74 BasicBlock **blockList;
75 const Method *method;
76 const JitTraceDescription *traceDesc;
77 LIR *firstLIRInsn;
78 LIR *lastLIRInsn;
79 LIR *wordList;
Bill Buzbee6e963e12009-06-17 16:56:19 -070080 LIR *chainCellOffsetLIR;
Ben Chengba4fc8b2009-06-01 13:00:29 -070081 GrowableList pcReconstructionList;
Ben Cheng1efc9c52009-06-08 18:25:27 -070082 int headerSize; // bytes before the first code ptr
83 int dataOffset; // starting offset of literal pool
84 int totalSize; // header + code size
Ben Chengba4fc8b2009-06-01 13:00:29 -070085 unsigned char *codeBuffer;
86 void *baseAddr;
87 bool printMe;
88 bool allSingleStep;
Ben Cheng1efc9c52009-06-08 18:25:27 -070089 bool halveInstCount;
Bill Buzbee6e963e12009-06-17 16:56:19 -070090 bool executionCount; // Add code to count trace executions
Ben Chengba4fc8b2009-06-01 13:00:29 -070091 int numChainingCells[CHAINING_CELL_LAST];
92 LIR *firstChainingLIR[CHAINING_CELL_LAST];
Ben Chenge9695e52009-06-16 16:11:47 -070093 RegisterScoreboard registerScoreboard; // Track register dependency
94 int optRound; // round number to tell an LIR's age
Bill Buzbee716f1202009-07-23 13:22:09 -070095 JitInstructionSetType instructionSet;
Ben Chengba4fc8b2009-06-01 13:00:29 -070096} CompilationUnit;
97
98BasicBlock *dvmCompilerNewBB(BBType blockType);
99
100void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
101
102void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
103
Ben Chenge9695e52009-06-16 16:11:47 -0700104void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
105
Ben Chengba4fc8b2009-06-01 13:00:29 -0700106/* Debug Utilities */
107void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
108
109#endif /* _DALVIK_VM_COMPILER_IR */