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.
6 // This include file determines how VARSET_TP is implemented.
8 #ifndef _VARSET_INCLUDED_
9 #define _VARSET_INCLUDED_ 1
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.
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
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.
35 #include "compilerbitsettraits.h"
37 const unsigned UInt64Bits = sizeof(UINT64) * 8;
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
44 #if VARSET_REP == BSUInt64
46 #include "bitsetasuint64.h"
48 typedef BitSetOps</*BitSetType*/ UINT64,
51 /*BitSetTraits*/ TrackedVarBitSetTraits>
54 typedef UINT64 VARSET_TP;
56 const unsigned lclMAX_TRACKED = UInt64Bits;
58 #define VARSET_REP_IS_CLASS 0
60 #elif VARSET_REP == BSShortLong
62 #include "bitsetasshortlong.h"
64 typedef BitSetOps</*BitSetType*/ BitSetShortLongRep,
67 /*BitSetTraits*/ TrackedVarBitSetTraits>
70 typedef BitSetShortLongRep VARSET_TP;
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 // There were a number of failures when 512 was used for legacy, so we just retain the 128 value
76 // for legacy backend.
78 #if !defined(LEGACY_BACKEND)
79 const unsigned lclMAX_TRACKED = 512;
81 const unsigned lclMAX_TRACKED = 128;
84 #define VARSET_REP_IS_CLASS 0
86 #elif VARSET_REP == BSUInt64Class
88 #include "bitsetasuint64inclass.h"
90 typedef BitSetOps</*BitSetType*/ BitSetUint64<Compiler*, TrackedVarBitSetTraits>,
93 /*BitSetTraits*/ TrackedVarBitSetTraits>
96 typedef BitSetUint64<Compiler*, TrackedVarBitSetTraits> VARSET_TP;
98 const unsigned lclMAX_TRACKED = UInt64Bits;
100 #define VARSET_REP_IS_CLASS 1
104 #error "Unrecognized BitSet implemention for VarSet."
108 // These types should be used as the types for VARSET_TP arguments and return values, respectively.
109 // Arg type represent the read only argument type, that can't be modified.
110 typedef VarSetOpsRaw::ValArgType VARSET_VALARG_TP;
111 typedef VarSetOpsRaw::RetValType VARSET_VALRET_TP;
113 #define VARSET_COUNTOPS 0
115 typedef BitSetOpsWithCounter<VARSET_TP,
118 TrackedVarBitSetTraits,
124 typedef VarSetOpsRaw VarSetOps;
127 #define ALLVARSET_REP BSUInt64
129 #if ALLVARSET_REP == BSUInt64
131 #include "bitsetasuint64.h"
133 typedef BitSetOps</*BitSetType*/ UINT64,
134 /*Brand*/ ALLVARSET_REP,
136 /*BitSetTraits*/ AllVarBitSetTraits>
139 typedef UINT64 ALLVARSET_TP;
141 const unsigned lclMAX_ALLSET_TRACKED = UInt64Bits;
143 #define ALLVARSET_REP_IS_CLASS 0
145 #elif ALLVARSET_REP == BSShortLong
147 #include "bitsetasshortlong.h"
149 typedef BitSetOps</*BitSetType*/ BitSetShortLongRep,
150 /*Brand*/ ALLVARSET_REP,
152 /*BitSetTraits*/ AllVarBitSetTraits>
155 typedef BitSetShortLongRep ALLVARSET_TP;
157 const unsigned lclMAX_ALLSET_TRACKED = lclMAX_TRACKED;
159 #define ALLVARSET_REP_IS_CLASS 0
161 #elif ALLVARSET_REP == BSUInt64Class
163 #include "bitsetasuint64inclass.h"
165 typedef BitSetOps</*BitSetType*/ BitSetUint64<Compiler*, AllVarBitSetTraits>,
166 /*Brand*/ ALLVARSET_REP,
168 /*BitSetTraits*/ AllVarBitSetTraits>
171 typedef BitSetUint64<Compiler*, AllVarBitSetTraits> ALLVARSET_TP;
173 const unsigned lclMAX_ALLSET_TRACKED = UInt64Bits;
175 #define ALLVARSET_REP_IS_CLASS 1
178 #error "Unrecognized BitSet implemention for AllVarSet."
181 // These types should be used as the types for ALLVARSET_TP arguments and return values, respectively.
182 typedef AllVarSetOps::ValArgType ALLVARSET_VALARG_TP;
183 typedef AllVarSetOps::RetValType ALLVARSET_VALRET_TP;
185 #endif // _VARSET_INCLUDED_