| 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 | |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 17 | #include "codegen/Optimizer.h" |
| 18 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 19 | #ifndef _DALVIK_VM_COMPILER_IR |
| 20 | #define _DALVIK_VM_COMPILER_IR |
| 21 | |
| 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, |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 28 | CHAINING_CELL_LAST, |
| 29 | DALVIK_BYTECODE, |
| 30 | PC_RECONSTRUCTION, |
| 31 | EXCEPTION_HANDLING, |
| 32 | } BBType; |
| 33 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 34 | typedef struct ChainCellCounts { |
| 35 | union { |
| 36 | u1 count[CHAINING_CELL_LAST]; |
| 37 | u4 dummyForAlignment; |
| 38 | } u; |
| 39 | } ChainCellCounts; |
| 40 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 41 | typedef struct LIR { |
| 42 | int offset; |
| 43 | struct LIR *next; |
| 44 | struct LIR *prev; |
| 45 | struct LIR *target; |
| 46 | } LIR; |
| 47 | |
| 48 | typedef struct MIR { |
| 49 | DecodedInstruction dalvikInsn; |
| 50 | unsigned int width; |
| 51 | unsigned int offset; |
| 52 | struct MIR *prev; |
| 53 | struct MIR *next; |
| 54 | } MIR; |
| 55 | |
| 56 | typedef 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 Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 62 | bool needFallThroughBranch; // For blocks ended due to length limit |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 63 | 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 | |
| 70 | typedef struct CompilationUnit { |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 71 | int numInsts; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 72 | int numBlocks; |
| 73 | BasicBlock **blockList; |
| 74 | const Method *method; |
| 75 | const JitTraceDescription *traceDesc; |
| 76 | LIR *firstLIRInsn; |
| 77 | LIR *lastLIRInsn; |
| 78 | LIR *wordList; |
| Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 79 | LIR *chainCellOffsetLIR; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 80 | GrowableList pcReconstructionList; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 81 | int headerSize; // bytes before the first code ptr |
| 82 | int dataOffset; // starting offset of literal pool |
| 83 | int totalSize; // header + code size |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 84 | unsigned char *codeBuffer; |
| 85 | void *baseAddr; |
| 86 | bool printMe; |
| 87 | bool allSingleStep; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 88 | bool halveInstCount; |
| Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 89 | bool executionCount; // Add code to count trace executions |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 90 | int numChainingCells[CHAINING_CELL_LAST]; |
| 91 | LIR *firstChainingLIR[CHAINING_CELL_LAST]; |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 92 | RegisterScoreboard registerScoreboard; // Track register dependency |
| 93 | int optRound; // round number to tell an LIR's age |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 94 | } CompilationUnit; |
| 95 | |
| 96 | BasicBlock *dvmCompilerNewBB(BBType blockType); |
| 97 | |
| 98 | void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir); |
| 99 | |
| 100 | void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir); |
| 101 | |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 102 | void dvmCompilerInsertLIRBefore(LIR *currentLIR, LIR *newLIR); |
| 103 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 104 | /* Debug Utilities */ |
| 105 | void dvmCompilerDumpCompilationUnit(CompilationUnit *cUnit); |
| 106 | |
| 107 | #endif /* _DALVIK_VM_COMPILER_IR */ |