buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 ART_SRC_COMPILER_COMPILER_UTILITY_H_ |
| 18 | #define ART_SRC_COMPILER_COMPILER_UTILITY_H_ |
| 19 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <stddef.h> |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 22 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 25 | struct CompilationUnit; |
| 26 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 27 | /* Each arena page has some overhead, so take a few bytes off */ |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 28 | #define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 29 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 30 | /* Type of allocation for memory tuning */ |
| 31 | enum oatAllocKind { |
| 32 | kAllocMisc, |
| 33 | kAllocBB, |
| 34 | kAllocLIR, |
| 35 | kAllocMIR, |
| 36 | kAllocDFInfo, |
| 37 | kAllocGrowableList, |
| 38 | kAllocGrowableBitMap, |
| 39 | kAllocDalvikToSSAMap, |
| 40 | kAllocDebugInfo, |
| 41 | kAllocSuccessor, |
| 42 | kAllocRegAlloc, |
| 43 | kAllocData, |
| 44 | kAllocPredecessors, |
| 45 | kNumAllocKinds |
| 46 | }; |
| 47 | |
| 48 | /* Type of growable list for memory tuning */ |
| 49 | enum oatListKind { |
| 50 | kListMisc = 0, |
| 51 | kListBlockList, |
| 52 | kListSSAtoDalvikMap, |
| 53 | kListDfsOrder, |
| 54 | kListDfsPostOrder, |
| 55 | kListDomPostOrderTraversal, |
| 56 | kListThrowLaunchPads, |
| 57 | kListSuspendLaunchPads, |
| 58 | kListSwitchTables, |
| 59 | kListFillArrayData, |
| 60 | kListSuccessorBlocks, |
| 61 | kListPredecessors, |
| 62 | kNumListKinds |
| 63 | }; |
| 64 | |
| 65 | /* Type of growable bitmap for memory tuning */ |
| 66 | enum oatBitMapKind { |
| 67 | kBitMapMisc = 0, |
| 68 | kBitMapUse, |
| 69 | kBitMapDef, |
| 70 | kBitMapLiveIn, |
| 71 | kBitMapBMatrix, |
| 72 | kBitMapDominators, |
| 73 | kBitMapIDominated, |
| 74 | kBitMapDomFrontier, |
| 75 | kBitMapPhi, |
| 76 | kBitMapTmpBlocks, |
| 77 | kBitMapInputBlocks, |
| 78 | kBitMapRegisterV, |
| 79 | kBitMapTempSSARegisterV, |
| 80 | kBitMapNullCheck, |
| 81 | kBitMapTmpBlockV, |
| 82 | kBitMapPredecessors, |
| 83 | kNumBitMapKinds |
| 84 | }; |
| 85 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 86 | /* Allocate the initial memory block for arena-based allocation */ |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 87 | bool oatHeapInit(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 88 | |
Elliott Hughes | abe64aa | 2012-05-30 17:34:45 -0700 | [diff] [blame] | 89 | /* Collect memory usage statistics */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 90 | //#define WITH_MEMSTATS |
| 91 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 92 | struct ArenaMemBlock { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 93 | size_t blockSize; |
| 94 | size_t bytesAllocated; |
| 95 | ArenaMemBlock *next; |
| 96 | char ptr[0]; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 97 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 98 | |
Elliott Hughes | abe64aa | 2012-05-30 17:34:45 -0700 | [diff] [blame] | 99 | void* oatNew(CompilationUnit* cUnit, size_t size, bool zero, oatAllocKind kind); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 100 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 101 | void oatArenaReset(CompilationUnit *cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 102 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 103 | struct GrowableList { |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 104 | GrowableList() : numAllocated(0), numUsed(0), elemList(NULL) { |
| 105 | } |
| 106 | |
| 107 | size_t numAllocated; |
| 108 | size_t numUsed; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame^] | 109 | uintptr_t* elemList; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 110 | #ifdef WITH_MEMSTATS |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 111 | oatListKind kind; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 112 | #endif |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 113 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 114 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 115 | struct GrowableListIterator { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 116 | GrowableList* list; |
| 117 | size_t idx; |
| 118 | size_t size; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 119 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Expanding bitmap, used for tracking resources. Bits are numbered starting |
| 123 | * from zero. |
| 124 | * |
| 125 | * All operations on a BitVector are unsynchronized. |
| 126 | */ |
| 127 | struct ArenaBitVector { |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 128 | bool expandable; /* expand bitmap if we run out? */ |
| 129 | uint32_t storageSize; /* current size, in 32-bit words */ |
| 130 | uint32_t* storage; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 131 | #ifdef WITH_MEMSTATS |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 132 | oatBitMapKind kind; /* for memory use tuning */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 133 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | /* Handy iterator to walk through the bit positions set to 1 */ |
| 137 | struct ArenaBitVectorIterator { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 138 | ArenaBitVector* pBits; |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 139 | uint32_t idx; |
| 140 | uint32_t bitSize; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame^] | 143 | #define GET_ELEM_N(LIST, TYPE, N) ((reinterpret_cast<TYPE*>(LIST->elemList)[N])) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 144 | |
| 145 | #define BLOCK_NAME_LEN 80 |
| 146 | |
| 147 | /* Forward declarations */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 148 | struct BasicBlock; |
| 149 | struct CompilationUnit; |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 150 | struct LIR; |
| 151 | struct RegLocation; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 152 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 153 | void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList, |
| 154 | size_t initLength, oatListKind kind = kListMisc); |
| 155 | void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList, |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame^] | 156 | uintptr_t elem); |
| 157 | void oatDeleteGrowableList(GrowableList* gList, uintptr_t elem); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 158 | void oatGrowableListIteratorInit(GrowableList* gList, |
| 159 | GrowableListIterator* iterator); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame^] | 160 | uintptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator); |
| 161 | uintptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 162 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 163 | ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit, |
| 164 | unsigned int startBits, bool expandable, |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 165 | oatBitMapKind = kBitMapMisc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 166 | void oatBitVectorIteratorInit(ArenaBitVector* pBits, |
| 167 | ArenaBitVectorIterator* iterator); |
| 168 | int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 169 | bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 170 | bool oatClearBit(ArenaBitVector* pBits, unsigned int num); |
| 171 | void oatMarkAllBits(ArenaBitVector* pBits, bool set); |
| 172 | void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length); |
| 173 | bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num); |
| 174 | void oatClearAllBits(ArenaBitVector* pBits); |
| 175 | void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits); |
| 176 | void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src); |
| 177 | bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 178 | const ArenaBitVector* src2); |
| 179 | bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 180 | const ArenaBitVector* src2); |
| 181 | bool oatCompareBitVectors(const ArenaBitVector* src1, |
| 182 | const ArenaBitVector* src2); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 183 | bool oatTestBitVectors(const ArenaBitVector* src1, const ArenaBitVector* src2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 184 | int oatCountSetBits(const ArenaBitVector* pBits); |
| 185 | |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 186 | void oatDumpLIRInsn(CompilationUnit* cUnit, LIR* lir, unsigned char* baseAddr); |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 187 | void oatDumpResourceMask(LIR* lir, uint64_t mask, const char* prefix); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 188 | void oatDumpBlockBitVector(const GrowableList* blocks, char* msg, |
| 189 | const ArenaBitVector* bv, int length); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 190 | void oatGetBlockName(BasicBlock* bb, char* name); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 191 | const char* oatGetShortyFromTargetIdx(CompilationUnit*, int); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 192 | void oatDumpRegLocTable(RegLocation*, int); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 193 | void oatDumpMemStats(CompilationUnit* cUnit); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 194 | void oatDumpRegLoc(RegLocation loc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 195 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 196 | } // namespace art |
| 197 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 198 | #endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_ |