blob: da3a237971446431573da91f030ee7d6fd11577d [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
Elliott Hughesabe64aa2012-05-30 17:34:45 -070030/* Collect memory usage statistics */
buzbee5abfa3e2012-01-31 17:01:43 -080031//#define WITH_MEMSTATS
32
Elliott Hughes719ace42012-03-09 18:06:03 -080033struct ArenaMemBlock {
Bill Buzbeea114add2012-05-03 15:00:40 -070034 size_t blockSize;
35 size_t bytesAllocated;
36 ArenaMemBlock *next;
37 char ptr[0];
Elliott Hughes719ace42012-03-09 18:06:03 -080038};
buzbee67bf8852011-08-17 17:51:35 -070039
Elliott Hughesabe64aa2012-05-30 17:34:45 -070040void* oatNew(CompilationUnit* cUnit, size_t size, bool zero, oatAllocKind kind);
buzbee67bf8852011-08-17 17:51:35 -070041
buzbeeba938cb2012-02-03 14:47:55 -080042void oatArenaReset(CompilationUnit *cUnit);
buzbee67bf8852011-08-17 17:51:35 -070043
Elliott Hughes719ace42012-03-09 18:06:03 -080044struct GrowableList {
Elliott Hughese52e49b2012-04-02 16:05:44 -070045 GrowableList() : numAllocated(0), numUsed(0), elemList(NULL) {
46 }
47
48 size_t numAllocated;
49 size_t numUsed;
50 intptr_t* elemList;
buzbee5abfa3e2012-01-31 17:01:43 -080051#ifdef WITH_MEMSTATS
Elliott Hughese52e49b2012-04-02 16:05:44 -070052 oatListKind kind;
buzbee5abfa3e2012-01-31 17:01:43 -080053#endif
Elliott Hughes719ace42012-03-09 18:06:03 -080054};
buzbee67bf8852011-08-17 17:51:35 -070055
Elliott Hughes719ace42012-03-09 18:06:03 -080056struct GrowableListIterator {
Bill Buzbeea114add2012-05-03 15:00:40 -070057 GrowableList* list;
58 size_t idx;
59 size_t size;
Elliott Hughes719ace42012-03-09 18:06:03 -080060};
buzbee67bf8852011-08-17 17:51:35 -070061
62/*
63 * Expanding bitmap, used for tracking resources. Bits are numbered starting
64 * from zero.
65 *
66 * All operations on a BitVector are unsynchronized.
67 */
68struct ArenaBitVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070069 bool expandable; /* expand bitmap if we run out? */
70 u4 storageSize; /* current size, in 32-bit words */
71 u4* storage;
buzbee5abfa3e2012-01-31 17:01:43 -080072#ifdef WITH_MEMSTATS
Bill Buzbeea114add2012-05-03 15:00:40 -070073 oatBitMapKind kind; /* for memory use tuning */
buzbee5abfa3e2012-01-31 17:01:43 -080074#endif
buzbee67bf8852011-08-17 17:51:35 -070075};
76
77/* Handy iterator to walk through the bit positions set to 1 */
78struct ArenaBitVectorIterator {
Bill Buzbeea114add2012-05-03 15:00:40 -070079 ArenaBitVector* pBits;
80 u4 idx;
81 u4 bitSize;
buzbee67bf8852011-08-17 17:51:35 -070082};
83
84#define GET_ELEM_N(LIST, TYPE, N) (((TYPE*) LIST->elemList)[N])
85
86#define BLOCK_NAME_LEN 80
87
88/* Forward declarations */
buzbee67bf8852011-08-17 17:51:35 -070089struct BasicBlock;
90struct CompilationUnit;
Elliott Hughes7b9d9962012-04-20 18:48:18 -070091struct LIR;
92struct RegLocation;
buzbee67bf8852011-08-17 17:51:35 -070093
buzbeeba938cb2012-02-03 14:47:55 -080094void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList,
95 size_t initLength, oatListKind kind = kListMisc);
96void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList,
97 intptr_t elem);
buzbee5abfa3e2012-01-31 17:01:43 -080098void oatDeleteGrowableList(GrowableList* gList, intptr_t elem);
buzbee67bf8852011-08-17 17:51:35 -070099void oatGrowableListIteratorInit(GrowableList* gList,
100 GrowableListIterator* iterator);
101intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
102intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
103
buzbeeba938cb2012-02-03 14:47:55 -0800104ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit,
105 unsigned int startBits, bool expandable,
buzbee5abfa3e2012-01-31 17:01:43 -0800106 oatBitMapKind = kBitMapMisc);
buzbee67bf8852011-08-17 17:51:35 -0700107void oatBitVectorIteratorInit(ArenaBitVector* pBits,
108 ArenaBitVectorIterator* iterator);
109int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
buzbeeba938cb2012-02-03 14:47:55 -0800110bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num);
buzbee67bf8852011-08-17 17:51:35 -0700111bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
112void oatMarkAllBits(ArenaBitVector* pBits, bool set);
113void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);
114bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num);
115void oatClearAllBits(ArenaBitVector* pBits);
116void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits);
117void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src);
118bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
119 const ArenaBitVector* src2);
120bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
121 const ArenaBitVector* src2);
122bool oatCompareBitVectors(const ArenaBitVector* src1,
123 const ArenaBitVector* src2);
buzbeee1965672012-03-11 18:39:19 -0700124bool oatTestBitVectors(const ArenaBitVector* src1, const ArenaBitVector* src2);
buzbee67bf8852011-08-17 17:51:35 -0700125int oatCountSetBits(const ArenaBitVector* pBits);
126
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700127void oatDumpLIRInsn(CompilationUnit* cUnit, LIR* lir, unsigned char* baseAddr);
128void oatDumpResourceMask(LIR* lir, u8 mask, const char* prefix);
buzbee67bf8852011-08-17 17:51:35 -0700129void oatDumpBlockBitVector(const GrowableList* blocks, char* msg,
130 const ArenaBitVector* bv, int length);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700131void oatGetBlockName(BasicBlock* bb, char* name);
buzbeeed3e9302011-09-23 17:34:19 -0700132const char* oatGetShortyFromTargetIdx(CompilationUnit*, int);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700133void oatDumpRegLocTable(RegLocation*, int);
buzbee5abfa3e2012-01-31 17:01:43 -0800134void oatDumpMemStats(CompilationUnit* cUnit);
buzbee6969d502012-06-15 16:40:31 -0700135void oatDumpRegLoc(RegLocation loc);
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_