blob: ba449a4d6081ddc8a45503f0625b98e9d1bcca13 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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 Hughes11d1b0c2012-01-23 16:57:47 -080022namespace art {
23
buzbee67bc2362011-10-11 18:08:40 -070024/* Each arena page has some overhead, so take a few bytes off */
25#define ARENA_DEFAULT_SIZE ((256 * 1024) - 256)
buzbee67bf8852011-08-17 17:51:35 -070026
27/* Allocate the initial memory block for arena-based allocation */
28bool oatHeapInit(void);
29
buzbee5abfa3e2012-01-31 17:01:43 -080030/* Collect memory usage statstics */
31//#define WITH_MEMSTATS
32
buzbee67bf8852011-08-17 17:51:35 -070033typedef struct ArenaMemBlock {
34 size_t blockSize;
35 size_t bytesAllocated;
36 struct ArenaMemBlock *next;
37 char ptr[0];
38} ArenaMemBlock;
39
buzbee5abfa3e2012-01-31 17:01:43 -080040void* oatNew(size_t size, bool zero, oatAllocKind kind = kAllocMisc);
buzbee67bf8852011-08-17 17:51:35 -070041
42void oatArenaReset(void);
43
44typedef struct GrowableList {
45 size_t numAllocated;
46 size_t numUsed;
47 intptr_t *elemList;
buzbee5abfa3e2012-01-31 17:01:43 -080048#ifdef WITH_MEMSTATS
49 oatListKind kind;
50#endif
buzbee67bf8852011-08-17 17:51:35 -070051} GrowableList;
52
53typedef struct GrowableListIterator {
54 GrowableList* list;
55 size_t idx;
56 size_t size;
57} GrowableListIterator;
58
59/*
60 * Expanding bitmap, used for tracking resources. Bits are numbered starting
61 * from zero.
62 *
63 * All operations on a BitVector are unsynchronized.
64 */
65struct ArenaBitVector {
66 bool expandable; /* expand bitmap if we run out? */
67 u4 storageSize; /* current size, in 32-bit words */
68 u4* storage;
buzbee5abfa3e2012-01-31 17:01:43 -080069#ifdef WITH_MEMSTATS
70 oatBitMapKind kind; /* for memory use tuning */
71#endif
buzbee67bf8852011-08-17 17:51:35 -070072};
73
74/* Handy iterator to walk through the bit positions set to 1 */
75struct ArenaBitVectorIterator {
76 ArenaBitVector* pBits;
77 u4 idx;
78 u4 bitSize;
79};
80
81#define GET_ELEM_N(LIST, TYPE, N) (((TYPE*) LIST->elemList)[N])
82
83#define BLOCK_NAME_LEN 80
84
85/* Forward declarations */
86struct LIR;
87struct BasicBlock;
88struct CompilationUnit;
89
buzbee5abfa3e2012-01-31 17:01:43 -080090void oatInitGrowableList(GrowableList* gList, size_t initLength,
91 oatListKind kind = kListMisc);
buzbee67bf8852011-08-17 17:51:35 -070092void oatInsertGrowableList(GrowableList* gList, intptr_t elem);
buzbee5abfa3e2012-01-31 17:01:43 -080093void oatDeleteGrowableList(GrowableList* gList, intptr_t elem);
buzbee67bf8852011-08-17 17:51:35 -070094void oatGrowableListIteratorInit(GrowableList* gList,
95 GrowableListIterator* iterator);
96intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
97intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
98
buzbee5abfa3e2012-01-31 17:01:43 -080099ArenaBitVector* oatAllocBitVector(unsigned int startBits, bool expandable,
100 oatBitMapKind = kBitMapMisc);
buzbee67bf8852011-08-17 17:51:35 -0700101void oatBitVectorIteratorInit(ArenaBitVector* pBits,
102 ArenaBitVectorIterator* iterator);
103int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
104bool oatSetBit(ArenaBitVector* pBits, unsigned int num);
105bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
106void oatMarkAllBits(ArenaBitVector* pBits, bool set);
107void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);
108bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num);
109void oatClearAllBits(ArenaBitVector* pBits);
110void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits);
111void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src);
112bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
113 const ArenaBitVector* src2);
114bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
115 const ArenaBitVector* src2);
116bool oatCompareBitVectors(const ArenaBitVector* src1,
117 const ArenaBitVector* src2);
118int oatCountSetBits(const ArenaBitVector* pBits);
119
120void oatDumpLIRInsn(CompilationUnit* cUnit, struct LIR* lir,
121 unsigned char* baseAddr);
122void oatDumpResourceMask(struct LIR* lir, u8 mask, const char* prefix);
123void oatDumpBlockBitVector(const GrowableList* blocks, char* msg,
124 const ArenaBitVector* bv, int length);
125void oatGetBlockName(struct BasicBlock* bb, char* name);
buzbeeed3e9302011-09-23 17:34:19 -0700126const char* oatGetShortyFromTargetIdx(CompilationUnit*, int);
buzbee6181f792011-09-29 11:14:04 -0700127void oatDumpRegLocTable(struct RegLocation*, int);
buzbee5abfa3e2012-01-31 17:01:43 -0800128void oatDumpMemStats(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700129
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800130} // namespace art
131
buzbee67bf8852011-08-17 17:51:35 -0700132#endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_