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