blob: 201b0cc5d80569f329d9cd2fc62450548caa3ae9 [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,
Ben Chengba4fc8b2009-06-01 13:00:29 -070028 CHAINING_CELL_LAST,
29 DALVIK_BYTECODE,
30 PC_RECONSTRUCTION,
31 EXCEPTION_HANDLING,
32} BBType;
33
Bill Buzbee46cd5b62009-06-05 15:36:06 -070034typedef struct ChainCellCounts {
35 union {
36 u1 count[CHAINING_CELL_LAST];
37 u4 dummyForAlignment;
38 } u;
39} ChainCellCounts;
40
Ben Chengba4fc8b2009-06-01 13:00:29 -070041typedef struct LIR {
42 int offset;
43 struct LIR *next;
44 struct LIR *prev;
45 struct LIR *target;
46} LIR;
47
48typedef struct MIR {
49 DecodedInstruction dalvikInsn;
50 unsigned int width;
51 unsigned int offset;
52 struct MIR *prev;
53 struct MIR *next;
54} MIR;
55
56typedef struct BasicBlock {
57 int id;
58 int visited;
59 unsigned int startOffset;
60 const Method *containingMethod; // For blocks from the callee
61 BBType blockType;
Ben Cheng1efc9c52009-06-08 18:25:27 -070062 bool needFallThroughBranch; // For blocks ended due to length limit
Ben Chengba4fc8b2009-06-01 13:00:29 -070063 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
70typedef struct CompilationUnit {
Ben Cheng1efc9c52009-06-08 18:25:27 -070071 int numInsts;
Ben Chengba4fc8b2009-06-01 13:00:29 -070072 int numBlocks;
73 BasicBlock **blockList;
74 const Method *method;
75 const JitTraceDescription *traceDesc;
76 LIR *firstLIRInsn;
77 LIR *lastLIRInsn;
78 LIR *wordList;
Bill Buzbee6e963e12009-06-17 16:56:19 -070079 LIR *chainCellOffsetLIR;
Ben Chengba4fc8b2009-06-01 13:00:29 -070080 GrowableList pcReconstructionList;
Ben Cheng1efc9c52009-06-08 18:25:27 -070081 int headerSize; // bytes before the first code ptr
82 int dataOffset; // starting offset of literal pool
83 int totalSize; // header + code size
Ben Chengba4fc8b2009-06-01 13:00:29 -070084 unsigned char *codeBuffer;
85 void *baseAddr;
86 bool printMe;
87 bool allSingleStep;
Ben Cheng1efc9c52009-06-08 18:25:27 -070088 bool halveInstCount;
Bill Buzbee6e963e12009-06-17 16:56:19 -070089 bool executionCount; // Add code to count trace executions
Ben Chengba4fc8b2009-06-01 13:00:29 -070090 int numChainingCells[CHAINING_CELL_LAST];
91 LIR *firstChainingLIR[CHAINING_CELL_LAST];
Ben Chenge9695e52009-06-16 16:11:47 -070092 RegisterScoreboard registerScoreboard; // Track register dependency
93 int optRound; // round number to tell an LIR's age
Ben Chengba4fc8b2009-06-01 13:00:29 -070094} CompilationUnit;
95
96BasicBlock *dvmCompilerNewBB(BBType blockType);
97
98void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
99
100void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
101
Ben Chenge9695e52009-06-16 16:11:47 -0700102void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
103
Ben Chengba4fc8b2009-06-01 13:00:29 -0700104/* Debug Utilities */
105void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
106
107#endif /* _DALVIK_VM_COMPILER_IR */