blob: 4a15f265e782b5078a6a4d761ee126aa153b4ae8 [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 */
buzbeeba938cb2012-02-03 14:47:55 -080025#define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256)
buzbee67bf8852011-08-17 17:51:35 -070026
27/* Allocate the initial memory block for arena-based allocation */
buzbeeba938cb2012-02-03 14:47:55 -080028bool oatHeapInit(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -070029
buzbee5abfa3e2012-01-31 17:01:43 -080030/* Collect memory usage statstics */
31//#define WITH_MEMSTATS
32
Elliott Hughes719ace42012-03-09 18:06:03 -080033struct ArenaMemBlock {
buzbee67bf8852011-08-17 17:51:35 -070034 size_t blockSize;
35 size_t bytesAllocated;
Elliott Hughes7b9d9962012-04-20 18:48:18 -070036 ArenaMemBlock *next;
buzbee67bf8852011-08-17 17:51:35 -070037 char ptr[0];
Elliott Hughes719ace42012-03-09 18:06:03 -080038};
buzbee67bf8852011-08-17 17:51:35 -070039
buzbeeba938cb2012-02-03 14:47:55 -080040void* oatNew(CompilationUnit* cUnit, size_t size, bool zero,
41 oatAllocKind kind = kAllocMisc);
buzbee67bf8852011-08-17 17:51:35 -070042
buzbeeba938cb2012-02-03 14:47:55 -080043void oatArenaReset(CompilationUnit *cUnit);
buzbee67bf8852011-08-17 17:51:35 -070044
Elliott Hughes719ace42012-03-09 18:06:03 -080045struct GrowableList {
Elliott Hughese52e49b2012-04-02 16:05:44 -070046 GrowableList() : numAllocated(0), numUsed(0), elemList(NULL) {
47 }
48
49 size_t numAllocated;
50 size_t numUsed;
51 intptr_t* elemList;
buzbee5abfa3e2012-01-31 17:01:43 -080052#ifdef WITH_MEMSTATS
Elliott Hughese52e49b2012-04-02 16:05:44 -070053 oatListKind kind;
buzbee5abfa3e2012-01-31 17:01:43 -080054#endif
Elliott Hughes719ace42012-03-09 18:06:03 -080055};
buzbee67bf8852011-08-17 17:51:35 -070056
Elliott Hughes719ace42012-03-09 18:06:03 -080057struct GrowableListIterator {
buzbee67bf8852011-08-17 17:51:35 -070058 GrowableList* list;
59 size_t idx;
60 size_t size;
Elliott Hughes719ace42012-03-09 18:06:03 -080061};
buzbee67bf8852011-08-17 17:51:35 -070062
63/*
64 * Expanding bitmap, used for tracking resources. Bits are numbered starting
65 * from zero.
66 *
67 * All operations on a BitVector are unsynchronized.
68 */
69struct ArenaBitVector {
70 bool expandable; /* expand bitmap if we run out? */
71 u4 storageSize; /* current size, in 32-bit words */
72 u4* storage;
buzbee5abfa3e2012-01-31 17:01:43 -080073#ifdef WITH_MEMSTATS
74 oatBitMapKind kind; /* for memory use tuning */
75#endif
buzbee67bf8852011-08-17 17:51:35 -070076};
77
78/* Handy iterator to walk through the bit positions set to 1 */
79struct ArenaBitVectorIterator {
80 ArenaBitVector* pBits;
81 u4 idx;
82 u4 bitSize;
83};
84
85#define GET_ELEM_N(LIST, TYPE, N) (((TYPE*) LIST->elemList)[N])
86
87#define BLOCK_NAME_LEN 80
88
89/* Forward declarations */
buzbee67bf8852011-08-17 17:51:35 -070090struct BasicBlock;
91struct CompilationUnit;
Elliott Hughes7b9d9962012-04-20 18:48:18 -070092struct LIR;
93struct RegLocation;
buzbee67bf8852011-08-17 17:51:35 -070094
buzbeeba938cb2012-02-03 14:47:55 -080095void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList,
96 size_t initLength, oatListKind kind = kListMisc);
97void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList,
98 intptr_t elem);
buzbee5abfa3e2012-01-31 17:01:43 -080099void oatDeleteGrowableList(GrowableList* gList, intptr_t elem);
buzbee67bf8852011-08-17 17:51:35 -0700100void oatGrowableListIteratorInit(GrowableList* gList,
101 GrowableListIterator* iterator);
102intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
103intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
104
buzbeeba938cb2012-02-03 14:47:55 -0800105ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit,
106 unsigned int startBits, bool expandable,
buzbee5abfa3e2012-01-31 17:01:43 -0800107 oatBitMapKind = kBitMapMisc);
buzbee67bf8852011-08-17 17:51:35 -0700108void oatBitVectorIteratorInit(ArenaBitVector* pBits,
109 ArenaBitVectorIterator* iterator);
110int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
buzbeeba938cb2012-02-03 14:47:55 -0800111bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num);
buzbee67bf8852011-08-17 17:51:35 -0700112bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
113void oatMarkAllBits(ArenaBitVector* pBits, bool set);
114void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);
115bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num);
116void oatClearAllBits(ArenaBitVector* pBits);
117void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits);
118void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src);
119bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
120 const ArenaBitVector* src2);
121bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
122 const ArenaBitVector* src2);
123bool oatCompareBitVectors(const ArenaBitVector* src1,
124 const ArenaBitVector* src2);
buzbeee1965672012-03-11 18:39:19 -0700125bool oatTestBitVectors(const ArenaBitVector* src1, const ArenaBitVector* src2);
buzbee67bf8852011-08-17 17:51:35 -0700126int oatCountSetBits(const ArenaBitVector* pBits);
127
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700128void oatDumpLIRInsn(CompilationUnit* cUnit, LIR* lir, unsigned char* baseAddr);
129void oatDumpResourceMask(LIR* lir, u8 mask, const char* prefix);
buzbee67bf8852011-08-17 17:51:35 -0700130void oatDumpBlockBitVector(const GrowableList* blocks, char* msg,
131 const ArenaBitVector* bv, int length);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700132void oatGetBlockName(BasicBlock* bb, char* name);
buzbeeed3e9302011-09-23 17:34:19 -0700133const char* oatGetShortyFromTargetIdx(CompilationUnit*, int);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700134void oatDumpRegLocTable(RegLocation*, int);
buzbee5abfa3e2012-01-31 17:01:43 -0800135void oatDumpMemStats(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700136
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800137} // namespace art
138
buzbee67bf8852011-08-17 17:51:35 -0700139#endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_