blob: 948f3e75b754653d57da7ca644d5a36e19efab77 [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
Ben Cheng4238ec22009-08-24 16:32:22 -070020#include "codegen/Optimizer.h"
21
Ben Chengba4fc8b2009-06-01 13:00:29 -070022typedef 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,
Ben Cheng4238ec22009-08-24 16:32:22 -070030 ENTRY_BLOCK,
Ben Chengba4fc8b2009-06-01 13:00:29 -070031 DALVIK_BYTECODE,
Ben Cheng4238ec22009-08-24 16:32:22 -070032 EXIT_BLOCK,
Ben Chengba4fc8b2009-06-01 13:00:29 -070033 PC_RECONSTRUCTION,
34 EXCEPTION_HANDLING,
35} BBType;
36
Bill Buzbee46cd5b62009-06-05 15:36:06 -070037typedef struct ChainCellCounts {
38 union {
39 u1 count[CHAINING_CELL_LAST];
40 u4 dummyForAlignment;
41 } u;
42} ChainCellCounts;
43
Ben Chengba4fc8b2009-06-01 13:00:29 -070044typedef struct LIR {
45 int offset;
46 struct LIR *next;
47 struct LIR *prev;
48 struct LIR *target;
49} LIR;
50
Ben Cheng4238ec22009-08-24 16:32:22 -070051enum ExtendedMIROpcode {
52 MIR_OP_FIRST = 256,
53 MIR_OP_PHI = MIR_OP_FIRST,
54 MIR_OP_NULL_N_RANGE_UP_CHECK,
55 MIR_OP_NULL_N_RANGE_DOWN_CHECK,
56 MIR_OP_LOWER_BOUND_CHECK,
57 MIR_OP_PUNT,
58 MIR_OP_LAST,
59};
60
61struct SSARepresentation;
62
63typedef enum {
64 kMIRIgnoreNullCheck = 0,
65 kMIRNullCheckOnly,
66 kMIRIgnoreRangeCheck,
67 kMIRRangeCheckOnly,
68} MIROptimizationFlagPositons;
69
70#define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck)
71#define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly)
72#define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck)
73#define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly)
74
Ben Chengba4fc8b2009-06-01 13:00:29 -070075typedef struct MIR {
76 DecodedInstruction dalvikInsn;
77 unsigned int width;
78 unsigned int offset;
79 struct MIR *prev;
80 struct MIR *next;
Ben Cheng4238ec22009-08-24 16:32:22 -070081 struct SSARepresentation *ssaRep;
82 int OptimizationFlags;
Ben Chengba4fc8b2009-06-01 13:00:29 -070083} MIR;
84
Ben Cheng4238ec22009-08-24 16:32:22 -070085struct BasicBlockDataFlow;
86
Ben Chengba4fc8b2009-06-01 13:00:29 -070087typedef struct BasicBlock {
88 int id;
89 int visited;
90 unsigned int startOffset;
91 const Method *containingMethod; // For blocks from the callee
92 BBType blockType;
Ben Cheng1efc9c52009-06-08 18:25:27 -070093 bool needFallThroughBranch; // For blocks ended due to length limit
Ben Chengba4fc8b2009-06-01 13:00:29 -070094 MIR *firstMIRInsn;
95 MIR *lastMIRInsn;
96 struct BasicBlock *fallThrough;
97 struct BasicBlock *taken;
98 struct BasicBlock *next; // Serial link for book keeping purposes
Ben Cheng4238ec22009-08-24 16:32:22 -070099 struct BasicBlockDataFlow *dataFlowInfo;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700100} BasicBlock;
101
Ben Cheng4238ec22009-08-24 16:32:22 -0700102struct LoopAnalysis;
103
Ben Chengba4fc8b2009-06-01 13:00:29 -0700104typedef struct CompilationUnit {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700105 int numInsts;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700106 int numBlocks;
107 BasicBlock **blockList;
108 const Method *method;
109 const JitTraceDescription *traceDesc;
110 LIR *firstLIRInsn;
111 LIR *lastLIRInsn;
112 LIR *wordList;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700113 LIR *chainCellOffsetLIR;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700114 GrowableList pcReconstructionList;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700115 int headerSize; // bytes before the first code ptr
116 int dataOffset; // starting offset of literal pool
117 int totalSize; // header + code size
Ben Chengba4fc8b2009-06-01 13:00:29 -0700118 unsigned char *codeBuffer;
119 void *baseAddr;
120 bool printMe;
121 bool allSingleStep;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700122 bool halveInstCount;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700123 bool executionCount; // Add code to count trace executions
Ben Cheng4238ec22009-08-24 16:32:22 -0700124 bool hasLoop;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700125 int numChainingCells[CHAINING_CELL_LAST];
126 LIR *firstChainingLIR[CHAINING_CELL_LAST];
Ben Chenge9695e52009-06-16 16:11:47 -0700127 RegisterScoreboard registerScoreboard; // Track register dependency
128 int optRound; // round number to tell an LIR's age
Bill Buzbee716f1202009-07-23 13:22:09 -0700129 JitInstructionSetType instructionSet;
Ben Cheng4238ec22009-08-24 16:32:22 -0700130 /* Number of total regs used in the whole cUnit after SSA transformation */
131 int numSSARegs;
132 /* Map SSA reg i to the Dalvik[15..0]/Sub[31..16] pair. */
133 GrowableList *ssaToDalvikMap;
134
135 /* The following are new data structures to support SSA representations */
136 /* Map original Dalvik reg i to the SSA[15..0]/Sub[31..16] pair */
137 int *dalvikToSSAMap; // length == method->registersSize
138 BitVector *isConstantV; // length == numSSAReg
139 int *constantValues; // length == numSSAReg
140
141 /* Data structure for loop analysis and optimizations */
142 struct LoopAnalysis *loopAnalysis;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700143} CompilationUnit;
144
145BasicBlock *dvmCompilerNewBB(BBType blockType);
146
147void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir);
148
Ben Cheng4238ec22009-08-24 16:32:22 -0700149void dvmCompilerPrependMIR(BasicBlock *bb, MIR *mir);
150
Ben Chengba4fc8b2009-06-01 13:00:29 -0700151void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir);
152
Ben Chenge9695e52009-06-16 16:11:47 -0700153void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR);
154
Ben Chengba4fc8b2009-06-01 13:00:29 -0700155/* Debug Utilities */
156void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit);
157
158#endif /* _DALVIK_VM_COMPILER_IR */