| 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_DEFINED |
| 6 | #define CompilerBitSetTraits_DEFINED 1 |
| 7 | |
| 8 | #include "bitset.h" |
| 9 | #include "compiler.h" |
| 10 | #include "bitsetasshortlong.h" |
| 11 | |
| 12 | /////////////////////////////////////////////////////////////////////////////// |
| 13 | // |
| 14 | // CompAllocBitSetTraits: a base class for other BitSet traits classes. |
| 15 | // |
| 16 | // The classes in this file define "BitSetTraits" arguments to the "BitSetOps" type, ones that assume that |
| 17 | // Compiler* is the "Env" type. |
| 18 | // |
| 19 | // This class just wraps the compiler's allocator. |
| 20 | // |
| 21 | class CompAllocBitSetTraits |
| 22 | { |
| 23 | public: |
| 24 | static inline void* Alloc(Compiler* comp, size_t byteSize); |
| 25 | |
| 26 | #ifdef DEBUG |
| 27 | static inline void* DebugAlloc(Compiler* comp, size_t byteSize); |
| 28 | #endif // DEBUG |
| 29 | }; |
| 30 | |
| 31 | /////////////////////////////////////////////////////////////////////////////// |
| 32 | // |
| 33 | // TrackedVarBitSetTraits |
| 34 | // |
| 35 | // This class is customizes the bit set to represent sets of tracked local vars. |
| 36 | // The size of the bitset is determined by the # of tracked locals (up to some internal |
| 37 | // maximum), and the Compiler* tracks the tracked local epochs. |
| 38 | // |
| 39 | class TrackedVarBitSetTraits : public CompAllocBitSetTraits |
| 40 | { |
| 41 | public: |
| 42 | static inline unsigned GetSize(Compiler* comp); |
| 43 | |
| 44 | static inline unsigned GetArrSize(Compiler* comp, unsigned elemSize); |
| 45 | |
| 46 | static inline unsigned GetEpoch(class Compiler* comp); |
| 47 | |
| 48 | static inline BitSetSupport::BitSetOpCounter* GetOpCounter(Compiler* comp); |
| 49 | }; |
| 50 | |
| 51 | /////////////////////////////////////////////////////////////////////////////// |
| 52 | // |
| 53 | // AllVarBitSetTraits |
| 54 | // |
| 55 | // This class is customizes the bit set to represent sets of all local vars (tracked or not) -- |
| 56 | // at least up to some maximum index. (This index is private to the Compiler, and it is |
| 57 | // the responsibility of the compiler not to use indices >= this maximum.) |
| 58 | // We rely on the fact that variables are never deleted, and therefore use the |
| 59 | // total # of locals as the epoch number (up to the maximum). |
| 60 | // |
| 61 | class AllVarBitSetTraits : public CompAllocBitSetTraits |
| 62 | { |
| 63 | public: |
| 64 | static inline unsigned GetSize(Compiler* comp); |
| 65 | |
| 66 | static inline unsigned GetArrSize(Compiler* comp, unsigned elemSize); |
| 67 | |
| 68 | static inline unsigned GetEpoch(class Compiler* comp); |
| 69 | |
| 70 | static inline BitSetSupport::BitSetOpCounter* GetOpCounter(Compiler* comp); |
| 71 | }; |
| 72 | |
| 73 | /////////////////////////////////////////////////////////////////////////////// |
| 74 | // |
| 75 | // BasicBlockBitSetTraits |
| 76 | // |
| 77 | // This class is customizes the bit set to represent sets of BasicBlocks. |
| 78 | // The size of the bitset is determined by maximum assigned BasicBlock number |
| 79 | // (Compiler::fgBBNumMax) (Note that fgBBcount is not equal to this during inlining, |
| 80 | // when fgBBcount is the number of blocks in the inlined function, but the assigned |
| 81 | // block numbers are higher than the inliner function. fgBBNumMax counts both. |
| 82 | // Thus, if you only care about the inlinee, during inlining, this bit set will waste |
| 83 | // the lower numbered block bits.) The Compiler* tracks the BasicBlock epochs. |
| 84 | // |
| 85 | class BasicBlockBitSetTraits : public CompAllocBitSetTraits |
| 86 | { |
| 87 | public: |
| 88 | static inline unsigned GetSize(Compiler* comp); |
| 89 | |
| 90 | static inline unsigned GetArrSize(Compiler* comp, unsigned elemSize); |
| 91 | |
| 92 | static inline unsigned GetEpoch(class Compiler* comp); |
| 93 | |
| 94 | static inline BitSetSupport::BitSetOpCounter* GetOpCounter(Compiler* comp); |
| 95 | }; |
| 96 | |
| 97 | /////////////////////////////////////////////////////////////////////////////// |
| 98 | // |
| 99 | // BitVecTraits |
| 100 | // |
| 101 | // This class simplifies creation and usage of "ShortLong" bitsets. |
| 102 | // |
| 103 | struct BitVecTraits |
| 104 | { |
| 105 | private: |
| 106 | unsigned size; |
| 107 | Compiler* comp; |
| 108 | |
| 109 | public: |
| 110 | BitVecTraits(unsigned size, Compiler* comp) : size(size), comp(comp) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | static inline void* Alloc(BitVecTraits* b, size_t byteSize); |
| 115 | |
| 116 | #ifdef DEBUG |
| 117 | static inline void* DebugAlloc(BitVecTraits* b, size_t byteSize); |
| 118 | #endif // DEBUG |
| 119 | |
| 120 | static inline unsigned GetSize(BitVecTraits* b); |
| 121 | |
| 122 | static inline unsigned GetArrSize(BitVecTraits* b, unsigned elemSize); |
| 123 | |
| 124 | static inline unsigned GetEpoch(BitVecTraits* b); |
| 125 | |
| 126 | static inline BitSetSupport::BitSetOpCounter* GetOpCounter(BitVecTraits* b); |
| 127 | }; |
| 128 | |
| 129 | #endif // CompilerBitSetTraits_DEFINED |
| 130 | |