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 | |
| 22 | /* Each arena page has some overhead, so take a few bytes off 8k */ |
| 23 | #define ARENA_DEFAULT_SIZE 8100 |
| 24 | |
| 25 | /* Allocate the initial memory block for arena-based allocation */ |
| 26 | bool oatHeapInit(void); |
| 27 | |
| 28 | typedef struct ArenaMemBlock { |
| 29 | size_t blockSize; |
| 30 | size_t bytesAllocated; |
| 31 | struct ArenaMemBlock *next; |
| 32 | char ptr[0]; |
| 33 | } ArenaMemBlock; |
| 34 | |
| 35 | void* oatNew(size_t size, bool zero); |
| 36 | |
| 37 | void oatArenaReset(void); |
| 38 | |
| 39 | typedef struct GrowableList { |
| 40 | size_t numAllocated; |
| 41 | size_t numUsed; |
| 42 | intptr_t *elemList; |
| 43 | } GrowableList; |
| 44 | |
| 45 | typedef struct GrowableListIterator { |
| 46 | GrowableList* list; |
| 47 | size_t idx; |
| 48 | size_t size; |
| 49 | } GrowableListIterator; |
| 50 | |
| 51 | /* |
| 52 | * Expanding bitmap, used for tracking resources. Bits are numbered starting |
| 53 | * from zero. |
| 54 | * |
| 55 | * All operations on a BitVector are unsynchronized. |
| 56 | */ |
| 57 | struct ArenaBitVector { |
| 58 | bool expandable; /* expand bitmap if we run out? */ |
| 59 | u4 storageSize; /* current size, in 32-bit words */ |
| 60 | u4* storage; |
| 61 | }; |
| 62 | |
| 63 | /* Handy iterator to walk through the bit positions set to 1 */ |
| 64 | struct ArenaBitVectorIterator { |
| 65 | ArenaBitVector* pBits; |
| 66 | u4 idx; |
| 67 | u4 bitSize; |
| 68 | }; |
| 69 | |
| 70 | #define GET_ELEM_N(LIST, TYPE, N) (((TYPE*) LIST->elemList)[N]) |
| 71 | |
| 72 | #define BLOCK_NAME_LEN 80 |
| 73 | |
| 74 | /* Forward declarations */ |
| 75 | struct LIR; |
| 76 | struct BasicBlock; |
| 77 | struct CompilationUnit; |
| 78 | |
| 79 | void oatInitGrowableList(GrowableList* gList, size_t initLength); |
| 80 | void oatInsertGrowableList(GrowableList* gList, intptr_t elem); |
| 81 | void oatGrowableListIteratorInit(GrowableList* gList, |
| 82 | GrowableListIterator* iterator); |
| 83 | intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator); |
| 84 | intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx); |
| 85 | |
| 86 | ArenaBitVector* oatAllocBitVector(unsigned int startBits, bool expandable); |
| 87 | void oatBitVectorIteratorInit(ArenaBitVector* pBits, |
| 88 | ArenaBitVectorIterator* iterator); |
| 89 | int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator); |
| 90 | bool oatSetBit(ArenaBitVector* pBits, unsigned int num); |
| 91 | bool oatClearBit(ArenaBitVector* pBits, unsigned int num); |
| 92 | void oatMarkAllBits(ArenaBitVector* pBits, bool set); |
| 93 | void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length); |
| 94 | bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num); |
| 95 | void oatClearAllBits(ArenaBitVector* pBits); |
| 96 | void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits); |
| 97 | void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src); |
| 98 | bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 99 | const ArenaBitVector* src2); |
| 100 | bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 101 | const ArenaBitVector* src2); |
| 102 | bool oatCompareBitVectors(const ArenaBitVector* src1, |
| 103 | const ArenaBitVector* src2); |
| 104 | int oatCountSetBits(const ArenaBitVector* pBits); |
| 105 | |
| 106 | void oatDumpLIRInsn(CompilationUnit* cUnit, struct LIR* lir, |
| 107 | unsigned char* baseAddr); |
| 108 | void oatDumpResourceMask(struct LIR* lir, u8 mask, const char* prefix); |
| 109 | void oatDumpBlockBitVector(const GrowableList* blocks, char* msg, |
| 110 | const ArenaBitVector* bv, int length); |
| 111 | void oatGetBlockName(struct BasicBlock* bb, char* name); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 112 | const char* oatGetShortyFromTargetIdx(CompilationUnit*, int); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame^] | 113 | void oatDumpRegLocTable(struct RegLocation*, int); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 114 | |
| 115 | #endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_ |