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 | |
| 20 | #include "Dalvik.h" |
| 21 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 22 | namespace art { |
| 23 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 24 | /* Each arena page has some overhead, so take a few bytes off */ |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 25 | #define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 26 | |
| 27 | /* Allocate the initial memory block for arena-based allocation */ |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 28 | bool oatHeapInit(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 29 | |
Elliott Hughes | abe64aa | 2012-05-30 17:34:45 -0700 | [diff] [blame] | 30 | /* Collect memory usage statistics */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 31 | //#define WITH_MEMSTATS |
| 32 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 33 | struct ArenaMemBlock { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 34 | size_t blockSize; |
| 35 | size_t bytesAllocated; |
| 36 | ArenaMemBlock *next; |
| 37 | char ptr[0]; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 38 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 39 | |
Elliott Hughes | abe64aa | 2012-05-30 17:34:45 -0700 | [diff] [blame] | 40 | void* oatNew(CompilationUnit* cUnit, size_t size, bool zero, oatAllocKind kind); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 41 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 42 | void oatArenaReset(CompilationUnit *cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 43 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 44 | struct GrowableList { |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 45 | GrowableList() : numAllocated(0), numUsed(0), elemList(NULL) { |
| 46 | } |
| 47 | |
| 48 | size_t numAllocated; |
| 49 | size_t numUsed; |
| 50 | intptr_t* elemList; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 51 | #ifdef WITH_MEMSTATS |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 52 | oatListKind kind; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 53 | #endif |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 54 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 55 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 56 | struct GrowableListIterator { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 57 | GrowableList* list; |
| 58 | size_t idx; |
| 59 | size_t size; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 60 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Expanding bitmap, used for tracking resources. Bits are numbered starting |
| 64 | * from zero. |
| 65 | * |
| 66 | * All operations on a BitVector are unsynchronized. |
| 67 | */ |
| 68 | struct ArenaBitVector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 69 | bool expandable; /* expand bitmap if we run out? */ |
| 70 | u4 storageSize; /* current size, in 32-bit words */ |
| 71 | u4* storage; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 72 | #ifdef WITH_MEMSTATS |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 73 | oatBitMapKind kind; /* for memory use tuning */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 74 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* Handy iterator to walk through the bit positions set to 1 */ |
| 78 | struct ArenaBitVectorIterator { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 79 | ArenaBitVector* pBits; |
| 80 | u4 idx; |
| 81 | u4 bitSize; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #define GET_ELEM_N(LIST, TYPE, N) (((TYPE*) LIST->elemList)[N]) |
| 85 | |
| 86 | #define BLOCK_NAME_LEN 80 |
| 87 | |
| 88 | /* Forward declarations */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 89 | struct BasicBlock; |
| 90 | struct CompilationUnit; |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 91 | struct LIR; |
| 92 | struct RegLocation; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 93 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 94 | void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList, |
| 95 | size_t initLength, oatListKind kind = kListMisc); |
| 96 | void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList, |
| 97 | intptr_t elem); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 98 | void oatDeleteGrowableList(GrowableList* gList, intptr_t elem); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 99 | void oatGrowableListIteratorInit(GrowableList* gList, |
| 100 | GrowableListIterator* iterator); |
| 101 | intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator); |
| 102 | intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx); |
| 103 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 104 | ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit, |
| 105 | unsigned int startBits, bool expandable, |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 106 | oatBitMapKind = kBitMapMisc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | void oatBitVectorIteratorInit(ArenaBitVector* pBits, |
| 108 | ArenaBitVectorIterator* iterator); |
| 109 | int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 110 | bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 111 | bool oatClearBit(ArenaBitVector* pBits, unsigned int num); |
| 112 | void oatMarkAllBits(ArenaBitVector* pBits, bool set); |
| 113 | void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length); |
| 114 | bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num); |
| 115 | void oatClearAllBits(ArenaBitVector* pBits); |
| 116 | void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits); |
| 117 | void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src); |
| 118 | bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 119 | const ArenaBitVector* src2); |
| 120 | bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 121 | const ArenaBitVector* src2); |
| 122 | bool oatCompareBitVectors(const ArenaBitVector* src1, |
| 123 | const ArenaBitVector* src2); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 124 | bool oatTestBitVectors(const ArenaBitVector* src1, const ArenaBitVector* src2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 125 | int oatCountSetBits(const ArenaBitVector* pBits); |
| 126 | |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 127 | void oatDumpLIRInsn(CompilationUnit* cUnit, LIR* lir, unsigned char* baseAddr); |
| 128 | void oatDumpResourceMask(LIR* lir, u8 mask, const char* prefix); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 129 | void oatDumpBlockBitVector(const GrowableList* blocks, char* msg, |
| 130 | const ArenaBitVector* bv, int length); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 131 | void oatGetBlockName(BasicBlock* bb, char* name); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 132 | const char* oatGetShortyFromTargetIdx(CompilationUnit*, int); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 133 | void oatDumpRegLocTable(RegLocation*, int); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 134 | void oatDumpMemStats(CompilationUnit* cUnit); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 135 | void oatDumpRegLoc(RegLocation loc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 136 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 137 | } // namespace art |
| 138 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 139 | #endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_ |