1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | #ifndef CompilerBitSetTraits_HPP_DEFINED |
6 | #define CompilerBitSetTraits_HPP_DEFINED 1 |
7 | |
8 | #include "compilerbitsettraits.h" |
9 | #include "compiler.h" |
10 | |
11 | /////////////////////////////////////////////////////////////////////////////// |
12 | // |
13 | // CompAllocBitSetTraits |
14 | // |
15 | /////////////////////////////////////////////////////////////////////////////// |
16 | |
17 | // static |
18 | void* CompAllocBitSetTraits::Alloc(Compiler* comp, size_t byteSize) |
19 | { |
20 | return comp->getAllocator(CMK_bitset).allocate<char>(byteSize); |
21 | } |
22 | |
23 | #ifdef DEBUG |
24 | // static |
25 | void* CompAllocBitSetTraits::DebugAlloc(Compiler* comp, size_t byteSize) |
26 | { |
27 | return comp->getAllocator(CMK_DebugOnly).allocate<char>(byteSize); |
28 | } |
29 | #endif // DEBUG |
30 | |
31 | /////////////////////////////////////////////////////////////////////////////// |
32 | // |
33 | // TrackedVarBitSetTraits |
34 | // |
35 | /////////////////////////////////////////////////////////////////////////////// |
36 | |
37 | // static |
38 | unsigned TrackedVarBitSetTraits::GetSize(Compiler* comp) |
39 | { |
40 | return comp->lvaTrackedCount; |
41 | } |
42 | |
43 | // static |
44 | unsigned TrackedVarBitSetTraits::GetArrSize(Compiler* comp, unsigned elemSize) |
45 | { |
46 | assert(elemSize == sizeof(size_t)); |
47 | return comp->lvaTrackedCountInSizeTUnits; |
48 | } |
49 | |
50 | // static |
51 | unsigned TrackedVarBitSetTraits::GetEpoch(Compiler* comp) |
52 | { |
53 | return comp->GetCurLVEpoch(); |
54 | } |
55 | |
56 | // static |
57 | BitSetSupport::BitSetOpCounter* TrackedVarBitSetTraits::GetOpCounter(Compiler* comp) |
58 | { |
59 | #if VARSET_COUNTOPS |
60 | return &Compiler::m_varsetOpCounter; |
61 | #else |
62 | return nullptr; |
63 | #endif |
64 | } |
65 | |
66 | /////////////////////////////////////////////////////////////////////////////// |
67 | // |
68 | // AllVarBitSetTraits |
69 | // |
70 | /////////////////////////////////////////////////////////////////////////////// |
71 | |
72 | // static |
73 | unsigned AllVarBitSetTraits::GetSize(Compiler* comp) |
74 | { |
75 | return min(comp->lvaCount, lclMAX_ALLSET_TRACKED); |
76 | } |
77 | |
78 | // static |
79 | unsigned AllVarBitSetTraits::GetArrSize(Compiler* comp, unsigned elemSize) |
80 | { |
81 | return roundUp(GetSize(comp), elemSize); |
82 | } |
83 | |
84 | // static |
85 | unsigned AllVarBitSetTraits::GetEpoch(Compiler* comp) |
86 | { |
87 | return GetSize(comp); |
88 | } |
89 | |
90 | // static |
91 | BitSetSupport::BitSetOpCounter* AllVarBitSetTraits::GetOpCounter(Compiler* comp) |
92 | { |
93 | #if ALLVARSET_COUNTOPS |
94 | return &Compiler::m_allvarsetOpCounter; |
95 | #else |
96 | return nullptr; |
97 | #endif |
98 | } |
99 | |
100 | /////////////////////////////////////////////////////////////////////////////// |
101 | // |
102 | // BasicBlockBitSetTraits |
103 | // |
104 | /////////////////////////////////////////////////////////////////////////////// |
105 | |
106 | // static |
107 | unsigned BasicBlockBitSetTraits::GetSize(Compiler* comp) |
108 | { |
109 | return comp->fgCurBBEpochSize; |
110 | } |
111 | |
112 | // static |
113 | unsigned BasicBlockBitSetTraits::GetArrSize(Compiler* comp, unsigned elemSize) |
114 | { |
115 | // Assert that the epoch has been initialized. This is a convenient place to assert this because |
116 | // GetArrSize() is called for every function, via IsShort(). |
117 | assert(GetEpoch(comp) != 0); |
118 | |
119 | assert(elemSize == sizeof(size_t)); |
120 | return comp->fgBBSetCountInSizeTUnits; // This is precomputed to avoid doing math every time this function is called |
121 | } |
122 | |
123 | // static |
124 | unsigned BasicBlockBitSetTraits::GetEpoch(Compiler* comp) |
125 | { |
126 | return comp->GetCurBasicBlockEpoch(); |
127 | } |
128 | |
129 | // static |
130 | BitSetSupport::BitSetOpCounter* BasicBlockBitSetTraits::GetOpCounter(Compiler* comp) |
131 | { |
132 | return nullptr; |
133 | } |
134 | |
135 | /////////////////////////////////////////////////////////////////////////////// |
136 | // |
137 | // BitVecTraits |
138 | // |
139 | /////////////////////////////////////////////////////////////////////////////// |
140 | |
141 | // static |
142 | void* BitVecTraits::Alloc(BitVecTraits* b, size_t byteSize) |
143 | { |
144 | return b->comp->getAllocator(CMK_bitset).allocate<char>(byteSize); |
145 | } |
146 | |
147 | #ifdef DEBUG |
148 | // static |
149 | void* BitVecTraits::DebugAlloc(BitVecTraits* b, size_t byteSize) |
150 | { |
151 | return b->comp->getAllocator(CMK_DebugOnly).allocate<char>(byteSize); |
152 | } |
153 | #endif // DEBUG |
154 | |
155 | // static |
156 | unsigned BitVecTraits::GetSize(BitVecTraits* b) |
157 | { |
158 | return b->size; |
159 | } |
160 | |
161 | // static |
162 | unsigned BitVecTraits::GetArrSize(BitVecTraits* b, unsigned elemSize) |
163 | { |
164 | assert(elemSize == sizeof(size_t)); |
165 | unsigned elemBits = 8 * elemSize; |
166 | return roundUp(b->size, elemBits) / elemBits; |
167 | } |
168 | |
169 | // static |
170 | unsigned BitVecTraits::GetEpoch(BitVecTraits* b) |
171 | { |
172 | return b->size; |
173 | } |
174 | |
175 | // static |
176 | BitSetSupport::BitSetOpCounter* BitVecTraits::GetOpCounter(BitVecTraits* b) |
177 | { |
178 | return nullptr; |
179 | } |
180 | |
181 | #endif // CompilerBitSetTraits_HPP_DEFINED |
182 | |