| 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 | // | 
|---|
| 6 | // This include file determines how VARSET_TP is implemented. | 
|---|
| 7 | // | 
|---|
| 8 | #ifndef _VARSET_INCLUDED_ | 
|---|
| 9 | #define _VARSET_INCLUDED_ 1 | 
|---|
| 10 |  | 
|---|
| 11 | // A VARSET_TP is a set of (small) integers representing local variables. | 
|---|
| 12 | // We implement varsets using the BitSet abstraction, which supports | 
|---|
| 13 | // several different implementations. | 
|---|
| 14 | // | 
|---|
| 15 | // The set of tracked variables may change during a compilation, and variables may be | 
|---|
| 16 | // re-sorted, so the tracked variable index of a variable is decidedly *not* stable.  The | 
|---|
| 17 | // bitset abstraction supports labeling of bitsets with "epochs", and supports a | 
|---|
| 18 | // debugging mode in which live bitsets must have the current epoch.  To use this feature, | 
|---|
| 19 | // divide a compilation up into epochs, during which tracked variable indices are | 
|---|
| 20 | // stable. | 
|---|
| 21 |  | 
|---|
| 22 | // Some implementations of BitSet may use a level of indirection.  Therefore, we | 
|---|
| 23 | // must be careful about about assignment and initialization.  We often want to | 
|---|
| 24 | // reason about VARSET_TP as immutable values, and just copying the contents would | 
|---|
| 25 | // introduce sharing in the indirect case, which is usually not what's desired.  On | 
|---|
| 26 | // the other hand, there are many cases in which the RHS value has just been | 
|---|
| 27 | // created functionally, and the intialization/assignment is obviously its last | 
|---|
| 28 | // use.  In these cases, allocating a new indirect representation for the lhs (if | 
|---|
| 29 | // it does not already have one) would be unnecessary and wasteful.  Thus, for both | 
|---|
| 30 | // initialization and assignment, we have normal versions, which do make copies to | 
|---|
| 31 | // prevent sharing and definitely preserve value semantics, and "NOCOPY" versions, | 
|---|
| 32 | // which do not.  Obviously, the latter should be used with care. | 
|---|
| 33 |  | 
|---|
| 34 | #include "bitset.h" | 
|---|
| 35 | #include "compilerbitsettraits.h" | 
|---|
| 36 |  | 
|---|
| 37 | const unsigned UInt64Bits = sizeof(UINT64) * 8; | 
|---|
| 38 |  | 
|---|
| 39 | // This #define chooses the BitSet representation used for VARSET. | 
|---|
| 40 | // The choices are defined in "bitset.h"; they currently include | 
|---|
| 41 | // BSUInt64, BSShortLong, and BSUInt64Class. | 
|---|
| 42 | #define VARSET_REP BSShortLong | 
|---|
| 43 |  | 
|---|
| 44 | #if VARSET_REP == BSUInt64 | 
|---|
| 45 |  | 
|---|
| 46 | #include "bitsetasuint64.h" | 
|---|
| 47 |  | 
|---|
| 48 | typedef BitSetOps</*BitSetType*/ UINT64, | 
|---|
| 49 | /*Brand*/ VARSET_REP, | 
|---|
| 50 | /*Env*/ Compiler*, | 
|---|
| 51 | /*BitSetTraits*/ TrackedVarBitSetTraits> | 
|---|
| 52 | VarSetOpsRaw; | 
|---|
| 53 |  | 
|---|
| 54 | typedef UINT64 VARSET_TP; | 
|---|
| 55 |  | 
|---|
| 56 | const unsigned lclMAX_TRACKED = UInt64Bits; | 
|---|
| 57 |  | 
|---|
| 58 | #define VARSET_REP_IS_CLASS 0 | 
|---|
| 59 |  | 
|---|
| 60 | #elif VARSET_REP == BSShortLong | 
|---|
| 61 |  | 
|---|
| 62 | #include "bitsetasshortlong.h" | 
|---|
| 63 |  | 
|---|
| 64 | typedef BitSetOps</*BitSetType*/ BitSetShortLongRep, | 
|---|
| 65 | /*Brand*/ VARSET_REP, | 
|---|
| 66 | /*Env*/ Compiler*, | 
|---|
| 67 | /*BitSetTraits*/ TrackedVarBitSetTraits> | 
|---|
| 68 | VarSetOpsRaw; | 
|---|
| 69 |  | 
|---|
| 70 | typedef BitSetShortLongRep VARSET_TP; | 
|---|
| 71 |  | 
|---|
| 72 | // Tested various sizes for max tracked locals. The largest value for which no throughput regression | 
|---|
| 73 | // could be measured was 512. Going to 1024 showed the first throughput regressions. | 
|---|
| 74 | // We anticipate the larger size will be needed to support better inlining. | 
|---|
| 75 |  | 
|---|
| 76 | const unsigned       lclMAX_TRACKED = 512; | 
|---|
| 77 |  | 
|---|
| 78 | #define VARSET_REP_IS_CLASS 0 | 
|---|
| 79 |  | 
|---|
| 80 | #elif VARSET_REP == BSUInt64Class | 
|---|
| 81 |  | 
|---|
| 82 | #include "bitsetasuint64inclass.h" | 
|---|
| 83 |  | 
|---|
| 84 | typedef BitSetOps</*BitSetType*/ BitSetUint64<Compiler*, TrackedVarBitSetTraits>, | 
|---|
| 85 | /*Brand*/ VARSET_REP, | 
|---|
| 86 | /*Env*/ Compiler*, | 
|---|
| 87 | /*BitSetTraits*/ TrackedVarBitSetTraits> | 
|---|
| 88 | VarSetOpsRaw; | 
|---|
| 89 |  | 
|---|
| 90 | typedef BitSetUint64<Compiler*, TrackedVarBitSetTraits> VARSET_TP; | 
|---|
| 91 |  | 
|---|
| 92 | const unsigned lclMAX_TRACKED = UInt64Bits; | 
|---|
| 93 |  | 
|---|
| 94 | #define VARSET_REP_IS_CLASS 1 | 
|---|
| 95 |  | 
|---|
| 96 | #else | 
|---|
| 97 |  | 
|---|
| 98 | #error "Unrecognized BitSet implemention for VarSet." | 
|---|
| 99 |  | 
|---|
| 100 | #endif | 
|---|
| 101 |  | 
|---|
| 102 | // These types should be used as the types for VARSET_TP arguments and return values, respectively. | 
|---|
| 103 | // Arg type represent the read only argument type, that can't be modified. | 
|---|
| 104 | typedef VarSetOpsRaw::ValArgType VARSET_VALARG_TP; | 
|---|
| 105 | typedef VarSetOpsRaw::RetValType VARSET_VALRET_TP; | 
|---|
| 106 |  | 
|---|
| 107 | #define VARSET_COUNTOPS 0 | 
|---|
| 108 | #if VARSET_COUNTOPS | 
|---|
| 109 | typedef BitSetOpsWithCounter<VARSET_TP, | 
|---|
| 110 | VARSET_REP, | 
|---|
| 111 | Compiler*, | 
|---|
| 112 | TrackedVarBitSetTraits, | 
|---|
| 113 | VARSET_VALARG_TP, | 
|---|
| 114 | VARSET_VALRET_TP, | 
|---|
| 115 | VarSetOpsRaw::Iter> | 
|---|
| 116 | VarSetOps; | 
|---|
| 117 | #else | 
|---|
| 118 | typedef VarSetOpsRaw VarSetOps; | 
|---|
| 119 | #endif | 
|---|
| 120 |  | 
|---|
| 121 | #define ALLVARSET_REP BSUInt64 | 
|---|
| 122 |  | 
|---|
| 123 | #if ALLVARSET_REP == BSUInt64 | 
|---|
| 124 |  | 
|---|
| 125 | #include "bitsetasuint64.h" | 
|---|
| 126 |  | 
|---|
| 127 | typedef BitSetOps</*BitSetType*/ UINT64, | 
|---|
| 128 | /*Brand*/ ALLVARSET_REP, | 
|---|
| 129 | /*Env*/ Compiler*, | 
|---|
| 130 | /*BitSetTraits*/ AllVarBitSetTraits> | 
|---|
| 131 | AllVarSetOps; | 
|---|
| 132 |  | 
|---|
| 133 | typedef UINT64 ALLVARSET_TP; | 
|---|
| 134 |  | 
|---|
| 135 | const unsigned lclMAX_ALLSET_TRACKED = UInt64Bits; | 
|---|
| 136 |  | 
|---|
| 137 | #define ALLVARSET_REP_IS_CLASS 0 | 
|---|
| 138 |  | 
|---|
| 139 | #elif ALLVARSET_REP == BSShortLong | 
|---|
| 140 |  | 
|---|
| 141 | #include "bitsetasshortlong.h" | 
|---|
| 142 |  | 
|---|
| 143 | typedef BitSetOps</*BitSetType*/ BitSetShortLongRep, | 
|---|
| 144 | /*Brand*/ ALLVARSET_REP, | 
|---|
| 145 | /*Env*/ Compiler*, | 
|---|
| 146 | /*BitSetTraits*/ AllVarBitSetTraits> | 
|---|
| 147 | AllVarSetOps; | 
|---|
| 148 |  | 
|---|
| 149 | typedef BitSetShortLongRep ALLVARSET_TP; | 
|---|
| 150 |  | 
|---|
| 151 | const unsigned lclMAX_ALLSET_TRACKED = lclMAX_TRACKED; | 
|---|
| 152 |  | 
|---|
| 153 | #define ALLVARSET_REP_IS_CLASS 0 | 
|---|
| 154 |  | 
|---|
| 155 | #elif ALLVARSET_REP == BSUInt64Class | 
|---|
| 156 |  | 
|---|
| 157 | #include "bitsetasuint64inclass.h" | 
|---|
| 158 |  | 
|---|
| 159 | typedef BitSetOps</*BitSetType*/ BitSetUint64<Compiler*, AllVarBitSetTraits>, | 
|---|
| 160 | /*Brand*/ ALLVARSET_REP, | 
|---|
| 161 | /*Env*/ Compiler*, | 
|---|
| 162 | /*BitSetTraits*/ AllVarBitSetTraits> | 
|---|
| 163 | AllVarSetOps; | 
|---|
| 164 |  | 
|---|
| 165 | typedef BitSetUint64<Compiler*, AllVarBitSetTraits> ALLVARSET_TP; | 
|---|
| 166 |  | 
|---|
| 167 | const unsigned lclMAX_ALLSET_TRACKED = UInt64Bits; | 
|---|
| 168 |  | 
|---|
| 169 | #define ALLVARSET_REP_IS_CLASS 1 | 
|---|
| 170 |  | 
|---|
| 171 | #else | 
|---|
| 172 | #error "Unrecognized BitSet implemention for AllVarSet." | 
|---|
| 173 | #endif | 
|---|
| 174 |  | 
|---|
| 175 | // These types should be used as the types for ALLVARSET_TP arguments and return values, respectively. | 
|---|
| 176 | typedef AllVarSetOps::ValArgType ALLVARSET_VALARG_TP; | 
|---|
| 177 | typedef AllVarSetOps::RetValType ALLVARSET_VALRET_TP; | 
|---|
| 178 |  | 
|---|
| 179 | #endif // _VARSET_INCLUDED_ | 
|---|
| 180 |  | 
|---|