blob: c0dcaf76c1747b2c4add347fc16a453651ebc4ec [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
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 */
26bool oatHeapInit(void);
27
28typedef struct ArenaMemBlock {
29 size_t blockSize;
30 size_t bytesAllocated;
31 struct ArenaMemBlock *next;
32 char ptr[0];
33} ArenaMemBlock;
34
35void* oatNew(size_t size, bool zero);
36
37void oatArenaReset(void);
38
39typedef struct GrowableList {
40 size_t numAllocated;
41 size_t numUsed;
42 intptr_t *elemList;
43} GrowableList;
44
45typedef 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 */
57struct 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 */
64struct 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 */
75struct LIR;
76struct BasicBlock;
77struct CompilationUnit;
78
79void oatInitGrowableList(GrowableList* gList, size_t initLength);
80void oatInsertGrowableList(GrowableList* gList, intptr_t elem);
81void oatGrowableListIteratorInit(GrowableList* gList,
82 GrowableListIterator* iterator);
83intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
84intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
85
86ArenaBitVector* oatAllocBitVector(unsigned int startBits, bool expandable);
87void oatBitVectorIteratorInit(ArenaBitVector* pBits,
88 ArenaBitVectorIterator* iterator);
89int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
90bool oatSetBit(ArenaBitVector* pBits, unsigned int num);
91bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
92void oatMarkAllBits(ArenaBitVector* pBits, bool set);
93void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);
94bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num);
95void oatClearAllBits(ArenaBitVector* pBits);
96void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits);
97void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src);
98bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
99 const ArenaBitVector* src2);
100bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
101 const ArenaBitVector* src2);
102bool oatCompareBitVectors(const ArenaBitVector* src1,
103 const ArenaBitVector* src2);
104int oatCountSetBits(const ArenaBitVector* pBits);
105
106void oatDumpLIRInsn(CompilationUnit* cUnit, struct LIR* lir,
107 unsigned char* baseAddr);
108void oatDumpResourceMask(struct LIR* lir, u8 mask, const char* prefix);
109void oatDumpBlockBitVector(const GrowableList* blocks, char* msg,
110 const ArenaBitVector* bv, int length);
111void oatGetBlockName(struct BasicBlock* bb, char* name);
buzbeeed3e9302011-09-23 17:34:19 -0700112const char* oatGetShortyFromTargetIdx(CompilationUnit*, int);
buzbee6181f792011-09-29 11:14:04 -0700113void oatDumpRegLocTable(struct RegLocation*, int);
buzbee67bf8852011-08-17 17:51:35 -0700114
115#endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_