blob: ab9154982cee88ab18d16ba52e01434d5f630130 [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
buzbeeeaf09bc2012-11-15 14:51:41 -080020#include <stdint.h>
21#include <stddef.h>
buzbee67bf8852011-08-17 17:51:35 -070022
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080023namespace art {
24
buzbeeeaf09bc2012-11-15 14:51:41 -080025struct CompilationUnit;
26
buzbee67bc2362011-10-11 18:08:40 -070027/* Each arena page has some overhead, so take a few bytes off */
buzbeeba938cb2012-02-03 14:47:55 -080028#define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256)
buzbee67bf8852011-08-17 17:51:35 -070029
buzbeeeaf09bc2012-11-15 14:51:41 -080030/* Type of allocation for memory tuning */
31enum oatAllocKind {
32 kAllocMisc,
33 kAllocBB,
34 kAllocLIR,
35 kAllocMIR,
36 kAllocDFInfo,
37 kAllocGrowableList,
38 kAllocGrowableBitMap,
39 kAllocDalvikToSSAMap,
40 kAllocDebugInfo,
41 kAllocSuccessor,
42 kAllocRegAlloc,
43 kAllocData,
44 kAllocPredecessors,
45 kNumAllocKinds
46};
47
48/* Type of growable list for memory tuning */
49enum oatListKind {
50 kListMisc = 0,
51 kListBlockList,
52 kListSSAtoDalvikMap,
53 kListDfsOrder,
54 kListDfsPostOrder,
55 kListDomPostOrderTraversal,
56 kListThrowLaunchPads,
57 kListSuspendLaunchPads,
58 kListSwitchTables,
59 kListFillArrayData,
60 kListSuccessorBlocks,
61 kListPredecessors,
62 kNumListKinds
63};
64
65/* Type of growable bitmap for memory tuning */
66enum oatBitMapKind {
67 kBitMapMisc = 0,
68 kBitMapUse,
69 kBitMapDef,
70 kBitMapLiveIn,
71 kBitMapBMatrix,
72 kBitMapDominators,
73 kBitMapIDominated,
74 kBitMapDomFrontier,
75 kBitMapPhi,
76 kBitMapTmpBlocks,
77 kBitMapInputBlocks,
78 kBitMapRegisterV,
79 kBitMapTempSSARegisterV,
80 kBitMapNullCheck,
81 kBitMapTmpBlockV,
82 kBitMapPredecessors,
83 kNumBitMapKinds
84};
85
buzbee67bf8852011-08-17 17:51:35 -070086/* Allocate the initial memory block for arena-based allocation */
buzbeeba938cb2012-02-03 14:47:55 -080087bool oatHeapInit(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -070088
Elliott Hughesabe64aa2012-05-30 17:34:45 -070089/* Collect memory usage statistics */
buzbee5abfa3e2012-01-31 17:01:43 -080090//#define WITH_MEMSTATS
91
Elliott Hughes719ace42012-03-09 18:06:03 -080092struct ArenaMemBlock {
Bill Buzbeea114add2012-05-03 15:00:40 -070093 size_t blockSize;
94 size_t bytesAllocated;
95 ArenaMemBlock *next;
96 char ptr[0];
Elliott Hughes719ace42012-03-09 18:06:03 -080097};
buzbee67bf8852011-08-17 17:51:35 -070098
Elliott Hughesabe64aa2012-05-30 17:34:45 -070099void* oatNew(CompilationUnit* cUnit, size_t size, bool zero, oatAllocKind kind);
buzbee67bf8852011-08-17 17:51:35 -0700100
buzbeeba938cb2012-02-03 14:47:55 -0800101void oatArenaReset(CompilationUnit *cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700102
Elliott Hughes719ace42012-03-09 18:06:03 -0800103struct GrowableList {
Elliott Hughese52e49b2012-04-02 16:05:44 -0700104 GrowableList() : numAllocated(0), numUsed(0), elemList(NULL) {
105 }
106
107 size_t numAllocated;
108 size_t numUsed;
buzbeecbd6d442012-11-17 14:11:25 -0800109 uintptr_t* elemList;
buzbee5abfa3e2012-01-31 17:01:43 -0800110#ifdef WITH_MEMSTATS
Elliott Hughese52e49b2012-04-02 16:05:44 -0700111 oatListKind kind;
buzbee5abfa3e2012-01-31 17:01:43 -0800112#endif
Elliott Hughes719ace42012-03-09 18:06:03 -0800113};
buzbee67bf8852011-08-17 17:51:35 -0700114
Elliott Hughes719ace42012-03-09 18:06:03 -0800115struct GrowableListIterator {
Bill Buzbeea114add2012-05-03 15:00:40 -0700116 GrowableList* list;
117 size_t idx;
118 size_t size;
Elliott Hughes719ace42012-03-09 18:06:03 -0800119};
buzbee67bf8852011-08-17 17:51:35 -0700120
121/*
122 * Expanding bitmap, used for tracking resources. Bits are numbered starting
123 * from zero.
124 *
125 * All operations on a BitVector are unsynchronized.
126 */
127struct ArenaBitVector {
buzbeeeaf09bc2012-11-15 14:51:41 -0800128 bool expandable; /* expand bitmap if we run out? */
129 uint32_t storageSize; /* current size, in 32-bit words */
130 uint32_t* storage;
buzbee5abfa3e2012-01-31 17:01:43 -0800131#ifdef WITH_MEMSTATS
Bill Buzbeea114add2012-05-03 15:00:40 -0700132 oatBitMapKind kind; /* for memory use tuning */
buzbee5abfa3e2012-01-31 17:01:43 -0800133#endif
buzbee67bf8852011-08-17 17:51:35 -0700134};
135
136/* Handy iterator to walk through the bit positions set to 1 */
137struct ArenaBitVectorIterator {
Bill Buzbeea114add2012-05-03 15:00:40 -0700138 ArenaBitVector* pBits;
buzbeeeaf09bc2012-11-15 14:51:41 -0800139 uint32_t idx;
140 uint32_t bitSize;
buzbee67bf8852011-08-17 17:51:35 -0700141};
142
buzbeecbd6d442012-11-17 14:11:25 -0800143#define GET_ELEM_N(LIST, TYPE, N) ((reinterpret_cast<TYPE*>(LIST->elemList)[N]))
buzbee67bf8852011-08-17 17:51:35 -0700144
145#define BLOCK_NAME_LEN 80
146
147/* Forward declarations */
buzbee67bf8852011-08-17 17:51:35 -0700148struct BasicBlock;
149struct CompilationUnit;
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700150struct LIR;
151struct RegLocation;
buzbee67bf8852011-08-17 17:51:35 -0700152
buzbeeba938cb2012-02-03 14:47:55 -0800153void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList,
154 size_t initLength, oatListKind kind = kListMisc);
155void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList,
buzbeecbd6d442012-11-17 14:11:25 -0800156 uintptr_t elem);
157void oatDeleteGrowableList(GrowableList* gList, uintptr_t elem);
buzbee67bf8852011-08-17 17:51:35 -0700158void oatGrowableListIteratorInit(GrowableList* gList,
159 GrowableListIterator* iterator);
buzbeecbd6d442012-11-17 14:11:25 -0800160uintptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
161uintptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
buzbee67bf8852011-08-17 17:51:35 -0700162
buzbeeba938cb2012-02-03 14:47:55 -0800163ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit,
164 unsigned int startBits, bool expandable,
buzbee5abfa3e2012-01-31 17:01:43 -0800165 oatBitMapKind = kBitMapMisc);
buzbee67bf8852011-08-17 17:51:35 -0700166void oatBitVectorIteratorInit(ArenaBitVector* pBits,
167 ArenaBitVectorIterator* iterator);
168int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
buzbeeba938cb2012-02-03 14:47:55 -0800169bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num);
buzbee67bf8852011-08-17 17:51:35 -0700170bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
171void oatMarkAllBits(ArenaBitVector* pBits, bool set);
172void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);
173bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num);
174void oatClearAllBits(ArenaBitVector* pBits);
175void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits);
176void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src);
177bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
178 const ArenaBitVector* src2);
179bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
180 const ArenaBitVector* src2);
181bool oatCompareBitVectors(const ArenaBitVector* src1,
182 const ArenaBitVector* src2);
buzbeee1965672012-03-11 18:39:19 -0700183bool oatTestBitVectors(const ArenaBitVector* src1, const ArenaBitVector* src2);
buzbee67bf8852011-08-17 17:51:35 -0700184int oatCountSetBits(const ArenaBitVector* pBits);
185
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700186void oatDumpLIRInsn(CompilationUnit* cUnit, LIR* lir, unsigned char* baseAddr);
buzbeeeaf09bc2012-11-15 14:51:41 -0800187void oatDumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbee67bf8852011-08-17 17:51:35 -0700188void oatDumpBlockBitVector(const GrowableList* blocks, char* msg,
189 const ArenaBitVector* bv, int length);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700190void oatGetBlockName(BasicBlock* bb, char* name);
buzbeeed3e9302011-09-23 17:34:19 -0700191const char* oatGetShortyFromTargetIdx(CompilationUnit*, int);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700192void oatDumpRegLocTable(RegLocation*, int);
buzbee5abfa3e2012-01-31 17:01:43 -0800193void oatDumpMemStats(CompilationUnit* cUnit);
buzbee6969d502012-06-15 16:40:31 -0700194void oatDumpRegLoc(RegLocation loc);
buzbee67bf8852011-08-17 17:51:35 -0700195
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800196} // namespace art
197
buzbee67bf8852011-08-17 17:51:35 -0700198#endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_