blob: ffc216074db63ce521c6cfff1898e9042d5643ee [file] [log] [blame]
buzbee862a7602013-04-05 10:58:54 -07001/*
2 * Copyright (C) 2013 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_DEX_COMPILER_ARENA_BIT_VECTOR_H_
18#define ART_SRC_COMPILER_DEX_COMPILER_ARENA_BIT_VECTOR_H_
19
20#include <stdint.h>
21#include <stddef.h>
22#include "compiler_enums.h"
23#include "arena_allocator.h"
24
25namespace art {
26
27// Type of growable bitmap for memory tuning.
28enum OatBitMapKind {
29 kBitMapMisc = 0,
30 kBitMapUse,
31 kBitMapDef,
32 kBitMapLiveIn,
33 kBitMapBMatrix,
34 kBitMapDominators,
35 kBitMapIDominated,
36 kBitMapDomFrontier,
37 kBitMapPhi,
38 kBitMapTmpBlocks,
39 kBitMapInputBlocks,
40 kBitMapRegisterV,
41 kBitMapTempSSARegisterV,
42 kBitMapNullCheck,
43 kBitMapTmpBlockV,
44 kBitMapPredecessors,
45 kNumBitMapKinds
46};
47
48/*
49 * Expanding bitmap, used for tracking resources. Bits are numbered starting
50 * from zero. All operations on a BitVector are unsynchronized.
51 */
52class ArenaBitVector {
53 public:
54
55 class Iterator {
56 public:
57 Iterator(ArenaBitVector* bit_vector)
58 : p_bits_(bit_vector),
59 bit_storage_(bit_vector->GetRawStorage()),
60 bit_index_(0),
61 bit_size_(p_bits_->storage_size_ * sizeof(uint32_t) * 8) {};
62
63 int Next(); // Returns -1 when no next.
64
65 static void* operator new(size_t size, ArenaAllocator* arena) {
66 return arena->NewMem(sizeof(ArenaBitVector::Iterator), true,
67 ArenaAllocator::kAllocGrowableBitMap);
68 };
69 static void operator delete(void* p) {}; // Nop.
70
71 private:
72 ArenaBitVector* const p_bits_;
73 uint32_t* const bit_storage_;
74 uint32_t bit_index_; // Current index (size in bits).
75 const uint32_t bit_size_; // Size of vector in bits.
76 };
77
78 ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits, bool expandable,
79 OatBitMapKind kind = kBitMapMisc);
80 ~ArenaBitVector() {};
81
82 static void* operator new( size_t size, ArenaAllocator* arena) {
83 return arena->NewMem(sizeof(ArenaBitVector), true, ArenaAllocator::kAllocGrowableBitMap);
84 }
85 static void operator delete(void* p) {}; // Nop.
86
87 void SetBit(unsigned int num);
88 void ClearBit(unsigned int num);
89 void MarkAllBits(bool set);
90 void DebugBitVector(char* msg, int length);
91 bool IsBitSet(unsigned int num);
92 void ClearAllBits();
93 void SetInitialBits(unsigned int num_bits);
94 void Copy(ArenaBitVector* src);
95 void Intersect(const ArenaBitVector* src2);
96 void Union(const ArenaBitVector* src);
97 bool Equal(const ArenaBitVector* src);
98 int NumSetBits();
99
100 uint32_t GetStorageSize() const { return storage_size_; }
101 bool IsExpandable() const { return expandable_; }
102 uint32_t GetRawStorageWord(size_t idx) const { return storage_[idx]; }
103 uint32_t* GetRawStorage() { return storage_; }
104
105 private:
106 ArenaAllocator* const arena_;
107 const bool expandable_; // expand bitmap if we run out?
108 const OatBitMapKind kind_; // for memory use tuning.
109 uint32_t storage_size_; // current size, in 32-bit words.
110 uint32_t* storage_;
111};
112
113
114} // namespace art
115
116#endif // ART_SRC_COMPILER_DEX_COMPILER_ARENA_BIT_VECTOR_H_