| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 20 | #include "codegen/Optimizer.h" |
| 21 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 22 | typedef enum BBType { |
| 23 | /* For coding convenience reasons chaining cell types should appear first */ |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 24 | CHAINING_CELL_NORMAL = 0, |
| 25 | CHAINING_CELL_HOT, |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 26 | CHAINING_CELL_INVOKE_SINGLETON, |
| 27 | CHAINING_CELL_INVOKE_PREDICTED, |
| Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame] | 28 | CHAINING_CELL_BACKWARD_BRANCH, |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 29 | CHAINING_CELL_LAST, |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 30 | ENTRY_BLOCK, |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 31 | DALVIK_BYTECODE, |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 32 | EXIT_BLOCK, |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 33 | PC_RECONSTRUCTION, |
| 34 | EXCEPTION_HANDLING, |
| 35 | } BBType; |
| 36 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 37 | typedef struct ChainCellCounts { |
| 38 | union { |
| 39 | u1 count[CHAINING_CELL_LAST]; |
| 40 | u4 dummyForAlignment; |
| 41 | } u; |
| 42 | } ChainCellCounts; |
| 43 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 44 | typedef struct LIR { |
| 45 | int offset; |
| 46 | struct LIR *next; |
| 47 | struct LIR *prev; |
| 48 | struct LIR *target; |
| 49 | } LIR; |
| 50 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 51 | enum 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 | |
| 61 | struct SSARepresentation; |
| 62 | |
| 63 | typedef 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 Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 75 | typedef struct MIR { |
| 76 | DecodedInstruction dalvikInsn; |
| 77 | unsigned int width; |
| 78 | unsigned int offset; |
| 79 | struct MIR *prev; |
| 80 | struct MIR *next; |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 81 | struct SSARepresentation *ssaRep; |
| 82 | int OptimizationFlags; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 83 | } MIR; |
| 84 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 85 | struct BasicBlockDataFlow; |
| 86 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 87 | typedef 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 Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 93 | bool needFallThroughBranch; // For blocks ended due to length limit |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 94 | MIR *firstMIRInsn; |
| 95 | MIR *lastMIRInsn; |
| 96 | struct BasicBlock *fallThrough; |
| 97 | struct BasicBlock *taken; |
| 98 | struct BasicBlock *next; // Serial link for book keeping purposes |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 99 | struct BasicBlockDataFlow *dataFlowInfo; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 100 | } BasicBlock; |
| 101 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 102 | struct LoopAnalysis; |
| 103 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 104 | typedef struct CompilationUnit { |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 105 | int numInsts; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 106 | int numBlocks; |
| 107 | BasicBlock **blockList; |
| 108 | const Method *method; |
| 109 | const JitTraceDescription *traceDesc; |
| 110 | LIR *firstLIRInsn; |
| 111 | LIR *lastLIRInsn; |
| 112 | LIR *wordList; |
| Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 113 | LIR *chainCellOffsetLIR; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 114 | GrowableList pcReconstructionList; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 115 | int headerSize; // bytes before the first code ptr |
| 116 | int dataOffset; // starting offset of literal pool |
| 117 | int totalSize; // header + code size |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 118 | unsigned char *codeBuffer; |
| 119 | void *baseAddr; |
| 120 | bool printMe; |
| 121 | bool allSingleStep; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 122 | bool halveInstCount; |
| Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 123 | bool executionCount; // Add code to count trace executions |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 124 | bool hasLoop; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 125 | int numChainingCells[CHAINING_CELL_LAST]; |
| 126 | LIR *firstChainingLIR[CHAINING_CELL_LAST]; |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 127 | RegisterScoreboard registerScoreboard; // Track register dependency |
| 128 | int optRound; // round number to tell an LIR's age |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 129 | JitInstructionSetType instructionSet; |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 130 | /* 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 Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 143 | } CompilationUnit; |
| 144 | |
| 145 | BasicBlock *dvmCompilerNewBB(BBType blockType); |
| 146 | |
| 147 | void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir); |
| 148 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame^] | 149 | void dvmCompilerPrependMIR(BasicBlock *bb, MIR *mir); |
| 150 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 151 | void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir); |
| 152 | |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 153 | void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR); |
| 154 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 155 | /* Debug Utilities */ |
| 156 | void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit); |
| 157 | |
| 158 | #endif /* _DALVIK_VM_COMPILER_IR */ |